Пример #1
0
def init_db_handle():
    """Initializes database module and replaces the existing one"""

    global _Database

    try:
        # Closing existing connection if exists
        if not _Database.is_closed():
            # Unregister close() method from atexit handler
            atexit.unregister(_Database.close)

            # Close the connection
            _Database.close()

    except:  # noqa
        pass

    # Removing existing db at init location if exists
    init_obj = get_init_data()
    db_location = init_obj["DB"].get("location")
    if os.path.exists(db_location):
        os.remove(db_location)

    # Initialize new database object
    _Database = Database()
Пример #2
0
def read_local_file(filename):
    file_path = os.path.join(".local", filename)

    # Checking if file exists
    abs_file_path = os.path.join(
        os.path.dirname(inspect.getfile(sys._getframe(1))), file_path)

    # If not exists read from home directory
    if not file_exists(abs_file_path):
        init_obj = get_init_data()
        file_path = os.path.join(init_obj["LOCAL_DIR"].get("location"),
                                 filename)
        return read_file(file_path, 0).rstrip()  # To remove \n, use rstrip

    return read_file(file_path, depth=2)
Пример #3
0
 def instantiate_db():
     init_obj = get_init_data()
     db_location = init_obj["DB"].get("location")
     dsl_database.init(db_location)
     return dsl_database