Thu, 18 Jan 2018 23:01:16 +0000
basic scheduler structure draft, etc.
BorgInstance.py | file | annotate | diff | comparison | revisions | |
backup.py | file | annotate | diff | comparison | revisions | |
borgend.py | file | annotate | diff | comparison | revisions | |
config.py | file | annotate | diff | comparison | revisions | |
instance.py | file | annotate | diff | comparison | revisions | |
scheduler.py | file | annotate | diff | comparison | revisions | |
ui.py | file | annotate | diff | comparison | revisions |
--- 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 - - - -
--- /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 + + +
--- 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
--- 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); +
--- /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 + + + +
--- /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)