split the programm into modules
This commit is contained in:
parent
5445c2a194
commit
5a4d9ff69a
|
@ -1,5 +1,5 @@
|
||||||
[DEFAULT]
|
[DEFAULT]
|
||||||
server:
|
server: fileserver.2li.local
|
||||||
user:
|
user: borg
|
||||||
repository_path: /home/andreas/test
|
repository_path: /home/borg/backup/gwyn
|
||||||
password: foo
|
password:
|
||||||
|
|
|
@ -2,77 +2,13 @@
|
||||||
import os
|
import os
|
||||||
import configparser
|
import configparser
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import interface_functions
|
||||||
|
import interface_variables
|
||||||
|
|
||||||
chosen_activity = None
|
chosen_activity = None
|
||||||
mount_point = None
|
|
||||||
|
|
||||||
def list_archives():
|
|
||||||
os.system('borg list | less')
|
|
||||||
|
|
||||||
def show_info():
|
|
||||||
archive_name = input("Please enter the archive name: ")
|
|
||||||
os.system('clear')
|
|
||||||
os.system('borg info ::' + archive_name)
|
|
||||||
print()
|
|
||||||
input("Press a key to continue.")
|
|
||||||
|
|
||||||
def mount_archive():
|
|
||||||
global mount_point
|
|
||||||
archive_name = input("Please enter the archive name: ")
|
|
||||||
mount_point = "/tmp/" + archive_name
|
|
||||||
if not os.path.exists(mount_point):
|
|
||||||
os.makedirs(mount_point)
|
|
||||||
os.system('borg mount ::' + archive_name + " " + mount_point)
|
|
||||||
print()
|
|
||||||
print("Archive mounted at " + mount_point + "/")
|
|
||||||
print()
|
|
||||||
|
|
||||||
def restore_archive():
|
|
||||||
archive_name = input("Please enter the archive name: ")
|
|
||||||
restore_path = input("Please enter the path where you want to "
|
|
||||||
"restore to: ")
|
|
||||||
if not os.path.exists(restore_path):
|
|
||||||
os.makedirs(restore_path)
|
|
||||||
p = subprocess.Popen(['borg', 'extract', '::' + archive_name]
|
|
||||||
,cwd=restore_path)
|
|
||||||
p.wait()
|
|
||||||
print()
|
|
||||||
print("Archive extracted to " + restore_path)
|
|
||||||
print()
|
|
||||||
|
|
||||||
def configuration():
|
|
||||||
# setup the config parser
|
|
||||||
config = configparser.ConfigParser()
|
|
||||||
# read config file
|
|
||||||
config.read('borg_interface.cfg')
|
|
||||||
# assign the repository variable
|
|
||||||
if 'server' in config:
|
|
||||||
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():
|
|
||||||
global mount_point
|
|
||||||
if (not mount_point):
|
|
||||||
print()
|
|
||||||
else:
|
|
||||||
print()
|
|
||||||
print("Unmount Archive and remove folder.")
|
|
||||||
print()
|
|
||||||
os.system('fusermount -u' + " " + mount_point)
|
|
||||||
os.rmdir(mount_point)
|
|
||||||
|
|
||||||
# The main menu starts there
|
# The main menu starts there
|
||||||
configuration()
|
interface_functions.configuration()
|
||||||
while chosen_activity != 0:
|
while chosen_activity != 0:
|
||||||
os.system('clear')
|
os.system('clear')
|
||||||
print("What would you like to do?")
|
print("What would you like to do?")
|
||||||
|
@ -84,17 +20,17 @@ while chosen_activity != 0:
|
||||||
if chosen_activity == 1:
|
if chosen_activity == 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
|
||||||
list_archives()
|
interface_functions.list_archives()
|
||||||
if chosen_activity == 2:
|
if chosen_activity == 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
|
||||||
show_info()
|
interface_functions.show_info()
|
||||||
if chosen_activity == 3:
|
if chosen_activity == 3:
|
||||||
# mounts a chosen archive to /tmp/archive name
|
# mounts a chosen archive to /tmp/archive name
|
||||||
mount_archive()
|
interface_functions.mount_archive()
|
||||||
if chosen_activity == 4:
|
if chosen_activity == 4:
|
||||||
restore_archive()
|
interface_functions.restore_archive()
|
||||||
elif chosen_activity == 0:
|
elif chosen_activity == 0:
|
||||||
exit()
|
interface_functions.exit()
|
||||||
except ValueError:
|
except ValueError:
|
||||||
print("Please enter a full number.")
|
print("Please enter a full number.")
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
import os
|
||||||
|
import configparser
|
||||||
|
import subprocess
|
||||||
|
import interface_variables
|
||||||
|
|
||||||
|
int_vars = interface_variables
|
||||||
|
|
||||||
|
def list_archives():
|
||||||
|
os.system('borg list | less')
|
||||||
|
|
||||||
|
def show_info():
|
||||||
|
archive_name = input("Please enter the archive name: ")
|
||||||
|
os.system('clear')
|
||||||
|
os.system('borg info ::' + archive_name)
|
||||||
|
print()
|
||||||
|
input("Press a key to continue.")
|
||||||
|
|
||||||
|
def mount_archive():
|
||||||
|
archive_name = input("Please enter the archive name: ")
|
||||||
|
int_vars.mount_point = "/tmp/" + archive_name
|
||||||
|
if not os.path.exists(int_vars.mount_point):
|
||||||
|
os.makedirs(int_vars.mount_point)
|
||||||
|
os.system('borg mount ::' + archive_name + " " + int_vars.mount_point)
|
||||||
|
print()
|
||||||
|
print("Archive mounted at " + int_vars.mount_point + "/")
|
||||||
|
print()
|
||||||
|
|
||||||
|
def restore_archive():
|
||||||
|
archive_name = input("Please enter the archive name: ")
|
||||||
|
restore_path = input("Please enter the path where you want to "
|
||||||
|
"restore to: ")
|
||||||
|
if not os.path.exists(restore_path):
|
||||||
|
os.makedirs(restore_path)
|
||||||
|
p = subprocess.Popen(['borg', 'extract', '::' + archive_name]
|
||||||
|
,cwd=restore_path)
|
||||||
|
p.wait()
|
||||||
|
print()
|
||||||
|
print("Archive extracted to " + restore_path)
|
||||||
|
print()
|
||||||
|
|
||||||
|
def configuration():
|
||||||
|
# setup the config parser
|
||||||
|
config = configparser.ConfigParser()
|
||||||
|
# read config file
|
||||||
|
config.read('borg_interface.cfg')
|
||||||
|
# assign the repository variable
|
||||||
|
print(config['DEFAULT']['server'])
|
||||||
|
if 'server' in config:
|
||||||
|
repository = (config['DEFAULT']['user']
|
||||||
|
+ "@"
|
||||||
|
+ config['DEFAULT']['server']
|
||||||
|
+ ":"
|
||||||
|
+ config['DEFAULT']['repository_path'])
|
||||||
|
print("remote archive")
|
||||||
|
else:
|
||||||
|
repository = config['DEFAULT']['repository_path']
|
||||||
|
print("local archive")
|
||||||
|
input()
|
||||||
|
# assign the password variable
|
||||||
|
password = config['DEFAULT']['password']
|
||||||
|
# set the environment variables
|
||||||
|
os.environ['BORG_REPO'] = repository
|
||||||
|
os.environ['BORG_PASSPHRASE'] = password
|
||||||
|
|
||||||
|
def exit():
|
||||||
|
if (not int_vars.mount_point):
|
||||||
|
print()
|
||||||
|
else:
|
||||||
|
print()
|
||||||
|
print("Unmount Archive and remove folder.")
|
||||||
|
print()
|
||||||
|
os.system('fusermount -u' + " " + int_vars.mount_point)
|
||||||
|
os.rmdir(int_vars.mount_point)
|
|
@ -0,0 +1 @@
|
||||||
|
mount_point = None
|
Reference in New Issue