Ejemplo n.º 1
0
    def listen_server(rabbitmq_username, rabbitmq_password, host,
                      data_changed_flags2, queue, scoreboard, channel):
        print('[ LISTEN ] Start listening...')
        start_listening.authenticate_login = handle_config.read_config_json()
        conn, cursor = manage_database.initialize_table()
        manage_local_ids.initialize_local_id(cursor)
        start_listening.cursor = cursor
        try:
            # creds = pika.PlainCredentials(rabbitmq_username, rabbitmq_password)
            # params = pika.ConnectionParameters(host = host, credentials = creds, heartbeat=0, blocked_connection_timeout=0)
            # connection = pika.BlockingConnection(params)
            # channel = connection.channel()
            start_listening.channel = channel
            # start_listening.connection = connection
            start_listening.host = host
            start_listening.data_changed_flags = data_changed_flags2
            start_listening.queue = queue
            start_listening.scoreboard = scoreboard

            start_listening.channel.basic_consume(
                queue=start_listening.authenticate_login["Username"],
                on_message_callback=start_listening.server_response_handler,
                auto_ack=True)
            start_listening.channel.start_consuming()
        except (KeyboardInterrupt, SystemExit):
            print('[ DELETE ] Queue ' +
                  start_listening.authenticate_login["Username"] +
                  ' deleted...')
            print("[ STOP ] Keyboard interrupt")
            start_listening.channel.stop_consuming()
            start_listening.channel.queue_delete(
                start_listening.authenticate_login["Username"])
            return
        except Exception as error:
            print('[ ERROR ] Shit ', error)
Ejemplo n.º 2
0
from database_management import manage_database
import os

rabbitmq_username = '******'
rabbitmq_password = '******'
host = 'localhost'

conn, cur = manage_database.initialize_table()
manage_database.reset_database(conn)

for i in os.listdir('./Solution/'):
	os.remove('./Solution/'+i)
Ejemplo n.º 3
0
def main():
    #################################
    # Initialize the database and returns the cursor
    print("[ SETUP ] INITIALISING DATABASE ............")
    conn, cursor = manage_database.initialize_table()
    manage_local_ids.initialize_local_id(cursor)

    ##################################
    # Create variables/lists that will be shared between processes
    data_changed_flags = multiprocessing.Array('i', 10)
    queue = multiprocessing.Queue()
    scoreboard = multiprocessing.Queue()
    for i in range(10):
        data_changed_flags[i] = 0
    # index    value         meaning
    # 0        0/1/2/3/4     Contest Not Started/Contest has been started/Running/Contest Stopped/Time Up
    # 1        0/1/2         Initialize/Verdict Not received/Verdict Received
    # 2        0/1/2         Initiaize/Query response Not received/Query response received
    # 3        1             Server NOt Accepting Submission
    # 4        0/1/3         Timer Stopped/ Timer running/Update Timer
    # 5        0/1/2         Proper Connection/Single Client Disconnected/All Clients Disconnected
    # 6        1             Leader Board Update
    # 7        1             Problem Edited
    # 8        1             Blockd user
    # 9        1             run id received

    ##################################
    # Makes connection with RabbitMQ
    # And returns channel,connection
    print("[ SETUP ] ESTABLISHING CONNECTION .........")
    try:
        channel, connection = manage_connection.initialize_connection(
            rabbitmq_username, rabbitmq_password, host)
    except Exception as error:
        print(str(error))

    try:
        print("----------------BitsOJ v1.0----------------")
        # Starting GUI for login portal
        start_interface(connection, data_changed_flags, queue)
        print("[ LOGIN ] Successful")

    except Exception as error:
        ex_type, ex_obj, ex_tb = sys.exc_info()
        f_name = os.path.split(ex_tb.tb_frame.f_code.co_filename)[1]
        print(ex_type, f_name, ex_tb.tb_lineno)
        print("[ CRITICAL ] GUI could not be loaded! " + str(error))

    try:
        # Manage Threads
        print('[ SETUP ] Initialising threads....')
        listen_pid = manage_process(rabbitmq_username, rabbitmq_password,
                                    cursor, host, data_changed_flags, queue,
                                    scoreboard)

    except Exception as error:
        ex_type, ex_obj, ex_tb = sys.exc_info()
        f_name = os.path.split(ex_tb.tb_frame.f_code.co_filename)[1]
        print(ex_type, f_name, ex_tb.tb_lineno)
        print("[ CRITICAL ] GUI could not be loaded! " + str(error))

    try:

        # After successful login
        # Starting Main GUI
        init_gui(channel, data_changed_flags, queue, scoreboard)
    except Exception as error:
        ex_type, ex_obj, ex_tb = sys.exc_info()
        f_name = os.path.split(ex_tb.tb_frame.f_code.co_filename)[1]
        print(ex_type, f_name, ex_tb.tb_lineno)
        print("[ CRITICAL ] GUI could not be loaded! " + str(error))

    print("[EXIT] Signal Passed")
    os.kill(listen_pid, signal.SIGINT)

    sleep(1)
    print("  ################################################")
    print("  #----------ClIENT CLOSED SUCCESSFULLY----------#")
    print("  ################################################")