diff options
author | Matthias Baumgartner <dev@igsor.net> | 2023-04-17 18:47:58 +0200 |
---|---|---|
committer | Matthias Baumgartner <dev@igsor.net> | 2023-04-17 18:47:58 +0200 |
commit | be6027859c815e18b08a49ca1a45df3fc0aac301 (patch) | |
tree | e978249655fcab58f9ee1479c268ca8b06af7e8d /bsie/utils | |
parent | af81318ae9311fd0b0e16949cef3cfaf7996970b (diff) | |
parent | aefd0cb4fa1a949beabc51e88a5c46843043a439 (diff) | |
download | bsie-be6027859c815e18b08a49ca1a45df3fc0aac301.tar.gz bsie-be6027859c815e18b08a49ca1a45df3fc0aac301.tar.bz2 bsie-be6027859c815e18b08a49ca1a45df3fc0aac301.zip |
Merge branch 'mb/iptc' into develop
Diffstat (limited to 'bsie/utils')
-rw-r--r-- | bsie/utils/__init__.py | 1 | ||||
-rw-r--r-- | bsie/utils/filewalker.py | 31 | ||||
-rw-r--r-- | bsie/utils/namespaces.py | 2 |
3 files changed, 34 insertions, 0 deletions
diff --git a/bsie/utils/__init__.py b/bsie/utils/__init__.py index 18c8db7..4f08604 100644 --- a/bsie/utils/__init__.py +++ b/bsie/utils/__init__.py @@ -8,6 +8,7 @@ from . import bsfs from . import filematcher from . import namespaces as ns from . import node +from .filewalker import list_files from .loading import safe_load, unpack_qualified_name # exports diff --git a/bsie/utils/filewalker.py b/bsie/utils/filewalker.py new file mode 100644 index 0000000..3c36926 --- /dev/null +++ b/bsie/utils/filewalker.py @@ -0,0 +1,31 @@ + +# standard imports +import os +import typing + +# exports +__all__: typing.Sequence[str] = ( + 'list_files', + ) + + +## code ## + +def list_files( + roots: typing.Iterable[str], + recursive: bool = True, + follow_symlinks: bool = True, + ) -> typing.Iterator[str]: + """Iterate over all files in *roots*, recursively by default.""" + # index input paths + for path in roots: + if not os.path.exists(path): + continue + elif os.path.isdir(path) and recursive: + for dirpath, _, filenames in os.walk(path, topdown=True, followlinks=follow_symlinks): + for filename in filenames: + yield os.path.join(dirpath, filename) + elif os.path.isfile(path): + yield path + +## EOF ## diff --git a/bsie/utils/namespaces.py b/bsie/utils/namespaces.py index 4a66048..9357253 100644 --- a/bsie/utils/namespaces.py +++ b/bsie/utils/namespaces.py @@ -20,6 +20,7 @@ bsf = bsie.Literal.Array.Feature bsl = bsfs.Literal bsn = bsie.Node bsp = bsie.Node.Preview() +bst = bsie.Node.Tag() # export __all__: typing.Sequence[str] = ( @@ -32,6 +33,7 @@ __all__: typing.Sequence[str] = ( 'bsl', 'bsn', 'bsp', + 'bst', 'xsd', ) |