53 lines
1.8 KiB
Python
53 lines
1.8 KiB
Python
import argparse
|
|
import asyncio
|
|
import os
|
|
from . import user_service, sys_service
|
|
from .sys_service import rpc
|
|
from .user_service import rpc
|
|
del rpc
|
|
|
|
|
|
def main(args):
|
|
# Parser
|
|
parser = argparse.ArgumentParser("home-backup", description="Manage backup tools")
|
|
parser.add_argument("--sys-server", dest="sys_server", action="store_const", const=True, default=False, help="Run system service (root required).")
|
|
parser.add_argument("--user-server", dest="user_server", action="store_const", const=True, default=False, help="Run user service.")
|
|
|
|
# Arguments
|
|
if not args:
|
|
args = ["--help"]
|
|
result = parser.parse_args(args)
|
|
|
|
def check_client_args_exists():
|
|
return False
|
|
|
|
# Deamon mode
|
|
if not isinstance(result.sys_server, bool):
|
|
raise RuntimeError("Arg parser has the wrong type.")
|
|
if not isinstance(result.user_server, bool):
|
|
raise RuntimeError("Arg parser has the wrong type.")
|
|
if result.sys_server and result.user_server:
|
|
raise ValueError("System and user service can't be set simultan.")
|
|
if result.sys_server:
|
|
# Checks
|
|
if check_client_args_exists():
|
|
raise RuntimeError("Client settings are setting in system service mode.")
|
|
if os.getuid() != 0: # Check root
|
|
raise RuntimeError("System service has to run as root.")
|
|
|
|
# Run deamon
|
|
asyncio.run(sys_service.rpc.run_deamon()) # TODO: Change default path
|
|
elif result.user_server:
|
|
# Checks
|
|
if check_client_args_exists():
|
|
raise RuntimeError("Client settings are setting in system service mode.")
|
|
|
|
# Run deamon
|
|
asyncio.run(user_service.rpc.run_deamon()) # TODO: Change default path of user and system socket
|
|
else:
|
|
raise NotImplementedError()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import sys
|
|
main(sys.argv[1:]) |