add a function to check for various configuration locations

This commit is contained in:
Andreas Zweili 2016-12-14 22:27:57 +01:00
parent 0b31b6f4b1
commit d61a78c5f1
2 changed files with 16 additions and 5 deletions

View File

@ -1,5 +1,5 @@
[DEFAULT]
#server: fileserver.2li.local
#user: borg
# server: fileserver.2li.local
# user: borg
repository_path: /home/andreas/test
password: foo

View File

@ -44,9 +44,20 @@ def restore_archive():
def configuration():
# setup the config parser
config = configparser.ConfigParser()
# read config file
config.read('borg_interface.cfg')
# assign the repository variable
# check whether the config file exists either in the home folder or next to
# the binary
home = os.getenv('HOME')
if os.path.isfile(home + '/.config/borg_interface/borg_interface.cfg'):
config.read(home + '/.config/borg_interface/borg_interface.cfg')
elif os.path.isfile(home + '/.borg_interface.cfg'):
config.read(home + '/.borg_interface.cfg')
elif os.path.isfile('borg_interface.cfg'):
config.read('borg_interface.cfg')
else:
print("Configuration file not found.")
quit()
# assign the repository variable depending wheter it's a remote or a local
# repository
if 'server' in config['DEFAULT']:
repository = (config['DEFAULT']['user']
+ "@"