Esempio n. 1
0
def test_ErrorOutputDirNotExists(tmpdir):
    '''Test the class ErrorOutputDirNotExists (error when a directory doesn't exist)'''
    tmpdir = tmpdir.strpath
    # Test instantiation
    test_error = NCBImetaErrors.ErrorOutputDirNotExists(tmpdir)
    # Test str representation (error message)
    error_output = str(test_error)
    error_expect = ("\n\nOutput directory does not exist." + "\n" +
                    "User entered: " + tmpdir)
    assert error_output == error_expect
Esempio n. 2
0
#--- Print the retrieved config file parameters ---#
print("\n" + "NCBImeta was run with the following options: " + "\n" + "\t" +
      "Config File: " + str(config_path) + "\n" + "\t" + "Output Directory: " +
      str(CONFIG_OUTPUT_DIR) + "\n" + "\t" + "Email: " + str(CONFIG_EMAIL) +
      "\n" + "\t" + "API Key: " + "\t\t" + str(CONFIG_API_KEY) + "\n" + "\t" +
      "User Database: " + str(CONFIG_DATABASE) + "\n" + "\t" + "Tables: " +
      str(CONFIG_TABLES) + "\n" + "\t" + "Search Terms: ",
      flush=True)
for table_search_term in CONFIG_SEARCH_TERMS:
    print("\t\t" + str(table_search_term), flush=True)
print("\n", flush=True)

# Check if output dir exists
if not os.path.exists(CONFIG_OUTPUT_DIR):
    raise NCBImetaErrors.ErrorOutputDirNotExists(CONFIG_OUTPUT_DIR)

# Flat mode checking
if flat_mode:
    print(
        "Flat mode was requested, organizational directories will not be used.",
        flush=True)
    DB_DIR = os.path.join(CONFIG_OUTPUT_DIR, "")
    LOG_PATH = CONFIG_OUTPUT_DIR

# Or Create accessory directory (ex. log, data, database, etc.)
elif not flat_mode:
    print(
        "Flat mode was not requested, organization directories will be used.",
        flush=True)
    NCBImetaUtilities.check_accessory_dir(CONFIG_OUTPUT_DIR)
Esempio n. 3
0
output_dir = args['outputDir']

#-----------------------------------------------------------------------#
#                           Argument Checking                           #
#-----------------------------------------------------------------------#

# Check if database exists
if os.path.exists(db_name):
    conn = sqlite3.connect(db_name)
    print('\nOpening database: ' + db_name, flush=True)
else:
    raise NCBImetaErrors.ErrorDBNotExists(db_name)

# Check if output dir exists
if not os.path.exists(output_dir):
    raise NCBImetaErrors.ErrorOutputDirNotExists(output_dir)

# no errors were raised, safe to connect to db
cur = conn.cursor()

#-----------------------------------------------------------------------#
#                         Process Database                              #
#-----------------------------------------------------------------------#

# Get a list of tables
cur.execute("SELECT name FROM sqlite_master WHERE type='table';")
table_list = cur.fetchall()

# Iterate through each table
for table in table_list:
    # Skip sqlite_sequence default table