From e36f7bb3a5ad74024c0bc539429e59acc88977c8 Mon Sep 17 00:00:00 2001 From: caryoscelus Date: Sun, 2 Jul 2023 03:37:46 +0000 Subject: [PATCH] siteSign accepts absolute paths as well as paths relative to working directory - also store working_dir in config so it's possible to use from other actions as well fixes #209 --- CHANGELOG.md | 1 + src/main.py | 13 +++++++++++++ zeronet.py | 1 + 3 files changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce2cb131..86a9aa72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ maintainers: @caryoscelus - sec update of msgpck dependency (@chncaption) - deprecate python-3.6 as it apparently is no longer used (by active users) - improvement in imports and naming (@caryoscelus) +- siteSign accepts absolute paths as well as paths relative to working directory (@caryoscelus) ### zeronet-conservancy 0.7.8.1 (2022-11-28) (0054eca9df0c9c8c2f4a78) maintainers: @caryoscelus diff --git a/src/main.py b/src/main.py index a5e15070..b4b656db 100644 --- a/src/main.py +++ b/src/main.py @@ -234,6 +234,19 @@ class Actions(object): # Not found in users.json, ask from console import getpass privatekey = getpass.getpass("Private key (input hidden):") + # inner_path can be either relative to site directory or absolute/relative path + if os.path.isabs(inner_path): + full_path = os.path.abspath(inner_path) + else: + full_path = os.path.abspath(config.working_dir + '/' + inner_path) + print(full_path) + if os.path.isfile(full_path): + if address in full_path: + # assuming site address is unique, keep only path after it + inner_path = full_path.split(address+'/')[1] + else: + # oops, file that we found seems to be rogue, so reverting to old behaviour + logging.warning(f'using {inner_path} relative to site directory') try: succ = site.content_manager.sign( inner_path=inner_path, privatekey=privatekey, diff --git a/zeronet.py b/zeronet.py index 6f0e63b9..bb53404f 100755 --- a/zeronet.py +++ b/zeronet.py @@ -123,6 +123,7 @@ def restart(): def start(): + config.working_dir = os.getcwd() app_dir = os.path.dirname(os.path.abspath(__file__)) os.chdir(app_dir) # Change working dir to zeronet.py dir sys.path.insert(0, os.path.join(app_dir, "src/lib")) # External liblary directory