# HG changeset patch # User Tuomo Valkonen # Date 1516311720 0 # Node ID f5aecaad0bcff151536c9ec8af8fca7ed7d54fd7 Some rough drafting diff -r 000000000000 -r f5aecaad0bcf BorgInstance.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BorgInstance.py Thu Jan 18 21:42:00 2018 +0000 @@ -0,0 +1,49 @@ +# +# 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 + + + + diff -r 000000000000 -r f5aecaad0bcf borgend.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/borgend.py Thu Jan 18 21:42:00 2018 +0000 @@ -0,0 +1,22 @@ +#!/usr/local/bin/python3 +import rumps +#import json +#import multiprocessing as mp +import threading as th +import queue +from pkg_resources import resource_string +from config import settings + +# f=io.open('status.json', 'r'); +# data=json.load(f); + +class BorgendTray(rumps.App): + @rumps.clicked("Status...") + def prefs(self, _): + rumps.alert("None") + + +if __name__ == "__main__": + print(settings) + #BorgendTray("Borgend").run() + diff -r 000000000000 -r f5aecaad0bcf config.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/config.py Thu Jan 18 21:42:00 2018 +0000 @@ -0,0 +1,30 @@ +# +# Borgend configuration loader +# + +import yaml +import io +import os +import xdg +import string + + +def expand_env(cfg, env): + if isinstance(cfg, dict): + out={key: expand_env(val, env) for key, val in cfg.items()} + elif isinstance(cfg, list): + out=[expand_env(val, env) for val in cfg] + elif isinstance(cfg, str): + out=string.Template(cfg).substitute(os.environ) + else: + out=cfg + + return out + +cfgfile=os.path.join(xdg.XDG_CONFIG_HOME, "borgend", "config.yaml") + +if not (os.path.exists(cfgfile) and os.path.isfile(cfgfile)): + raise SystemExit(f'Configuration file required: {cfgfile}') + +with io.open(cfgfile, 'r') as file: + settings=expand_env(yaml.load(file), os.environ);