diff --git a/bunker/cli/__init__.py b/bunker/cli/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bunker/cli/io.py b/bunker/cli/io.py new file mode 100644 index 0000000..bf64c09 --- /dev/null +++ b/bunker/cli/io.py @@ -0,0 +1,17 @@ +import os +from getpass import getpass + +from ..bunker import Bunker + +def open(file_name, create): + if(not os.path.exists(file_name)): + if(not create): + raise IOError("file '{}' does not exist".format(file_name)) + else: + if(not os.path.isfile(file_name)): + raise IOError("'{}' is not a file".format(file_name)) + + return Bunker.open(file_name) + +def read_password(): + getpass() diff --git a/bunker/cli/methods.py b/bunker/cli/methods.py new file mode 100644 index 0000000..5857076 --- /dev/null +++ b/bunker/cli/methods.py @@ -0,0 +1,22 @@ +from .io import read_password +from ..backends.directory_store import DirectoryStore +from ..backends.kvs import KeyValueStore + +def add_kvs(bunker, name, password): + if(password is None): + password = read_password() + + bunker.add_component(KeyValueStore.component_type, name, password) + +def add_ds(bunker, name, password): + if(password is None): + password = read_password() + + bunker.add_component(DirectoryStore.component_type, name, password) + +def list_components(bunker, password): + if(password is None): + password = read_password() + + for row in bunker._components: + print(row["type"], ",\t", row["component"])