Current progress
This commit is contained in:
parent
8d3be057a8
commit
b764bac090
|
@ -6,7 +6,7 @@ import os
|
|||
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
|
||||
disks_by_uuid = "/dev/disk/by-uuid"
|
||||
|
|
|
@ -3,10 +3,13 @@
|
|||
"""
|
||||
Service startup script.
|
||||
"""
|
||||
from backive.core.events import EventInterface
|
||||
|
||||
|
||||
class Backive:
|
||||
def __init__(self):
|
||||
pass
|
||||
self._config = None
|
||||
self._events = None
|
||||
|
||||
def serve(self):
|
||||
pass
|
||||
|
|
|
@ -7,7 +7,8 @@ definitions:
|
|||
device_section:
|
||||
type: object
|
||||
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
|
||||
properties:
|
||||
name:
|
||||
|
|
|
@ -1,24 +1,26 @@
|
|||
import os
|
||||
import socket
|
||||
import asyncio
|
||||
|
||||
|
||||
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
|
||||
)
|
||||
def __init__(self, event_callback, unix_socket_path=None, loop=None):
|
||||
self.event_callback = event_callback
|
||||
if not unix_socket_path:
|
||||
unix_socket_path = "/tmp/backive/backive.sock"
|
||||
if not os.path.exists(os.path.dirname(unix_socket_path)):
|
||||
os.makedirs(os.path.dirname(unix_socket_path))
|
||||
try:
|
||||
os.remove(unix_socket)
|
||||
os.remove(unix_socket_path)
|
||||
except OSError:
|
||||
pass
|
||||
self.socket.bind(unix_socket)
|
||||
self.socket.listen()
|
||||
|
||||
def accept(self):
|
||||
return self.socket.accept()
|
||||
if not loop:
|
||||
loop = asyncio.get_running_loop()
|
||||
loop.create_task(asyncio.start_unix_server(self.client_connected, unix_socket_path))
|
||||
|
||||
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