From 5a604967104b10eee7954817b30fabb55bda2cfb Mon Sep 17 00:00:00 2001 From: DUC ANH HOANG Date: Mon, 24 Apr 2023 10:16:21 +0200 Subject: [PATCH] taking into account salome-gui interactive feature for each component --- bin/SalomeOnDemandTK/extension_builder.py | 54 +++++++++++++++++-- bin/SalomeOnDemandTK/extension_remover.py | 11 +++- bin/SalomeOnDemandTK/extension_unpacker.py | 8 ++- bin/SalomeOnDemandTK/extension_utilities.py | 60 +++++++++++++++++++++ 4 files changed, 122 insertions(+), 11 deletions(-) diff --git a/bin/SalomeOnDemandTK/extension_builder.py b/bin/SalomeOnDemandTK/extension_builder.py index cb62a87f8..6f271a474 100644 --- a/bin/SalomeOnDemandTK/extension_builder.py +++ b/bin/SalomeOnDemandTK/extension_builder.py @@ -38,9 +38,9 @@ import io from traceback import format_exc from .extension_utilities import logger, \ - BFILE_EXT, DFILE_EXT, PYFILE_EXT, EXTNAME_KEY, ARCFILE_EXT, SALOME_EXTDIR, CFILE_EXT, \ + BFILE_EXT, DFILE_EXT, PYFILE_EXT, EXTNAME_KEY, ARCFILE_EXT, SALOME_EXTDIR, CFILE_EXT, EXTCOMPONENT_KEY, ITERACTIVE_EXTCOMPONENT_KEY, \ isvalid_filename, isvalid_dirname, read_salomexd, read_salomexb, list_files_filter, \ - list_tonewline_str + list_tonewline_str, comp_interaction_treat, value_from_salomexd, override_salomexd def add_files(ext, files_abs, files_rel): @@ -75,7 +75,7 @@ def add_files(ext, files_abs, files_rel): logger.handlers[0].terminator = default_terminator -def create_salomex(salomexb, salomexd, env_py, top_repository): +def create_salomex(salomexb, salomexd, env_py, top_repository, auto = True): """ Makes salome extension archive from provided in salomexb file directories. @@ -112,6 +112,49 @@ def create_salomex(salomexb, salomexd, env_py, top_repository): logger.debug('Set an extension name as: %s', salome_ext_name) + # Check components information + components = value_from_salomexd(salomexd, EXTCOMPONENT_KEY) + if components: + components_treated = comp_interaction_treat(components) + else: + logger.error('Cannot read components information') + return + comps_list = list(components_treated.keys()) + logger.info('Components list: %s', comps_list) + logger.info('Salome GUI components: %s',[k for k, v in components_treated.items() if v == True]) + + # Override the interactive components list + if not auto: + user_input = input('Do you want to override the components info (yes/y/no/n): ') + else: + user_input = 'n' + if user_input == 'yes' or user_input == 'y' : + interactive_comps_input = input('Give the interactive list. The syntax is MODULE_1,MODULE_2, etc: ') + interactive_comps_list = list(set(interactive_comps_input.split(','))) + for comp in interactive_comps_list: + if comp not in comps_list: + _input = input('The component %s was not defined in salomexd file. Do you want to continue (yes/y/no/n): '%comp) + if _input == 'yes' or _input == 'y': + pass + elif _input == 'no' or _input == 'n': + return + else: + logger.error('Unknown request. The correct request are yes/y/no/n') + return + else: + comps_list.remove(comp) + if len(comps_list) == 0: + comp_value = interactive_comps_list + else: + comp_value = {ITERACTIVE_EXTCOMPONENT_KEY : interactive_comps_list, 'other' : comps_list} + # Override components item of salomexd file + override_salomexd(salomexd, {EXTCOMPONENT_KEY:comp_value}) + elif user_input == 'no' or user_input == 'n' : + pass + else: + logger.error('Unknown request. The correct request are yes/y/no/n') + return + try: with tarfile.open(salome_ext_name + '.' + ARCFILE_EXT, "w:gz") as ext: # Write all included files to the extension's dir @@ -160,7 +203,10 @@ def create_salomex(salomexb, salomexd, env_py, top_repository): if __name__ == '__main__': if len(sys.argv) == 5: arg_1, arg_2, arg_3, arg_4 = sys.argv[1:5] - create_salomex(arg_1, arg_2, arg_3, arg_4) + create_salomex(arg_1, arg_2, arg_3, arg_4, True) + elif len(sys.argv) == 6: + arg_1, arg_2, arg_3, arg_4, arg_5 = sys.argv[1:5] + create_salomex(arg_1, arg_2, arg_3, arg_4, arg_5) else: logger.error('You must provide all the arguments!') logger.info(create_salomex.__doc__) diff --git a/bin/SalomeOnDemandTK/extension_remover.py b/bin/SalomeOnDemandTK/extension_remover.py index 7533436c8..ae13ba2e3 100644 --- a/bin/SalomeOnDemandTK/extension_remover.py +++ b/bin/SalomeOnDemandTK/extension_remover.py @@ -175,12 +175,19 @@ def remove_salomex(install_dir, salomex_name): # Remove description file if salomexd: # Get components to deactivate in UI if the case - components = value_from_salomexd(salomexd, EXTCOMPONENT_KEY) + comp_values = value_from_salomexd(salomexd, EXTCOMPONENT_KEY) + if type(comp_values) == dict: + components = [] + for grp in comp_values: + for component in comp_values[grp]: + if component not in components: + components.append(component) + else: + components = comp_values os.remove(salomexd) logger.debug('An extension %s was removed from %s', salomex_name, install_dir) - return components if components else [] diff --git a/bin/SalomeOnDemandTK/extension_unpacker.py b/bin/SalomeOnDemandTK/extension_unpacker.py index 0f7f1d1a2..2091bd6bb 100644 --- a/bin/SalomeOnDemandTK/extension_unpacker.py +++ b/bin/SalomeOnDemandTK/extension_unpacker.py @@ -39,8 +39,8 @@ from traceback import format_exc from .extension_utilities import logger, \ DFILE_EXT, ARCFILE_EXT, EXTDEPENDSON_KEY, EXTCOMPONENT_KEY, \ - isvalid_filename, isvalid_dirname, ext_info_bykey, set_selext_env, get_app_root, \ - check_if_installed + isvalid_filename, isvalid_dirname, ext_info_bykey, set_selext_env, \ + get_app_root, check_if_installed, comp_interaction_treat def unpack_salomex(salome_root, salomex): """ @@ -138,9 +138,7 @@ def install_salomex(salomex): # Get components to activate later components = ext_info_bykey(app_root, ext_name, EXTCOMPONENT_KEY) - - return components if components else [] - + return comp_interaction_treat(components) if components else {} if __name__ == '__main__': if len(sys.argv) == 3: diff --git a/bin/SalomeOnDemandTK/extension_utilities.py b/bin/SalomeOnDemandTK/extension_utilities.py index 9031b1a3b..dba088d98 100644 --- a/bin/SalomeOnDemandTK/extension_utilities.py +++ b/bin/SalomeOnDemandTK/extension_utilities.py @@ -67,6 +67,8 @@ EXTDESCR_KEY = 'descr' EXTDEPENDSON_KEY = 'depends_on' EXTAUTHOR_KEY = 'author' EXTCOMPONENT_KEY = 'components' +DKEY_LIST = [ EXTNAME_KEY, EXTDESCR_KEY, EXTDEPENDSON_KEY, EXTAUTHOR_KEY, EXTCOMPONENT_KEY ] +ITERACTIVE_EXTCOMPONENT_KEY = 'salome_interactive' def create_salomexd(name, descr='', depends_on=None, author='', components=None): @@ -135,6 +137,36 @@ def read_salomexd(file_path): return {} +def override_salomexd(file_path, item): + """ + Override a salomexd file + + Args: + file_path - the file_path of salomexd file + item - A dictionary containing all item modified + Key of these item must be declared in DKEY_LIST + + Returns: + None + """ + file_dir = os.path.dirname(file_path) + if file_dir: + os.chdir(file_dir) + data = read_salomexd(file_path) + for key in item: + if key not in DKEY_LIST: + logger.warning('Key %s was not declared in DKEY_LIST'%key) + else: + data[key] = item[key] + create_salomexd( + data[EXTNAME_KEY], + descr = data[EXTNAME_KEY], + depends_on = data[EXTDEPENDSON_KEY], + author = data[EXTAUTHOR_KEY], + components = data[EXTCOMPONENT_KEY] + ) + + def value_from_salomexd(file_path, key): """ Reads a content of a salomexd file and return a value for the given key. @@ -667,3 +699,31 @@ def check_if_installed(install_dir, salomex_name): logger.debug('An extension %s IS NOT installed.', salomex_name) return salomexd, salomexc + + +def comp_interaction_treat(components): + """ + Convert a dict of modules groups into dict containing modules names as key and its interactive_mode as value + All the modules belong group salome_interactive has interactive_mode == True, so it has salome gui. + + Args: + A dict {string: string list} containing group name and modules lists associated + + Returns: + A dict {string, bool} containing modules name and interative mode associated + """ + interactive = False + dict_treated = {} + if type(components) == dict: + for group in components: + if group != ITERACTIVE_EXTCOMPONENT_KEY: + interactive = False + else: + interactive = True + for component in components[group]: + dict_treated[component] = interactive + elif type(components) == list: + interactive = True + for component in components: + dict_treated[component] = interactive + return dict_treated -- 2.39.2