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
This commit is contained in:
caryoscelus 2023-07-02 03:37:46 +00:00
parent 62d1c9d27a
commit e36f7bb3a5
3 changed files with 15 additions and 0 deletions

View file

@ -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

View file

@ -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,

View file

@ -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