This script provides utility functions to set up the configuration files required by the package. It checks for the existence of essential files (encryption key, geo database, and NAICS database) and assists in setting them up by copying and renaming files to their appropriate locations. You can download the resources here.
from uscodekit.setup import (
setup_file_stats,
setup_geo_database,
setup_naics_database,
setup_encryption_key,
setup_all
)
setup_file_statsChecks the existence of configuration files and provides their status.
verbose (bool, default=True): If True, prints the status of each file.Dict: A dictionary indicating the presence of the files:
"encryption_key" (bool): True if the encryption key file exists."geo_database" (bool): True if the geo database file exists."naics_database" (bool): True if the NAICS database file exists.setup_geo_databaseSets up the Geo database by copying a .gz file to the specified directory.
file_path (str): Path to the .gz file.bool: True if the setup is successful, False otherwise.ValueError: If the provided file does not have a .gz extension.True without duplicating efforts.setup_naics_databaseSets up the NAICS database by copying a .bin file to the specified directory.
file_path (str): Path to the .bin file.bool: True if the setup is successful, False otherwise.ValueError: If the provided file does not have a .bin extension.True without duplicating efforts.setup_encryption_keySets up the encryption key by copying a .key file to the specified directory.
file_path (str): Path to the .key file.bool: True if the setup is successful, False otherwise.ValueError: If the provided file does not have a .key extension.True without duplicating efforts.setup_allPrompts the user for paths to the required files and sets them up.
Check File Status:
stats = setup_file_stats()
print(stats)
Output:
Encryption key...OK
Geo database...MISSING
NAICS database...OK
{'encryption_key': True, 'geo_database': False, 'naics_database': True}
Set Up Geo Database:
result = setup_geo_database("/path/to/geo_database.gz")
print(result) # True if successful
Set Up NAICS Database:
result = setup_naics_database("/path/to/naics_database.bin")
print(result) # True if successful
Set Up Encryption Key:
result = setup_encryption_key("/path/to/encryption_key.key")
print(result) # True if successful
Set Up All Files:
setup_all()
This will prompt for file paths and set up all files interactively.