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:
Andreas Zweili 2016-12-16 00:06:27 +01:00
parent 6864890ea9
commit 366dff3ee7
2 changed files with 35 additions and 12 deletions

View File

@ -3,16 +3,39 @@ import sys
import configparser
import subprocess
import interface_variables
import curses
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():
curses.endwin()
borg_list = subprocess.Popen(['borg', 'list'], stdout=subprocess.PIPE)
less_output = subprocess.Popen(['less'], stdin=borg_list.stdout)
borg_list.wait()
less_output.wait()
def show_info():
curses.endwin()
prompt_archive_name()
os.system('clear')
p = subprocess.Popen(['borg', 'info', '::' + int_vars.archive_name])
@ -21,6 +44,7 @@ def show_info():
pause()
def mount_archive():
curses.endwin()
prompt_archive_name()
int_vars.mount_point = "/tmp/" + int_vars.archive_name
if not os.path.exists(int_vars.mount_point):
@ -35,6 +59,7 @@ def mount_archive():
pause()
def restore_archive():
curses.endwin()
prompt_archive_name()
restore_path = input("Please enter the path where you want to "
"restore to: ")
@ -81,6 +106,7 @@ def configuration():
os.environ['BORG_PASSPHRASE'] = password
def exit():
curses.endwin()
if (not int_vars.mount_point):
print()
sys.exit(0)

View File

@ -2,33 +2,30 @@
import os
import interface_functions
import interface_variables
import curses
chosen_activity = None
# The main menu starts there
interface_functions.configuration()
while chosen_activity != 0:
os.system('clear')
print("What would you like to do?")
# 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")
interface_functions.draw_screen()
screen = curses.initscr()
try:
chosen_activity = int(input("Choose the desired activity: "))
if chosen_activity == 1:
chosen_activity = screen.getch()
if chosen_activity == ord('1'):
# prints all the archives in the repository and lists them with
# less
interface_functions.list_archives()
if chosen_activity == 2:
if chosen_activity == ord('2'):
# Displays all the information related to the archive name the user
# enters
interface_functions.show_info()
if chosen_activity == 3:
if chosen_activity == ord('3'):
# mounts a chosen archive to /tmp/archive name
interface_functions.mount_archive()
if chosen_activity == 4:
if chosen_activity == ord('4'):
interface_functions.restore_archive()
elif chosen_activity == 0:
elif chosen_activity == ord('0'):
interface_functions.exit()
except ValueError:
print("Please enter a full number.")