Commit 8c12165e authored by Lucas Bourneuf's avatar Lucas Bourneuf

documentation and clearer code for building scripts from files/dirs

parent c6f25672
......@@ -49,16 +49,23 @@ Script = namedtuple('Script', 'name, tags, description, module, run_on, options,
def gen_scripts_in_dir(dirname:str, extensions:[str]=('py', 'lp', 'json'),
def gen_files_in_dir(dirname:str, extensions:[str]=('py', 'lp', 'json'),
filter_prefixes:[str]='_') -> (str, str):
"Yield candidate scripts in given dir, based on file extension"
yield from (
for fname in map(os.path.basename, glob.glob('{}/*.{{{}}}'.format(dirname, ','.join(extensions))))
if not fname.startswith(filter_prefixes)
if not filter_prefixes or (filer_prefixes and not fname.startswith(filter_prefixes))
def build_scripts_from_dir(dirname:str='scripts', options:dict={}) -> [Script]:
"Yield all scripts found in given directory (not recursive)"
for file in gen_files_in_dir(dirname):
yield from build_scripts_from_file(file, options)
def build_scripts_from_file(fname:str, options:dict={}) -> [Script]:
"Yield all scripts found in given file (note that only JSON files can define multiple scripts)"
name, ext = os.path.splitext(fname)
if ext == '.json':
yield from build_scripts_from_json_file(fname)
......@@ -83,11 +90,6 @@ def build_scripts_from_file(fname:str, options:dict={}) -> [Script]:
print(f"WARNING file '{fname}' was not recognized")
def build_scripts_from_dir(base_dir:str='scripts') -> iter:
scripts = gen_scripts_in_dir(base_dir)
yield from map(build_scripts_from_file, scripts)
def merge_scripts_lists(*scripts_lists:iter) -> iter:
"""Yield scripts, ordered according to their dependancies"""
yield from sort_scripts_per_dependancies(itertools.chain.from_iterable(scripts_lists))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment