aboutsummaryrefslogtreecommitdiffstats
path: root/bsfs/apps/init.py
diff options
context:
space:
mode:
authorMatthias Baumgartner <dev@igsor.net>2022-12-18 14:21:11 +0100
committerMatthias Baumgartner <dev@igsor.net>2022-12-18 14:21:11 +0100
commit91437ba89d35bf482f3d9671bb99ef2fc69f5985 (patch)
treee9bfe27e5a641c040cfa8fe747a7cbb28091079c /bsfs/apps/init.py
parent87e4cd5a4581094f490f79d4f1cf91f51897660f (diff)
parente94368c75468e3e94382b12705e55d396249eaca (diff)
downloadbsfs-91437ba89d35bf482f3d9671bb99ef2fc69f5985.tar.gz
bsfs-91437ba89d35bf482f3d9671bb99ef2fc69f5985.tar.bz2
bsfs-91437ba89d35bf482f3d9671bb99ef2fc69f5985.zip
Merge branch 'develop' into main
Diffstat (limited to 'bsfs/apps/init.py')
-rw-r--r--bsfs/apps/init.py73
1 files changed, 73 insertions, 0 deletions
diff --git a/bsfs/apps/init.py b/bsfs/apps/init.py
new file mode 100644
index 0000000..3e2ef37
--- /dev/null
+++ b/bsfs/apps/init.py
@@ -0,0 +1,73 @@
+"""
+
+Part of the BlackStar filesystem (bsfs) module.
+A copy of the license is provided with the project.
+Author: Matthias Baumgartner, 2022
+"""
+# imports
+import argparse
+import json
+import sys
+import typing
+
+# bsfs imports
+from bsfs.utils import errors
+
+# exports
+__all__: typing.Sequence[str] = (
+ 'main',
+ )
+
+## code ##
+
+def init_sparql_store(user) -> typing.Any:
+ """Initialize a SparqlStore backend. Returns a configuration to load it."""
+ # nothing to do for non-persistent store
+ # return config to storage
+ return {
+ 'Graph': {
+ 'user': user,
+ 'backend': {
+ 'SparqlStore': {},
+ },
+ }
+ }
+
+
+def main(argv):
+ """Create a new bsfs storage structure."""
+ parser = argparse.ArgumentParser(description=main.__doc__, prog='init')
+ # global arguments
+ parser.add_argument('--user', type=str, default='http://example.com/me',
+ help='Default user.')
+ parser.add_argument('--output', type=str, default=None,
+ help='Write the config to a file instead of standard output.')
+ #parser.add_argument('--schema', type=str, default=None,
+ # help='Initial schema.')
+ # storage selection
+ parser.add_argument('store', choices=('sparql', ),
+ help='Which storage to initialize.')
+ # storage args
+ # parse args
+ args = parser.parse_args(argv)
+
+ # initialize selected storage
+ if args.store == 'sparql':
+ config = init_sparql_store(args.user)
+ else:
+ raise errors.UnreachableError()
+
+ # print config
+ if args.output is not None:
+ with open(args.output, mode='wt', encoding='UTF-8') as ofile:
+ json.dump(config, ofile)
+ else:
+ json.dump(config, sys.stdout)
+
+
+## main ##
+
+if __name__ == '__main__':
+ main(sys.argv[1:])
+
+## EOF ##