From: kosta Date: Tue, 21 Feb 2023 17:35:20 +0000 (+0100) Subject: [bos #32522][EDF] SALOME on Demand. Added unified check if an extension installed... X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4b6364fa3fb74e39113d2f868fca0e0a9be040cf;p=modules%2Fkernel.git [bos #32522][EDF] SALOME on Demand. Added unified check if an extension installed for unpacking and removing. --- diff --git a/bin/SalomeOnDemandTK/extension_remover.py b/bin/SalomeOnDemandTK/extension_remover.py index 53c12e83c..7533436c8 100644 --- a/bin/SalomeOnDemandTK/extension_remover.py +++ b/bin/SalomeOnDemandTK/extension_remover.py @@ -37,8 +37,9 @@ import shutil from traceback import format_exc from .extension_utilities import logger, \ - DFILE_EXT, CFILE_EXT, SALOME_EXTDIR, EXTCOMPONENT_KEY, \ - isvalid_dirname, list_dependants, is_empty_dir, find_salomexd, find_salomexc, find_envpy, value_from_salomexd + SALOME_EXTDIR, EXTCOMPONENT_KEY, \ + isvalid_dirname, list_dependants, is_empty_dir, \ + find_envpy, value_from_salomexd, check_if_installed def remove_if_empty(top_dir, directory): @@ -144,20 +145,9 @@ def remove_salomex(install_dir, salomex_name): return components # Check if the given extension is installed - logger.debug('Check if an extension %s is installed:', salomex_name) - - salomexd = find_salomexd(install_dir, salomex_name) - if not salomexd: - logger.debug('Cannot find a description file for extension %s! ' - 'Extension has been already removed or %s file was deleted by mistake. ' - 'In the former case we can use %s file to clean up.', - salomex_name, DFILE_EXT, CFILE_EXT) - - salomexc = find_salomexc(install_dir, salomex_name) + salomexd, salomexc = check_if_installed(install_dir, salomex_name) if not salomexc: - logger.debug('Cannot find %s for extension %s! ' - 'Going to exit from extension removing process.', - salomexc, salomex_name) + logger.debug('Going to exit from extension removing process.') return components # Check if we cannot remove an extension because of dependencies diff --git a/bin/SalomeOnDemandTK/extension_unpacker.py b/bin/SalomeOnDemandTK/extension_unpacker.py index 9d53009fc..4590c2908 100644 --- a/bin/SalomeOnDemandTK/extension_unpacker.py +++ b/bin/SalomeOnDemandTK/extension_unpacker.py @@ -39,7 +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 + isvalid_filename, isvalid_dirname, ext_info_bykey, set_selext_env, get_app_root, \ + check_if_installed def unpack_salomex(salome_root, salomex): @@ -61,9 +62,15 @@ def unpack_salomex(salome_root, salomex): not isvalid_filename(salomex, ARCFILE_EXT): return False + # Check if the given extension is already installed + salome_ext_name, _ = os.path.splitext(os.path.basename(salomex)) + _, salomexc = check_if_installed(salome_root, salome_ext_name) + if salomexc: + logger.debug('To reinstall an extension you need to remove it first!') + return False + try: with tarfile.open(salomex) as ext: - salome_ext_name, _ = os.path.splitext(os.path.basename(salomex)) # Read a list of dependencies, so let's check if they are present in salome_root logger.debug('Try to read %s.%s file...', salome_ext_name, DFILE_EXT) diff --git a/bin/SalomeOnDemandTK/extension_utilities.py b/bin/SalomeOnDemandTK/extension_utilities.py index 352c281e0..81069b2e0 100644 --- a/bin/SalomeOnDemandTK/extension_utilities.py +++ b/bin/SalomeOnDemandTK/extension_utilities.py @@ -632,3 +632,34 @@ def get_app_root(levels_up=5): logger.debug('App root: %s', app_root) return app_root + + +def check_if_installed(install_dir, salomex_name): + """ + Check if a given salome extension is installed in install_dir. + Now for install|remove process we consider an ext is installed + if we have at least salomexc file with list of files to remove + if we need to clean up. + + Args: + install_dir - path to SALOME install root directory. + salomex_name - a given ext name. + + Returns: + salomexd, salomexc file names. + """ + + logger.debug('Check if %s extension is installed in %s...', salomex_name, install_dir) + + salomexd = find_salomexd(install_dir, salomex_name) + if not salomexd: + logger.debug('Extension has been already removed or %s file was deleted by mistake. ' + 'In the former case we can use %s file to clean up.', DFILE_EXT, CFILE_EXT) + + salomexc = find_salomexc(install_dir, salomex_name) + if salomexd: + logger.debug('An extension %s IS installed.', salomex_name) + else: + logger.debug('An extension %s IS NOT installed.', salomex_name) + + return salomexd, salomexc