default config

This commit is contained in:
Q
2023-01-22 17:02:25 +02:00
parent cd37185d2a
commit ebf8e00c86
2 changed files with 23 additions and 6 deletions

View File

@@ -9,9 +9,18 @@ import random
import stat
import string
JSON = os.getenv(
"SPILLER_STORAGE", os.path.expanduser("~/.config/spiller/storage.json")
)
def get_config():
default_config = {
'SPILLER_STORAGE': os.path.expanduser("~/.config/spiller/storage.json")
}
try:
with open(os.path.expanduser("~/.config/spiller/config.json"), 'rt') as fp:
default_config.update(json.load(fp))
except Exception:
pass
return default_config
def get_opts():
@@ -19,8 +28,11 @@ def get_opts():
parser = argparse.ArgumentParser(
prog="spill",
description="""Key/value storage that uses JSON and GPG as backend.
Values are encrypted symmetrically with the key provided, or a random string is generated. Storage file can be changed with
SPILLER_STORAGE env variable. Encryption key can be passed from a variable SPILLER_KEY instead of a switch.""",
Values are encrypted symmetrically with the key provided, or a random string is generated.
Encryption key can be passed from a variable SPILLER_KEY instead of a switch.
Storage file can be changed with SPILLER_STORAGE env variable, in a
"SPILLER_STORAGE": key in a JSON file read at ~/.config/spill/config.json
""",
)
subparsers = parser.add_subparsers(dest="command", help="Command")
set_parser = subparsers.add_parser("set")
@@ -204,6 +216,11 @@ def get_random_key():
)
CONFIG = get_config()
JSON = os.getenv(
"SPILLER_STORAGE", CONFIG['SPILLER_STORAGE']
)
def main():
opts = get_opts()
if opts.command == "set":