diff --git a/py-packages/spiller/spiller/__init__.py b/py-packages/spiller/spiller/__init__.py index 52d028d..c48efc5 100644 --- a/py-packages/spiller/spiller/__init__.py +++ b/py-packages/spiller/spiller/__init__.py @@ -1,2 +1,2 @@ -__version__ = "0.1" +__version__ = "0.2" from spiller.spiller import retrieve, store, list_storage diff --git a/py-packages/spiller/spiller/spiller.py b/py-packages/spiller/spiller/spiller.py index 3cecd48..fdb5abb 100755 --- a/py-packages/spiller/spiller/spiller.py +++ b/py-packages/spiller/spiller/spiller.py @@ -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":