diff options
Diffstat (limited to 'bsie/apps')
-rw-r--r-- | bsie/apps/_loader.py | 6 | ||||
-rw-r--r-- | bsie/apps/index.py | 23 | ||||
-rw-r--r-- | bsie/apps/info.py | 2 |
3 files changed, 9 insertions, 22 deletions
diff --git a/bsie/apps/_loader.py b/bsie/apps/_loader.py index 6411f10..d9ea9bb 100644 --- a/bsie/apps/_loader.py +++ b/bsie/apps/_loader.py @@ -1,5 +1,6 @@ # standard imports +import os import typing # external imports @@ -12,8 +13,7 @@ from bsie.lib.pipeline import Pipeline from bsie.reader import ReaderBuilder # constants -DEFAULT_CONFIG_FILE = 'default_config.yaml' - +DEFAULT_CONFIG_FILE = os.path.join(os.path.dirname(__file__), 'default_config.yaml') # exports __all__: typing.Sequence[str] = ( 'DEFAULT_CONFIG_FILE', @@ -23,7 +23,7 @@ __all__: typing.Sequence[str] = ( ## code ## -def load_pipeline(path: str) -> Pipeline: +def load_pipeline(path: str = DEFAULT_CONFIG_FILE) -> Pipeline: """Load a pipeline according to a config at *path*.""" # load config file with open(path, 'rt', encoding='utf-8') as ifile: diff --git a/bsie/apps/index.py b/bsie/apps/index.py index d64e8c2..7dda6f4 100644 --- a/bsie/apps/index.py +++ b/bsie/apps/index.py @@ -6,7 +6,7 @@ import typing # bsie imports from bsie.lib import BSIE, DefaultNamingPolicy -from bsie.utils import bsfs, errors, node as node_ +from bsie.utils import bsfs, errors, node as node_, list_files # inner-module imports from . import _loader @@ -23,7 +23,7 @@ def main(argv): """Index files or directories into BSFS.""" parser = argparse.ArgumentParser(description=main.__doc__, prog='index') parser.add_argument('--config', type=str, - default=os.path.join(os.path.dirname(__file__), _loader.DEFAULT_CONFIG_FILE), + default=_loader.DEFAULT_CONFIG_FILE, help='Path to the config file.') parser.add_argument('--host', type=bsfs.URI, default=bsfs.URI('http://example.com'), help='') @@ -59,22 +59,9 @@ def main(argv): # FIXME: simplify code (below but maybe also above) # FIXME: How to handle dependencies between data? # E.g. do I still want to link to a tag despite not being permitted to set its label? - - # index input paths - for path in args.input_file: - if not os.path.exists(path): - pass # FIXME: notify the user - elif os.path.isdir(path) and args.recursive: - for dirpath, _, filenames in os.walk(path, topdown=True, followlinks=args.follow): - for filename in filenames: - for node, pred, value in bsie.from_file(os.path.join(dirpath, filename)): - handle(node, pred, value) - elif os.path.isfile(path): - for node, pred, value in bsie.from_file(path): - handle(node, pred, value) - else: - raise errors.UnreachableError() - + for path in list_files(args.input_file, args.recursive, args.follow): + for node, pred, value in bsie.from_file(path): + handle(node, pred, value) if args.print: walk(print) diff --git a/bsie/apps/info.py b/bsie/apps/info.py index e27b70b..b6494da 100644 --- a/bsie/apps/info.py +++ b/bsie/apps/info.py @@ -23,7 +23,7 @@ def main(argv): """Show information from BSIE.""" parser = argparse.ArgumentParser(description=main.__doc__, prog='info') parser.add_argument('--config', type=str, - default=os.path.join(os.path.dirname(__file__), _loader.DEFAULT_CONFIG_FILE), + default=_loader.DEFAULT_CONFIG_FILE, help='Path to the config file.') parser.add_argument('what', choices=('predicates', 'schema'), help='Select what information to show.') |