instance.py

changeset 2
e343594c0014
parent 1
4cdc9c1f6b28
child 3
4cad934aa9ce
--- a/instance.py	Thu Jan 18 23:01:16 2018 +0000
+++ b/instance.py	Fri Jan 19 10:41:01 2018 +0000
@@ -3,12 +3,12 @@
 #
 
 import json
-import subprocess
-import config
-import Queue
-import Thread
+from subprocess import Popen, PIPE
+from config import settings, arglistify
+from queue import Queue
+from threading import Thread
 
-def linereader(stream, instance, queue)
+def linereader(stream, instance, queue):
     # What to do on error?
     for line in iter(stream.readline, b''):
         status=json.loads(line)
@@ -19,19 +19,25 @@
 
 class BorgInstance:
 
-    def __init__(self, identifier, operation, args):
+    def __init__(self, identifier, operation, args, archive, argsl):
         self.identifier=identifier;
         self.operation=operation;
         self.args=args;
+        self.archive=archive;
+        self.argsl=argsl;
 
     def construct_cmdline(self):
-        ???
+        cmd=([settings['borg']['executable'], '--log-json']+
+             arglistify(settings['borg']['common_parameters'])+
+             [self.operation])
+        tmp1=self.operation+'_parameters'
+        if tmp1 in settings['borg']:
+            cmd=cmd+arglistify(settings['borg'][tmp1])
+        return cmd+arglistify(self.args)+[self.archive]+self.argsl
 
     def launch(self, queue):
         # What to do with stderr? Is it needed?
-        self.proc=subprocess.Popen(self.construct_cmdline(),
-                                   stdout=subprocess.PIPE,
-                                   stderr=subprocess.PIPE)
+        self.proc=Popen(self.construct_cmdline(), stdout=PIPE, stderr=PIPE)
         linereaderargs=(self.proc.stdout, self, queue)
         self.t=Thread(target=linereader, args=linereaderargs)
         t.daemon=True

mercurial