add nearly full curses output

This commit is contained in:
Andreas Zweili 2016-12-16 13:13:58 +01:00
parent 2eeec351cb
commit ad0d54101c
2 changed files with 33 additions and 24 deletions

View File

@ -16,7 +16,7 @@ def get_param(prompt_string):
input = screen.getstr(3, 2, 60) input = screen.getstr(3, 2, 60)
return input return input
def draw_screen(): def draw_menu():
screen.clear() screen.clear()
screen.border(0) screen.border(0)
screen.addstr(2, 2, "Please enter a number...") screen.addstr(2, 2, "Please enter a number...")
@ -27,6 +27,13 @@ def draw_screen():
screen.addstr(8, 4, "0 - Exit") screen.addstr(8, 4, "0 - Exit")
screen.refresh() screen.refresh()
def draw_screen(r, c, message):
screen.clear()
screen.border(0)
screen.addstr(r, c, message)
screen.refresh()
def list_archives(): def list_archives():
curses.endwin() curses.endwin()
borg_list = subprocess.Popen(['borg', 'list'], stdout=subprocess.PIPE) borg_list = subprocess.Popen(['borg', 'list'], stdout=subprocess.PIPE)
@ -35,7 +42,7 @@ def list_archives():
less_output.wait() less_output.wait()
def show_info(): def show_info():
archive_name = get_param("Please enter the archive name: ") archive_name = get_param("Please enter the archive name: ").decode('utf-8')
curses.endwin() curses.endwin()
os.system('clear') os.system('clear')
p = subprocess.Popen(['borg', 'info', '::' + archive_name]) p = subprocess.Popen(['borg', 'info', '::' + archive_name])
@ -44,34 +51,30 @@ def show_info():
pause() pause()
def mount_archive(): def mount_archive():
archive_name = get_param("Please enter the archive name: ") archive_name = get_param("Please enter the archive name: ").decode('utf-8')
curses.endwin()
int_vars.mount_point = os.path.join('/tmp', archive_name) int_vars.mount_point = os.path.join('/tmp', archive_name)
if not os.path.exists(int_vars.mount_point): if not os.path.exists(int_vars.mount_point):
os.makedirs(int_vars.mount_point) os.makedirs(int_vars.mount_point)
p = subprocess.Popen(['borg', 'mount', '::' + archive_name, p = subprocess.Popen(['borg', 'mount', '::' + archive_name,
int_vars.mount_point]) int_vars.mount_point])
p.wait() p.wait()
print() draw_screen(2, 2, "Archive mounted at " + int_vars.mount_point + "/.")
print("Archive mounted at " + int_vars.mount_point + "/.") screen.addstr(3, 2, "The archive will remain mounted as long this programm is running.")
print("The archive will remain mounted as long this programm is running.") screen.refresh()
print() ncurses_pause()
pause()
def restore_archive(): def restore_archive():
curses.endwin() archive_name = get_param("Please enter the archive name: ").decode('utf-8')
prompt_archive_name() restore_path = get_param("Please enter the path where you want to "
restore_path = input("Please enter the path where you want to " "restore to: ").decode('utf-8')
"restore to: ") draw_screen(2, 2, "Please wait while the archive gets restored.")
if not os.path.exists(restore_path): if not os.path.exists(restore_path):
os.makedirs(restore_path) os.makedirs(restore_path)
p = subprocess.Popen(['borg', 'extract', '::' + int_vars.archive_name] p = subprocess.Popen(['borg', 'extract', '::' + archive_name]
,cwd=restore_path) ,cwd=restore_path)
p.wait() p.wait()
print() draw_screen(2, 2, "Archive extracted to " + restore_path)
print("Archive extracted to " + restore_path) ncurses_pause()
print()
pause()
def configuration(): def configuration():
# setup the config parser # setup the config parser
@ -106,19 +109,25 @@ def configuration():
os.environ['BORG_PASSPHRASE'] = password os.environ['BORG_PASSPHRASE'] = password
def exit(): def exit():
curses.endwin()
if (not int_vars.mount_point): if (not int_vars.mount_point):
print() curses.endwin()
os.system('clear') os.system('clear')
sys.exit(0) sys.exit(0)
else: else:
print() curses.endwin()
os.system('clear')
print("Unmount Archive and remove folder.") print("Unmount Archive and remove folder.")
print() print()
os.system('fusermount -u' + " " + int_vars.mount_point) os.system('fusermount -u' + " " + int_vars.mount_point)
os.rmdir(int_vars.mount_point) os.rmdir(int_vars.mount_point)
os.system('clear')
sys.exit(0) sys.exit(0)
def ncurses_pause():
screen.border(0)
screen.addstr(5, 2, "Press Enter to continue...")
screen.refresh()
input = screen.getstr(3, 2, 60)
return input
def pause(): def pause():
input("Press Enter to continue.") input("Press Enter to continue...")

View File

@ -8,7 +8,7 @@ chosen_activity = None
# The main menu starts there # The main menu starts there
interface_functions.configuration() interface_functions.configuration()
while chosen_activity != 0: while chosen_activity != 0:
interface_functions.draw_screen() interface_functions.draw_menu()
screen = curses.initscr() screen = curses.initscr()
try: try:
chosen_activity = screen.getch() chosen_activity = screen.getch()