From 8d3be057a88f2c13fb5a44eea43855779e518277 Mon Sep 17 00:00:00 2001 From: Marcel Otte Date: Sun, 24 Feb 2019 22:42:36 +0100 Subject: [PATCH] Another bit --- backive/backive_service | 12 ++++++++++++ backive/backive_udev | 10 ++++++++++ backive/core/backup.py | 6 ++---- backive/core/events.py | 24 ++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 backive/core/events.py diff --git a/backive/backive_service b/backive/backive_service index 7ec659f..eb83a62 100644 --- a/backive/backive_service +++ b/backive/backive_service @@ -3,3 +3,15 @@ """ Service startup script. """ + +class Backive: + def __init__(self): + pass + + def serve(self): + pass + + +if __name__ == "__main__": + backive = Backive() + backive.serve() diff --git a/backive/backive_udev b/backive/backive_udev index b41c127..12204d7 100644 --- a/backive/backive_udev +++ b/backive/backive_udev @@ -3,3 +3,13 @@ """ Callable script for udev rules. """ +import socket +import sys + +unix_socket = "/tmp/backive/backive.sock" + +sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) +sock.connect(unix_socket) +if len(sys.argv) > 1: + sock.send(sys.argv[1].encode()) +sock.close() diff --git a/backive/core/backup.py b/backive/core/backup.py index 65dca4b..c354ed8 100644 --- a/backive/core/backup.py +++ b/backive/core/backup.py @@ -2,11 +2,9 @@ import os class Backup: - - config = {} - def __init__(self, name, cfg=None): - pass + self.name = name + self.config = cfg def run(self): pass diff --git a/backive/core/events.py b/backive/core/events.py new file mode 100644 index 0000000..36a8019 --- /dev/null +++ b/backive/core/events.py @@ -0,0 +1,24 @@ +import os +import socket + + +class EventInterface: + def __init__(self, unix_socket=None): + if not unix_socket: + unix_socket = "/tmp/backive/backive.sock" + self.socket = socket.socket( + socket.AF_UNIX, + socket.SOCK_STREAM + ) + try: + os.remove(unix_socket) + except OSError: + pass + self.socket.bind(unix_socket) + self.socket.listen() + + def accept(self): + return self.socket.accept() + + +