# HG changeset patch # User Tuomo Valkonen # Date 1516316476 0 # Node ID 4cdc9c1f6b281d224d800724689ae17e0911c5d2 # Parent f5aecaad0bcff151536c9ec8af8fca7ed7d54fd7 basic scheduler structure draft, etc. diff -r f5aecaad0bcf -r 4cdc9c1f6b28 BorgInstance.py --- a/BorgInstance.py Thu Jan 18 21:42:00 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -# -# 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 f5aecaad0bcf -r 4cdc9c1f6b28 backup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/backup.py Thu Jan 18 23:01:16 2018 +0000 @@ -0,0 +1,13 @@ +# +# Borgend Backup instance +# + +class Backup: + + def __init__(self, identifier, config): + self.config=config + self.identifier=identifier + self.lastrun=None + + + diff -r f5aecaad0bcf -r 4cdc9c1f6b28 borgend.py --- a/borgend.py Thu Jan 18 21:42:00 2018 +0000 +++ b/borgend.py Thu Jan 18 23:01:16 2018 +0000 @@ -1,22 +1,20 @@ #!/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") - +from backup import Backup +from config import settings +import ui +import queue +import scheduler if __name__ == "__main__": print(settings) #BorgendTray("Borgend").run() - + +backupconfigs=settings['backups'] +backups=[None]*len(backupconfigs); + +for i in range(len(backupconfigs)): + backups[i]=Backup(i, backupconfigs[i]) + + +schedul \ No newline at end of file diff -r f5aecaad0bcf -r 4cdc9c1f6b28 config.py --- a/config.py Thu Jan 18 21:42:00 2018 +0000 +++ b/config.py Thu Jan 18 23:01:16 2018 +0000 @@ -28,3 +28,4 @@ with io.open(cfgfile, 'r') as file: settings=expand_env(yaml.load(file), os.environ); + diff -r f5aecaad0bcf -r 4cdc9c1f6b28 instance.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/instance.py Thu Jan 18 23:01:16 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 f5aecaad0bcf -r 4cdc9c1f6b28 scheduler.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scheduler.py Thu Jan 18 23:01:16 2018 +0000 @@ -0,0 +1,24 @@ +# +# Borgend scheduler +# + +from Queue import Queue +from runborg import BorgInstance +import sched +import ui + +def scheduler(sched): + timeout=??? + q=sched.eventqueue + while True: + timeout, timerevent=next_timed_event(sched); + t=Timer(timeout, lambda: q.put(timerevent)); + event=sq.get(True): + # Decide what to do + +class Scheduler: + + def __init__(self, backups): + self.backups=backups + self.eventqueue=Queue() + self.t=Thread(target=scheduler, args=self) diff -r f5aecaad0bcf -r 4cdc9c1f6b28 ui.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui.py Thu Jan 18 23:01:16 2018 +0000 @@ -0,0 +1,10 @@ +# +# MacOS UI +# + +import rumps + +class BorgendTray(rumps.App): + @rumps.clicked("Status...") + def prefs(self, _): + rumps.alert("None")