diff -r 4f0e9cf8f230 -r 4f56142e7497 instance.py --- a/instance.py Fri Jan 26 10:35:00 2018 +0000 +++ b/instance.py Fri Jan 26 19:04:04 2018 +0000 @@ -6,8 +6,8 @@ import logging import os import borgend +from config import settings from subprocess import Popen, PIPE -from config import settings, arglistify logger=borgend.logger.getChild(__name__) @@ -19,25 +19,33 @@ 'list': ['--json'], } +# Conversion of config into command line +def arglistify(args): + flatten=lambda l: [item for sublist in l for item in sublist] + if args is None: + return [] + else: + return flatten([['--' + key, str(d[key])] for d in args for key in d]) + class BorgInstance: - def __init__(self, operation, archive_or_repository, args, argsl): + def __init__(self, operation, archive_or_repository, + common_params, op_params, paths): self.operation=operation; - self.args=args; self.archive_or_repository=archive_or_repository; - self.argsl=argsl; + self.common_params=common_params + self.op_params=op_params + self.paths=paths def construct_cmdline(self): cmd=([settings['borg']['executable']]+necessary_opts+ - arglistify(settings['borg']['common_parameters'])+ + arglistify(self.common_params)+ [self.operation]) - tmp1=self.operation+'_parameters' - if tmp1 in settings['borg']: - cmd=cmd+arglistify(settings['borg'][tmp1]) if self.operation in necessary_opts_for: cmd=cmd+necessary_opts_for[self.operation] - return cmd+arglistify(self.args)+[self.archive_or_repository]+self.argsl + return (cmd+arglistify(self.op_params) + +[self.archive_or_repository]+self.paths) def launch(self, passphrase=None): cmd=self.construct_cmdline()