From d60943de8222984bce011810d893e03cdf83f311 Mon Sep 17 00:00:00 2001 From: Ouziel Slama Date: Mon, 16 Dec 2024 17:20:56 +0000 Subject: [PATCH] Add --cache-dir flag --- counterparty-core/counterpartycore/cli.py | 1 + counterparty-core/counterpartycore/server.py | 13 +++++++------ counterparty-core/counterpartycore/test/conftest.py | 1 + release-notes/release-notes-v10.9.0.md | 2 ++ 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/counterparty-core/counterpartycore/cli.py b/counterparty-core/counterpartycore/cli.py index b6e90fd82c..156a45c7da 100755 --- a/counterparty-core/counterpartycore/cli.py +++ b/counterparty-core/counterpartycore/cli.py @@ -240,6 +240,7 @@ def float_range_checker(arg): {"action": "store_true", "default": False, "help": "don't ask for confirmation"}, ], [("--data-dir",), {"default": None, "help": "the path to the data directory"}], + [("--cache-dir",), {"default": None, "help": "the path to the cache directory"}], [ ("--log-file",), {"nargs": "?", "const": None, "default": False, "help": "log to the specified file"}, diff --git a/counterparty-core/counterpartycore/server.py b/counterparty-core/counterpartycore/server.py index 284b20d840..371211b855 100755 --- a/counterparty-core/counterpartycore/server.py +++ b/counterparty-core/counterpartycore/server.py @@ -136,6 +136,7 @@ def initialise_log_config( def initialise_config( data_dir=None, + cache_dir=None, testnet=False, testcoin=False, regtest=False, @@ -193,9 +194,11 @@ def initialise_config( os.makedirs(data_dir, mode=0o755) config.DATA_DIR = data_dir - config.CACHE_DIR = appdirs.user_cache_dir(appauthor=config.XCP_NAME, appname=config.APP_NAME) - if not os.path.isdir(config.CACHE_DIR): + if not cache_dir: + cache_dir = appdirs.user_cache_dir(appauthor=config.XCP_NAME, appname=config.APP_NAME) + if not os.path.isdir(cache_dir): os.makedirs(config.CACHE_DIR, mode=0o755) + config.CACHE_DIR = cache_dir # testnet if testnet: @@ -245,10 +248,7 @@ def initialise_config( config.DATABASE = os.path.join(data_dir, filename) config.FETCHER_DB_OLD = os.path.join(os.path.dirname(config.DATABASE), f"fetcherdb{network}") - config.FETCHER_DB = os.path.join( - appdirs.user_cache_dir(appauthor=config.XCP_NAME, appname=config.APP_NAME), - f"fetcherdb{network}", - ) + config.FETCHER_DB = os.path.join(config.CACHE_DIR, f"fetcherdb{network}") config.STATE_DATABASE = os.path.join(os.path.dirname(config.DATABASE), f"state{network}.db") @@ -627,6 +627,7 @@ def initialise_log_and_config(args, api=False): # Configuration init_args = { "data_dir": args.data_dir, + "cache_dir": args.cache_dir, "testnet": args.testnet, "testcoin": args.testcoin, "regtest": args.regtest, diff --git a/counterparty-core/counterpartycore/test/conftest.py b/counterparty-core/counterpartycore/test/conftest.py index 2e402cb37b..4b3e70dc99 100644 --- a/counterparty-core/counterpartycore/test/conftest.py +++ b/counterparty-core/counterpartycore/test/conftest.py @@ -323,6 +323,7 @@ def api_server_v2(request, cp_server): "max_log_file_rotations": 20, "log_exclude_filters": None, "log_include_filters": None, + "cache_dir": None, } server_config = ( default_config diff --git a/release-notes/release-notes-v10.9.0.md b/release-notes/release-notes-v10.9.0.md index 5bac7bbac1..9a222dedaf 100644 --- a/release-notes/release-notes-v10.9.0.md +++ b/release-notes/release-notes-v10.9.0.md @@ -24,6 +24,8 @@ ## CLI +- Add `--cache-dir` flag + # Credits - Ouziel Slama