instance.py

Thu, 18 Jan 2018 23:01:16 +0000

author
Tuomo Valkonen <tuomov@iki.fi>
date
Thu, 18 Jan 2018 23:01:16 +0000
changeset 1
4cdc9c1f6b28
parent 0
BorgInstance.py@f5aecaad0bcf
child 2
e343594c0014
permissions
-rw-r--r--

basic scheduler structure draft, etc.

#
# Borgend borg launcher / processor
#

import json
import subprocess
import config
import Queue
import Thread

def linereader(stream, instance, queue)
    # What to do on error?
    for line in iter(stream.readline, b''):
        status=json.loads(line)
        queue.put({'identifier': instance.identifier,
                   'operation': instance.operation,
                   'status': status})
    out.close()

class BorgInstance:

    def __init__(self, identifier, operation, args):
        self.identifier=identifier;
        self.operation=operation;
        self.args=args;

    def construct_cmdline(self):
        ???

    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)
        linereaderargs=(self.proc.stdout, self, queue)
        self.t=Thread(target=linereader, args=linereaderargs)
        t.daemon=True
        t.start()

    def read_output():
        try:
            obj=self.queue.get_nowait()
        except Empty:
            obj=Empty
        return obj



mercurial