-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommit_database_server.py
More file actions
executable file
·57 lines (45 loc) · 1.71 KB
/
commit_database_server.py
File metadata and controls
executable file
·57 lines (45 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python3
from __future__ import annotations
import argparse, os
import signal
from dsviper import Cancelation, CommitDatabase, CommitDatabaseServer, LoggerConsole, LoggerNull, Logging, Socket
cancelation = Cancelation()
def signal_handler(sig, frame):
print("Server cancelation requested...\n")
cancelation.cancel()
signal.signal(signal.SIGINT, signal_handler)
parser = argparse.ArgumentParser()
parser.add_argument("-v", "--verbose", help="display activity", action="count")
parser.add_argument("--host", help="the host of the source", default="0.0.0.0")
parser.add_argument("--port", help="the port of the source if not defined 54321", type=int, default=54321)
parser.add_argument("--socket-path", help="the path to the socket of the source")
parser.add_argument('database', help='the Commit database')
args = parser.parse_args()
if not CommitDatabase.is_compatible(args.database):
print("Not a Commit Database.")
exit(0)
level = Logging.LEVEL_ALL
if args.verbose:
if args.verbose == 1:
level = Logging.LEVEL_CRITICAL
elif args.verbose == 2:
level = Logging.LEVEL_INFO
else:
level = Logging.LEVEL_DEBUG
logging = LoggerNull().logging()
if args.verbose:
logging = LoggerConsole(level).logging()
socket: Socket | None = None
if args.socket_path:
if os.path.exists(args.socket_path):
os.remove(args.socket_path)
socket = Socket.create_passive_local(args.socket_path)
else:
socket = Socket.create_passive_inet(args.host, str(args.port))
server = CommitDatabaseServer(args.database, socket, logging, cancelation)
server.start()
while server.step():
if cancelation.requested():
break
server.finish()
print("The server finished gracefully.")