Add logs/edit

This commit is contained in:
Digital Studium 2024-04-07 18:12:21 +03:00
parent 7bafd5376c
commit 6be42383f2
2 changed files with 60 additions and 8 deletions

65
kls
View File

@ -3,6 +3,11 @@ import curses
import subprocess import subprocess
stdscr = curses.initscr() stdscr = curses.initscr()
stdscr.refresh()
curses.noecho()
curses.cbreak()
stdscr.keypad(True)
curses.curs_set(0)
class Menu: class Menu:
@ -46,13 +51,53 @@ def main(stdscr):
current_menu = 0 current_menu = 0
menus[current_menu].win.addstr(1, 2, menus[current_menu].name, curses.A_REVERSE | curses.A_ITALIC) menus[current_menu].win.addstr(1, 2, menus[current_menu].name, curses.A_REVERSE | curses.A_ITALIC)
for menu in menus: for menu in menus:
menu.win.addstr(3, 2, menu.rows[0], curses.A_REVERSE | curses.A_ITALIC) menu.win.addstr(3, 2, menu.rows[menu.row], curses.A_REVERSE | curses.A_ITALIC)
while running: while running:
[menu.win.refresh() for menu in menus] # refresh all menus [menu.win.refresh() for menu in menus] # refresh all menus
the_user_presses_the_key_et_voila = stdscr.getkey() key_pressed = stdscr.getkey()
match the_user_presses_the_key_et_voila: match key_pressed:
case 'q': case 'q':
running = False running = False
case 'l':
if current_menu == 2 and not menus[2].rows[menus[2].row].startswith("No resources") and menus[1].rows[menus[1].row] == "pods":
namespace = menus[0].rows[menus[0].row]
api_resource = menus[1].rows[menus[1].row]
resource = menus[2].rows[menus[2].row]
process = subprocess.call(f"kubectl -n {namespace} logs {resource} | less", shell=True)
stdscr = curses.initscr()
stdscr.refresh()
curses.noecho()
curses.cbreak()
stdscr.keypad(True)
curses.curs_set(0)
for menu in menus:
menu.win.clear()
menu.win.box()
menu.win.addstr(1, 2, menu.name)
for index, row in enumerate(menu.rows):
menu.win.addstr(index + 3, 2, row)
menu.win.addstr(3, 2, menu.rows[menu.row], curses.A_REVERSE | curses.A_ITALIC)
menus[current_menu].win.addstr(1, 2, menus[current_menu].name, curses.A_REVERSE | curses.A_ITALIC)
case 'e':
if current_menu == 2 and not menus[2].rows[menus[2].row].startswith("No resources"):
namespace = menus[0].rows[menus[0].row]
api_resource = menus[1].rows[menus[1].row]
resource = menus[2].rows[menus[2].row]
process = subprocess.call(f"kubectl edit {api_resource} -n {namespace} {resource}", shell=True)
stdscr = curses.initscr()
stdscr.refresh()
curses.noecho()
curses.cbreak()
stdscr.keypad(True)
curses.curs_set(0)
for menu in menus:
menu.win.clear()
menu.win.box()
menu.win.addstr(1, 2, menu.name)
for index, row in enumerate(menu.rows):
menu.win.addstr(index + 3, 2, row)
menu.win.addstr(3, 2, menu.rows[menu.row], curses.A_REVERSE | curses.A_ITALIC)
menus[current_menu].win.addstr(1, 2, menus[current_menu].name, curses.A_REVERSE | curses.A_ITALIC)
case '\t' | "KEY_RIGHT": case '\t' | "KEY_RIGHT":
menus[current_menu].win.addstr(1, 2, menus[current_menu].name) menus[current_menu].win.addstr(1, 2, menus[current_menu].name)
current_menu = (current_menu + 1) % 3 current_menu = (current_menu + 1) % 3
@ -112,9 +157,13 @@ def main(stdscr):
else: else:
menus[2].win.addstr(index + 3, 2, row) menus[2].win.addstr(index + 3, 2, row)
curses.wrapper(main) main(stdscr)
curses.nocbreak()
stdscr.keypad(False)
curses.echo()
curses.endwin()
subprocess.call(["clear"])
#curses.wrapper(main)
#curses.nocbreak()
#stdscr.keypad(False)
#curses.echo()
#curses.endwin()

3
tmp.py Normal file
View File

@ -0,0 +1,3 @@
from subprocess import call
call("kubectl edit deploy -n kube-system traefik", shell=True)