diff --git a/bin/rougail b/bin/rougail new file mode 100755 index 0000000..79a0480 --- /dev/null +++ b/bin/rougail @@ -0,0 +1,8 @@ +#! /usr/bin/python3 -sP +# -*- coding: utf-8 -*- +import re +import sys +from rougail.cli.__main__ import main +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) + sys.exit(main()) diff --git a/src/rougail/cli/__init__.py b/src/rougail/cli/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/rougail/cli/__main__.py b/src/rougail/cli/__main__.py new file mode 100644 index 0000000..d83904c --- /dev/null +++ b/src/rougail/cli/__main__.py @@ -0,0 +1,56 @@ +from tiramisu_cmdline_parser import TiramisuCmdlineParser +from tiramisu import Config +from pathlib import Path + +from rougail import Rougail +from rougail.config import get_rougail_config +from rougail.utils import load_modules + + +def main(): + rougailconfig = get_rougail_config(backward_compatibility=False) + cmd_config = rougailconfig.config + cmd_config.property.read_write() + cmd_config.property.add('not_for_commandline') + parser = TiramisuCmdlineParser(cmd_config, + add_no_option_to_boolean=False, + short_name_max_len=2, + ) + parser.parse_args() + cmd_config.property.remove('not_for_commandline') + cmd_config.property.read_only() + user_data_names = rougailconfig['step.user_data'] + output_name = rougailconfig['step.output'] + # structural + rougail = Rougail(rougailconfig) + for user_data_name in user_data_names: + rougail.converted.plugins.append('user_data_' + user_data_name) + rougail.converted.plugins.append('output_' + output_name) + config = rougail.get_config() + # data user + if not user_data_names: + user_datas = None + else: + config.property.read_write() + user_datas = {'errors': [], + 'warnings': [], + } + for user_data_name in user_data_names: + path = Path(__file__).parent.parent / ('user_data_' + user_data_name) / 'cli.py' + if not path.is_file(): + raise Exception(f'cannot find cli file for "user_data" module "{user_data_name}"') + module = load_modules('rougail.user_data_' + user_data_name + '.cli', str(path)) + module.run(rougailconfig, + config, + user_datas, + ) + # output + config.property.read_only() + path = Path(__file__).parent.parent / ('output_' + output_name) / 'cli.py' + if not path.is_file(): + raise Exception(f'cannot find cli file for "output_name" module "{output_name}"') + module = load_modules('rougail.output_' + output_name + '.cli', str(path)) + module.run(rougailconfig, + config, + user_datas, + )