17 |
17 |
18 necessary_opts_for={ |
18 necessary_opts_for={ |
19 'create': ['--json'], |
19 'create': ['--json'], |
20 'info': ['--json'], |
20 'info': ['--json'], |
21 'list': ['--json'], |
21 'list': ['--json'], |
|
22 'prune': ['--list'], |
22 } |
23 } |
23 |
24 |
24 # Conversion of config into command line |
25 # Conversion of config into command line |
25 def arglistify(args): |
26 def arglistify(args): |
26 flatten=lambda l: [item for sublist in l for item in sublist] |
27 flatten=lambda l: [item for sublist in l for item in sublist] |
27 if args is None: |
28 if args is None: |
28 return [] |
29 return [] |
29 else: |
30 else: |
30 return flatten([['--' + key, str(d[key])] for d in args for key in d]) |
31 # Insert --key=str(value) for 'key: value' in the config. |
|
32 # Boolean values are handled different, since borg does not take |
|
33 # --key=true type of arguments. If the value is true --key is inserted, |
|
34 # otherwise not. |
|
35 def mkarg(key, value): |
|
36 if isinstance(value, bool): |
|
37 if value: |
|
38 return ['--' + key] |
|
39 else: |
|
40 return [] |
|
41 else: |
|
42 return ['--' + key, str(value)] |
|
43 return flatten([mkarg(key, d[key]) for d in args for key in d]) |
31 |
44 |
32 class BorgInstance: |
45 class BorgInstance: |
33 def __init__(self, operation, archive_or_repository, |
46 def __init__(self, operation, archive_or_repository, |
34 common_params, op_params, paths): |
47 common_params, op_params, paths): |
35 self.operation=operation; |
48 self.operation=operation; |
115 res=json.loads(line.decode()) |
128 res=json.loads(line.decode()) |
116 if 'type' not in res: |
129 if 'type' not in res: |
117 res['type']='UNKNOWN' |
130 res['type']='UNKNOWN' |
118 return res |
131 return res |
119 except: |
132 except: |
120 logger.exception('JSON parse failed on: %s' % str(line)) |
133 logger.exception('JSON parse failed on stderr: %s' % str(line)) |
121 |
134 |
122 errmsg=line |
135 errmsg=line |
123 for line in iter(stream.readline, b''): |
136 for line in iter(stream.readline, b''): |
124 errmsg=errmsg+line |
137 errmsg=errmsg+line |
125 |
138 |