From 9d293e85218f928b64045bf24cd0266bbd9590d9 Mon Sep 17 00:00:00 2001 From: "John M. Horan" Date: Thu, 7 Mar 2024 12:51:26 -0800 Subject: [PATCH] Rename log file and convert location to constant #247 Reference: https://github.com/nexB/purldb/pull/305 Reference: https://github.com/nexB/purldb/issues/247 Signed-off-by: John M. Horan --- purldb-toolkit/src/purldb_toolkit/purlcli.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/purldb-toolkit/src/purldb_toolkit/purlcli.py b/purldb-toolkit/src/purldb_toolkit/purlcli.py index 6f9804f2..e1809f1d 100644 --- a/purldb-toolkit/src/purldb_toolkit/purlcli.py +++ b/purldb-toolkit/src/purldb_toolkit/purlcli.py @@ -21,6 +21,8 @@ from packageurl import PackageURL from packageurl.contrib import purl2url +LOG_FILE_LOCATION = os.path.join(os.path.expanduser("~"), "purlcli.log") + @click.group() def purlcli(): @@ -254,7 +256,7 @@ def construct_headers( print(warning) continue - log_file = Path(os.path.join(os.path.expanduser("~"), "app.log")) + log_file = Path(LOG_FILE_LOCATION) if log_file.is_file(): with open(log_file, "r") as f: for line in f: @@ -657,7 +659,7 @@ def validate_purl(purl): print(f"validate_purl(): json.decoder.JSONDecodeError for '{purl}': {e}") logging.basicConfig( - filename=os.path.join(os.path.expanduser("~"), "app.log"), + filename=LOG_FILE_LOCATION, level=logging.ERROR, format="%(levelname)s - %(message)s", filemode="w", @@ -842,7 +844,7 @@ def check_for_duplicate_input_sources(purls, file): def clear_log_file(): - log_file = Path(os.path.join(os.path.expanduser("~"), "app.log")) + log_file = Path(LOG_FILE_LOCATION) if log_file.is_file(): os.remove(log_file)