add basic ncurses funcionality
this commit adds the basic functionality of curses. The output however doesn't get displayed in the window yet.
This commit is contained in:
parent
6864890ea9
commit
366dff3ee7
|
@ -3,16 +3,39 @@ import sys
|
||||||
import configparser
|
import configparser
|
||||||
import subprocess
|
import subprocess
|
||||||
import interface_variables
|
import interface_variables
|
||||||
|
import curses
|
||||||
|
|
||||||
int_vars = interface_variables
|
int_vars = interface_variables
|
||||||
|
|
||||||
|
def get_param(prompt_string):
|
||||||
|
screen.clear()
|
||||||
|
screen.border(0)
|
||||||
|
screen.addstr(2, 2, prompt_string)
|
||||||
|
screen.refresh()
|
||||||
|
input = screen.getstr(10, 10, 60)
|
||||||
|
return input
|
||||||
|
|
||||||
|
def draw_screen():
|
||||||
|
screen = curses.initscr()
|
||||||
|
screen.clear()
|
||||||
|
screen.border(0)
|
||||||
|
screen.addstr(2, 2, "Please enter a number...")
|
||||||
|
screen.addstr(4, 4, "1 - List archives in repository")
|
||||||
|
screen.addstr(5, 4, "2 - Show archive details")
|
||||||
|
screen.addstr(6, 4, "3 - Mount archive")
|
||||||
|
screen.addstr(7, 4, "4 - Restore an archive to specific location")
|
||||||
|
screen.addstr(8, 4, "0 - Exit")
|
||||||
|
screen.refresh()
|
||||||
|
|
||||||
def list_archives():
|
def list_archives():
|
||||||
|
curses.endwin()
|
||||||
borg_list = subprocess.Popen(['borg', 'list'], stdout=subprocess.PIPE)
|
borg_list = subprocess.Popen(['borg', 'list'], stdout=subprocess.PIPE)
|
||||||
less_output = subprocess.Popen(['less'], stdin=borg_list.stdout)
|
less_output = subprocess.Popen(['less'], stdin=borg_list.stdout)
|
||||||
borg_list.wait()
|
borg_list.wait()
|
||||||
less_output.wait()
|
less_output.wait()
|
||||||
|
|
||||||
def show_info():
|
def show_info():
|
||||||
|
curses.endwin()
|
||||||
prompt_archive_name()
|
prompt_archive_name()
|
||||||
os.system('clear')
|
os.system('clear')
|
||||||
p = subprocess.Popen(['borg', 'info', '::' + int_vars.archive_name])
|
p = subprocess.Popen(['borg', 'info', '::' + int_vars.archive_name])
|
||||||
|
@ -21,6 +44,7 @@ def show_info():
|
||||||
pause()
|
pause()
|
||||||
|
|
||||||
def mount_archive():
|
def mount_archive():
|
||||||
|
curses.endwin()
|
||||||
prompt_archive_name()
|
prompt_archive_name()
|
||||||
int_vars.mount_point = "/tmp/" + int_vars.archive_name
|
int_vars.mount_point = "/tmp/" + int_vars.archive_name
|
||||||
if not os.path.exists(int_vars.mount_point):
|
if not os.path.exists(int_vars.mount_point):
|
||||||
|
@ -35,6 +59,7 @@ def mount_archive():
|
||||||
pause()
|
pause()
|
||||||
|
|
||||||
def restore_archive():
|
def restore_archive():
|
||||||
|
curses.endwin()
|
||||||
prompt_archive_name()
|
prompt_archive_name()
|
||||||
restore_path = input("Please enter the path where you want to "
|
restore_path = input("Please enter the path where you want to "
|
||||||
"restore to: ")
|
"restore to: ")
|
||||||
|
@ -81,6 +106,7 @@ 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()
|
print()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
|
@ -2,33 +2,30 @@
|
||||||
import os
|
import os
|
||||||
import interface_functions
|
import interface_functions
|
||||||
import interface_variables
|
import interface_variables
|
||||||
|
import curses
|
||||||
chosen_activity = None
|
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:
|
||||||
os.system('clear')
|
interface_functions.draw_screen()
|
||||||
print("What would you like to do?")
|
screen = curses.initscr()
|
||||||
# Start the chosen activity and go back to the activity selector.
|
|
||||||
print("1: List Backups, 2: Show archive details, 3: Mount Archive, "
|
|
||||||
"4: Restore Backup, 0: Exit")
|
|
||||||
try:
|
try:
|
||||||
chosen_activity = int(input("Choose the desired activity: "))
|
chosen_activity = screen.getch()
|
||||||
if chosen_activity == 1:
|
if chosen_activity == ord('1'):
|
||||||
# prints all the archives in the repository and lists them with
|
# prints all the archives in the repository and lists them with
|
||||||
# less
|
# less
|
||||||
interface_functions.list_archives()
|
interface_functions.list_archives()
|
||||||
if chosen_activity == 2:
|
if chosen_activity == ord('2'):
|
||||||
# Displays all the information related to the archive name the user
|
# Displays all the information related to the archive name the user
|
||||||
# enters
|
# enters
|
||||||
interface_functions.show_info()
|
interface_functions.show_info()
|
||||||
if chosen_activity == 3:
|
if chosen_activity == ord('3'):
|
||||||
# mounts a chosen archive to /tmp/archive name
|
# mounts a chosen archive to /tmp/archive name
|
||||||
interface_functions.mount_archive()
|
interface_functions.mount_archive()
|
||||||
if chosen_activity == 4:
|
if chosen_activity == ord('4'):
|
||||||
interface_functions.restore_archive()
|
interface_functions.restore_archive()
|
||||||
elif chosen_activity == 0:
|
elif chosen_activity == ord('0'):
|
||||||
interface_functions.exit()
|
interface_functions.exit()
|
||||||
except ValueError:
|
except ValueError:
|
||||||
print("Please enter a full number.")
|
print("Please enter a full number.")
|
||||||
|
|
Reference in New Issue