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):
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
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):
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)
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