Beispiel #1
0
def main():
    logging.config.fileConfig('cfg/logging.cfg')
    cl_args = sys.argv
    log.info("args: %s" % cl_args)

    if 'red' in cl_args:
        analize_project()

    if 'app' in cl_args:
        port = int(os.environ.get('PORT', 5000))
        app.run(host='0.0.0.0', port=port, debug=True)
Beispiel #2
0
def main():

    if len(sys.argv) < 3:

        print("python run.py <DB_TYPE> <DB_NAME>")

    elif len(sys.argv) > 3:

        print("Too many variables. You are prohibited to run the webapp")

    else:

        os.environ["DB_TYPE"] = sys.argv[1]
        os.environ["DB_NAME"] = sys.argv[2]

        from app.webapp import app

        app.run(host="127.0.0.1", port=5000)

        del os.environ["DB_TYPE"]
        del os.environ["DB_NAME"]
Beispiel #3
0
    def get_webapp(self):

        from app.webapp import app

        app.run(host="127.0.0.1", port=5000)
from app.webapp import app

import os

if __name__ == '__main__':
    app.run(host=os.getenv("IP", "0.0.0.0"), port=int(os.getenv("PORT", 4000)))
Beispiel #5
0
from app.webapp import app

if __name__ == "__main__":
    app.run()
Beispiel #6
0
from app.webapp import app

if __name__ == "__main__":
    app.run(host="0.0.0.0", debug=True)
Beispiel #7
0
def database_interface(database_type: str, db_nickname: str=None):

    command_buffer = None

    command_keys = [
        "r", #return to previous command
        "t", #execute previous command
        "table", #display table inside the database
        "db", #List out all the registered database
        "help", #Look for help
        "h" #Look for help 
    ]

    if db_nickname:
    
        received_command = front_prompt(database_type, db_nickname)
    
    else:

        received_command = front_prompt(database_type)

    os.environ["DB_TYPE"] = database_type

    if database_type == "sqlite3":

        db_client = DBInterface("sqlite3", sqlite3_filename=db_nickname)
        os.environ["DB_NAME"] = db_nickname

    else:        
    
        db_client = DBInterface(database_type, db_nickname=db_nickname)
        os.environ["DB_NAME"] = db_nickname

    db_client.connect()

    while (received_command not in exit_command_list):

        try:

            if (received_command in command_keys) or re.search(r"save\s.+", received_command):

                db_client.command_interface(received_command, command_buffer)

            elif re.search(r"^column \w+(\.)*\w+\s?\|?$", received_command):

                db_client.delay_column(received_command)

            elif re.search(r"switch \w+$", received_command):

                database_interface(database_type, received_command.split(" ")[1])

            elif received_command == "webapp":
                
                from app.webapp import app

                app.run(host="127.0.0.1", port=5000)

            else:

                sql_regex = re.compile(r"^(?i)(CREATE|SELECT|UPDATE|INSERT|DELETE)$")

                if sql_regex.match(received_command.split(" ")[0]):

                    db_client.delay_command(received_command)
                
                else:

                    print("Not a valid SQL Expression!")

        except Exception as error:

            print(error)

        if not (received_command in command_keys):

            command_buffer = received_command
        
        received_command = front_prompt(database_type, db_nickname)

    #Clear the environment variable after the webapp
    
    del os.environ["DB_NAME"]
    del os.environ["DB_TYPE"]
Beispiel #8
0
def main():

    sql_lib_definition_dict = None

    with open("config/db_definition.json", "r") as definition_obj:

        sql_lib_definition_dict = json.loads(
            definition_obj.read()
        )
        
    if len(sys.argv) >= 2 and len(sys.argv) <= 3:

        if re.search(r"^(?i)(init|del)$", sys.argv[1]):

            init_db()
        
        else:

            db_main(sql_lib_definition_dict)

        #Clear the environment variable after the webapp
        del os.environ["DB_NAME"]
        del os.environ["DB_TYPE"]
    
    elif len(sys.argv) > 3 and len(sys.argv) <= 4:

        os.environ["DB_TYPE"] = sql_lib_definition_dict[sys.argv[2]]
        os.environ["DB_NAME"] = sys.argv[3]

        if sys.argv[1] == "webapp":
        
            from app.webapp import app

            app.run(host="127.0.0.1", port=5000)
        
        elif sys.argv[1] == "falcon":

            from app.webapp_falcon import app

            waitress.serve(app, host='127.0.0.1', port=8041, url_scheme='https')
        
        del os.environ["DB_TYPE"]
        del os.environ["DB_NAME"]

    else:

        print(
        """
        Help:

            python init.py init                                 -- to create a DB metadata
            python init.py del <db_nickname>                    -- to delete a DB metadata

            e.g. python init.py del yahoo_1223

            python main.py <sql_engine>                         -- to enter the client prompt
            python main.py <sql_engine> <db_nickname>           -- to connect a DB's client prompt

            e.g.
            python main.py mysql yahoo_1223

            Webapp
            python main.py webapp <sql_engine> <db_nickname>    -- to run webapp

        """
        )
from app.ex1 import ex1_multi
from app.ex2 import ex2, ex2_reg
from app.ex3 import ex3, ex3_nn
import sys

arguments = sys.argv

modules = {
    'ex1': ex1_multi,
    'ex2': ex2,
    'ex2_reg': ex2_reg,
    'ex3': ex3,
    'ex3_nn': ex3_nn
}

optional_argument = False
for arg in arguments:
    if arg in modules:
        modules[arg].run()
        optional_argument = True

if optional_argument == False:
    # Run web application
    from app.webapp import app
    if __name__ == '__main__':
        app.run(debug=True)