2016-12-13 22:49:17 +01:00
|
|
|
import os
|
2016-12-15 09:58:13 +01:00
|
|
|
import sys
|
2016-12-13 22:49:17 +01:00
|
|
|
import configparser
|
|
|
|
import subprocess
|
|
|
|
import interface_variables
|
2016-12-16 00:06:27 +01:00
|
|
|
import curses
|
2016-12-13 22:49:17 +01:00
|
|
|
|
|
|
|
int_vars = interface_variables
|
|
|
|
|
2016-12-16 00:06:27 +01:00
|
|
|
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()
|
|
|
|
|
2016-12-13 22:49:17 +01:00
|
|
|
def list_archives():
|
2016-12-16 00:06:27 +01:00
|
|
|
curses.endwin()
|
2016-12-15 15:02:21 +01:00
|
|
|
borg_list = subprocess.Popen(['borg', 'list'], stdout=subprocess.PIPE)
|
|
|
|
less_output = subprocess.Popen(['less'], stdin=borg_list.stdout)
|
|
|
|
borg_list.wait()
|
|
|
|
less_output.wait()
|
2016-12-13 22:49:17 +01:00
|
|
|
|
|
|
|
def show_info():
|
2016-12-16 00:06:27 +01:00
|
|
|
curses.endwin()
|
2016-12-15 12:50:58 +01:00
|
|
|
prompt_archive_name()
|
2016-12-13 22:49:17 +01:00
|
|
|
os.system('clear')
|
2016-12-15 15:02:21 +01:00
|
|
|
p = subprocess.Popen(['borg', 'info', '::' + int_vars.archive_name])
|
|
|
|
p.wait()
|
2016-12-13 22:49:17 +01:00
|
|
|
print()
|
2016-12-14 13:07:48 +01:00
|
|
|
pause()
|
2016-12-13 22:49:17 +01:00
|
|
|
|
|
|
|
def mount_archive():
|
2016-12-16 00:06:27 +01:00
|
|
|
curses.endwin()
|
2016-12-15 12:50:58 +01:00
|
|
|
prompt_archive_name()
|
|
|
|
int_vars.mount_point = "/tmp/" + int_vars.archive_name
|
2016-12-13 22:49:17 +01:00
|
|
|
if not os.path.exists(int_vars.mount_point):
|
|
|
|
os.makedirs(int_vars.mount_point)
|
2016-12-15 15:02:21 +01:00
|
|
|
p = subprocess.Popen(['borg', 'mount', '::' + int_vars.archive_name,
|
|
|
|
int_vars.mount_point])
|
|
|
|
p.wait()
|
2016-12-13 22:49:17 +01:00
|
|
|
print()
|
2016-12-14 13:07:48 +01:00
|
|
|
print("Archive mounted at " + int_vars.mount_point + "/.")
|
|
|
|
print("The archive will remain mounted as long this programm is running.")
|
2016-12-13 22:49:17 +01:00
|
|
|
print()
|
2016-12-14 13:07:48 +01:00
|
|
|
pause()
|
2016-12-13 22:49:17 +01:00
|
|
|
|
|
|
|
def restore_archive():
|
2016-12-16 00:06:27 +01:00
|
|
|
curses.endwin()
|
2016-12-15 12:50:58 +01:00
|
|
|
prompt_archive_name()
|
2016-12-13 22:49:17 +01:00
|
|
|
restore_path = input("Please enter the path where you want to "
|
|
|
|
"restore to: ")
|
|
|
|
if not os.path.exists(restore_path):
|
|
|
|
os.makedirs(restore_path)
|
2016-12-15 12:50:58 +01:00
|
|
|
p = subprocess.Popen(['borg', 'extract', '::' + int_vars.archive_name]
|
2016-12-13 22:49:17 +01:00
|
|
|
,cwd=restore_path)
|
|
|
|
p.wait()
|
|
|
|
print()
|
|
|
|
print("Archive extracted to " + restore_path)
|
|
|
|
print()
|
2016-12-14 20:54:49 +01:00
|
|
|
pause()
|
2016-12-13 22:49:17 +01:00
|
|
|
|
|
|
|
def configuration():
|
|
|
|
# setup the config parser
|
|
|
|
config = configparser.ConfigParser()
|
2016-12-14 22:27:57 +01:00
|
|
|
# check whether the config file exists either in the home folder or next to
|
|
|
|
# the binary
|
|
|
|
home = os.getenv('HOME')
|
2016-12-15 08:43:48 +01:00
|
|
|
config_file = "borg_interface.cfg"
|
2016-12-15 15:25:37 +01:00
|
|
|
config_folder = ".config/borg_interface/"
|
|
|
|
config_path = os.path.join(home, config_folder, config_file)
|
|
|
|
if os.path.isfile(config_path):
|
|
|
|
config.read(config_path)
|
2016-12-15 08:43:48 +01:00
|
|
|
elif os.path.isfile(config_file):
|
|
|
|
config.read(config_file)
|
2016-12-14 22:27:57 +01:00
|
|
|
else:
|
|
|
|
print("Configuration file not found.")
|
2016-12-15 09:58:13 +01:00
|
|
|
sys.exit(1)
|
2016-12-14 22:27:57 +01:00
|
|
|
# assign the repository variable depending wheter it's a remote or a local
|
|
|
|
# repository
|
2016-12-14 07:59:42 +01:00
|
|
|
if 'server' in config['DEFAULT']:
|
2016-12-13 22:49:17 +01:00
|
|
|
repository = (config['DEFAULT']['user']
|
|
|
|
+ "@"
|
|
|
|
+ config['DEFAULT']['server']
|
|
|
|
+ ":"
|
|
|
|
+ config['DEFAULT']['repository_path'])
|
|
|
|
else:
|
|
|
|
repository = config['DEFAULT']['repository_path']
|
|
|
|
# assign the password variable
|
|
|
|
password = config['DEFAULT']['password']
|
|
|
|
# set the environment variables
|
|
|
|
os.environ['BORG_REPO'] = repository
|
|
|
|
os.environ['BORG_PASSPHRASE'] = password
|
|
|
|
|
|
|
|
def exit():
|
2016-12-16 00:06:27 +01:00
|
|
|
curses.endwin()
|
2016-12-13 22:49:17 +01:00
|
|
|
if (not int_vars.mount_point):
|
|
|
|
print()
|
2016-12-15 09:58:13 +01:00
|
|
|
sys.exit(0)
|
2016-12-13 22:49:17 +01:00
|
|
|
else:
|
|
|
|
print()
|
|
|
|
print("Unmount Archive and remove folder.")
|
|
|
|
print()
|
|
|
|
os.system('fusermount -u' + " " + int_vars.mount_point)
|
|
|
|
os.rmdir(int_vars.mount_point)
|
2016-12-15 09:58:13 +01:00
|
|
|
sys.exit(0)
|
2016-12-14 13:07:48 +01:00
|
|
|
|
|
|
|
def pause():
|
2016-12-15 15:24:06 +01:00
|
|
|
input("Press Enter to continue.")
|
2016-12-15 12:50:58 +01:00
|
|
|
|
|
|
|
def prompt_archive_name():
|
|
|
|
int_vars.archive_name = input("Please enter the archive name: ")
|