Index: cloud_sync.py =================================================================== diff -u -r78fd392821abf65d46d47982d391808a02c34249 -rc7fd30aa9eafcefd698820e703b3313a8286cde9 --- cloud_sync.py (.../cloud_sync.py) (revision 78fd392821abf65d46d47982d391808a02c34249) +++ cloud_sync.py (.../cloud_sync.py) (revision c7fd30aa9eafcefd698820e703b3313a8286cde9) @@ -32,14 +32,37 @@ sleep(5) # wait for UI to prepare the configurations partition + +# set the execution mode regarding the passed command line argumment + try: - if os.path.isfile(OPERATION_CONFIG_FILE_PATH) and os.access(OPERATION_CONFIG_FILE_PATH, os.R_OK): - g_config = helpers_read_config(OPERATION_CONFIG_FILE_PATH) - CONFIG_PATH = OPERATION_CONFIG_FILE_PATH + ok = False + print(SETUP_CONSOLE_LINE) + + if EXEC_MODE_REGISTRATION_KEY in arguments: + # Read from $HOME + if os.path.isfile(CONFIG_PATH) and os.access(CONFIG_PATH, os.R_OK | os.W_OK): + g_config = helpers_read_config(CONFIG_PATH) + EXEC_MODE = EXEC_MODE_REGISTRATION + ok = True else: - g_config = helpers_read_config(CONFIG_PATH) + # Read from /var/configuraitons/ + if os.path.isfile(OPERATION_CONFIG_FILE_PATH) and os.access(OPERATION_CONFIG_FILE_PATH, os.R_OK): + g_config = helpers_read_config(OPERATION_CONFIG_FILE_PATH) + CONFIG_PATH = OPERATION_CONFIG_FILE_PATH + ok = True + + if ok: + print("CloudSync started in {0} mode".format(EXEC_MODE)) + print("Using config: ".format(CONFIG_PATH)) + else: + g_utils.logger.error("Error reading config file in {0}".format(EXEC_MODE)) + + print(SETUP_CONSOLE_LINE) + except Exception as e: g_utils.logger.error("Error reading config file - {0}".format(e)) + print(SETUP_CONSOLE_LINE) sys.exit(0) try: Index: cloudsync/utils/globals.py =================================================================== diff -u -r78fd392821abf65d46d47982d391808a02c34249 -rc7fd30aa9eafcefd698820e703b3313a8286cde9 --- cloudsync/utils/globals.py (.../globals.py) (revision 78fd392821abf65d46d47982d391808a02c34249) +++ cloudsync/utils/globals.py (.../globals.py) (revision c7fd30aa9eafcefd698820e703b3313a8286cde9) @@ -35,6 +35,15 @@ # DEFAULTS DEFAULT_REACHABILITY_URL = "https://google.com" +# CONSOLE OUT +SETUP_CONSOLE_LINE="--------------------------------------------------------------------------------" + +# EXECUTION MODE +EXEC_MODE_REGISTRATION='registration' +EXEC_MODE_REGISTRATION_KEY=EXEC_MODE_REGISTRATION +EXEC_MODE_OPERATION='operation' +EXEC_MODE=EXEC_MODE_OPERATION + # CONFIG CONFIG_PATH = os.path.join(PATH_HOME, "cloudsync/config/config.json") Index: cs.py =================================================================== diff -u -re2b5bba1ace2613e8cd3ca6d997756b1b61d77a4 -rc7fd30aa9eafcefd698820e703b3313a8286cde9 --- cs.py (.../cs.py) (revision e2b5bba1ace2613e8cd3ca6d997756b1b61d77a4) +++ cs.py (.../cs.py) (revision c7fd30aa9eafcefd698820e703b3313a8286cde9) @@ -8,14 +8,14 @@ import time import logging from subprocess import Popen +from cloudsync.utils.globals import EXEC_MODE_OPERATION, EXEC_MODE_REGISTRATION, EXEC_MODE DELAY = 0.5 -USAGE_FORMAT = "Usage: ./cs.py [debug|info|warning|error]" +USAGE_FORMAT = "Usage: ./cs.py [debug|info|warning|error] [registration|]" arguments = sys.argv logging_level = logging.INFO - def get_pid(): proc_list = list(os.popen("ps ax | grep cloud_sync.py | grep -v grep")) if len(proc_list) > 0: @@ -30,9 +30,9 @@ if cs_proc: print("CloudSync app already running") else: - print("Starting CloudSync app with logging level {0}".format(logging_level)) + print("Starting CloudSync app with logging level {0} in {1} mode".format(logging_level,EXEC_MODE)) time.sleep(DELAY) - Popen(['python3', 'cloud_sync.py', str(logging_level)]) + Popen(['python3', 'cloud_sync.py', str(logging_level),EXEC_MODE]) def stop(): @@ -45,34 +45,54 @@ print("CloudSync app is not running.") -if len(arguments) == 2 or len(arguments) == 3: - if len(arguments) == 3: - if arguments[2] == "debug": - logging_level = logging.DEBUG - elif arguments[2] == "info": - logging_level = logging.INFO - elif arguments[2] == "warning": - logging_level = logging.WARNING - elif arguments[2] == "error": - logging_level = logging.ERROR - else: - print(USAGE_FORMAT) - if arguments[1] == "start": +if len(arguments) <= 1: + print(USAGE_FORMAT) + sys.exit(101) + +if len(arguments) >= 4: + argument=arguments[3] + if argument == EXEC_MODE_REGISTRATION: + EXEC_MODE=EXEC_MODE_REGISTRATION + elif argument == EXEC_MODE_OPERATION: + EXEC_MODE=EXEC_MODE_OPERATION + else: + print("incorrect {0} argument".format(argument)) + print(USAGE_FORMAT) + sys.exit(104) + +if len(arguments) >= 3: + argument=arguments[2] + if argument == "debug": + logging_level = logging.DEBUG + elif argument == "info": + logging_level = logging.INFO + elif argument == "warning": + logging_level = logging.WARNING + elif argument== "error": + logging_level = logging.ERROR + else: + print("incorrect {0} argument".format(argument)) + print(USAGE_FORMAT) + sys.exit(103) + +if len(arguments) >= 2: + argument=arguments[1] + if argument == "start": start() - elif str(arguments[1]) == "stop": + elif argument == "stop": stop() - elif arguments[1] == "restart": + elif argument == "restart": print("Restarting CloudSync app...") time.sleep(DELAY) stop() start() - elif arguments[1] == "status": + elif argument == "status": cs_proc = get_pid() if cs_proc: print("CloudSync app IS running") else: print("CloudSync app IS NOT running") else: + print("incorrect {0} argument".format(argument)) print(USAGE_FORMAT) -else: - print(USAGE_FORMAT) + sys.exit(102) \ No newline at end of file