Current progress
This commit is contained in:
parent
8d3be057a8
commit
b764bac090
|
@ -6,7 +6,7 @@ import os
|
||||||
import pwd
|
import pwd
|
||||||
|
|
||||||
|
|
||||||
logging.basicConfig(format='%(asctime)s->%(name)s@%(levelname)s: %(message)s', filename=sys.stdout, level=logging.INFO)
|
logging.basicConfig(format='%(asctime)s->%(name)s@%(levelname)s: %(message)s', level=logging.INFO)
|
||||||
|
|
||||||
got_signal = False
|
got_signal = False
|
||||||
disks_by_uuid = "/dev/disk/by-uuid"
|
disks_by_uuid = "/dev/disk/by-uuid"
|
||||||
|
|
|
@ -3,10 +3,13 @@
|
||||||
"""
|
"""
|
||||||
Service startup script.
|
Service startup script.
|
||||||
"""
|
"""
|
||||||
|
from backive.core.events import EventInterface
|
||||||
|
|
||||||
|
|
||||||
class Backive:
|
class Backive:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
self._config = None
|
||||||
|
self._events = None
|
||||||
|
|
||||||
def serve(self):
|
def serve(self):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -7,7 +7,8 @@ definitions:
|
||||||
device_section:
|
device_section:
|
||||||
type: object
|
type: object
|
||||||
patternProperties:
|
patternProperties:
|
||||||
"^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$":
|
"^[^ \t/\\]+$":
|
||||||
|
# "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$":
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
name:
|
name:
|
||||||
|
|
|
@ -1,24 +1,26 @@
|
||||||
import os
|
import os
|
||||||
import socket
|
import asyncio
|
||||||
|
|
||||||
|
|
||||||
class EventInterface:
|
class EventInterface:
|
||||||
def __init__(self, unix_socket=None):
|
def __init__(self, event_callback, unix_socket_path=None, loop=None):
|
||||||
if not unix_socket:
|
self.event_callback = event_callback
|
||||||
unix_socket = "/tmp/backive/backive.sock"
|
if not unix_socket_path:
|
||||||
self.socket = socket.socket(
|
unix_socket_path = "/tmp/backive/backive.sock"
|
||||||
socket.AF_UNIX,
|
if not os.path.exists(os.path.dirname(unix_socket_path)):
|
||||||
socket.SOCK_STREAM
|
os.makedirs(os.path.dirname(unix_socket_path))
|
||||||
)
|
|
||||||
try:
|
try:
|
||||||
os.remove(unix_socket)
|
os.remove(unix_socket_path)
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
self.socket.bind(unix_socket)
|
if not loop:
|
||||||
self.socket.listen()
|
loop = asyncio.get_running_loop()
|
||||||
|
loop.create_task(asyncio.start_unix_server(self.client_connected, unix_socket_path))
|
||||||
def accept(self):
|
|
||||||
return self.socket.accept()
|
|
||||||
|
|
||||||
|
async def client_connected(self, reader, writer):
|
||||||
|
print("client_connected")
|
||||||
|
data = None
|
||||||
|
data = (await reader.read()).decode('utf8')
|
||||||
|
self.event_callback(data)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue