예제 #1
0
def __shutdown_server():
    print_.info('INFO', 'Shutting Down Server')
    response = requests.get(f'{ENDPOINT}/shutdown').json()
    if response['code'] == 200:
        return 1, 1
    else:
        return 0, 1
예제 #2
0
 def change_state(self, change_to):
     ''' Changes the state of the observation based on the approved parameter\n
     approved=True => approved \n approved=False => denyed '''
     if self.state != change_to:
         self.state = change_to
         colored_state = f'{Fore.CYAN}\'{self.state.value}\'{Fore.RESET}'
         info(f'OBSER', f'{self._id} state changed to {colored_state}')
예제 #3
0
def stop_timer(time_start, description=None):
    ''' Calculates the elapsed time between the actual time and the passed time,
    prints the information, and returns the elapsed time '''
    time_stop = __get_time_in_ns()
    elapsed = round(time_stop - time_start)
    if description:
        print_.info('INFO', f'{elapsed} ns in {description}')
    return elapsed
예제 #4
0
def start_server(app, no_stdout, condition=None, host='localhost', port=5000):
    ''' Starts the application passed as parameter '''
    __custom_configuration(app, no_stdout)
    print_.title("Launching Modules")
    for module in karmaserver.modules.get_all_modules():
        app.register_blueprint(module)
    print_.title("Starting Server")
    print_.info('INFO', f'Starting Server at {host}:{port}')
    if condition:
        condition.notify()
        condition.release()
    app.run(host=host, port=port)
예제 #5
0
def runtests():
    ''' Runs all the configured tests '''
    if check_if_server_up('localhost', 5000):
        print_.info('INFO', 'Server Already Up')
        result = karmaserver.tests.run_all_tests()
    else:
        # condition = threading.Condition()
        thread = ThreadWithReturnValue(target=__call_tests, args=(None, ))
        thread.start()
        # condition.acquire()
        runserver(no_stdout=True, condition=None)
        result = thread.join()
    if result:
        sys.exit(0)
    else:
        sys.exit(-1)
예제 #6
0
def initdb():
    """Initializes the database."""
    db.create_all()
    print_.info('INFO', 'Database Created')