From 5c0205481ca1d41720f12d8c231024c57d904aa6 Mon Sep 17 00:00:00 2001 From: kosta Date: Fri, 10 Feb 2023 15:08:53 +0100 Subject: [PATCH] [bos #32522][EDF] SALOME on Demand. Added method that returns ext_name: can_be_removed dictionary. --- bin/SalomeOnDemandTK/extension_query.py | 41 +++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/bin/SalomeOnDemandTK/extension_query.py b/bin/SalomeOnDemandTK/extension_query.py index 957da65fc..524fa1f73 100644 --- a/bin/SalomeOnDemandTK/extension_query.py +++ b/bin/SalomeOnDemandTK/extension_query.py @@ -403,6 +403,46 @@ def ext_by_name(directory): return res_names +def ext_canremove_flags(directory): + r""" + Calcualate a dict of extensions names paired with bool flag if able to be removed. + + Args: + directory - the given ext install directory. + + Returns: + For dependency tree for extensions A, B, C, D and E: + A + /|\ + / B D + \/ \/ + C E + + represented { 'A': ['B', 'C', 'D'], 'B': ['C', 'E'], 'C': [], 'D': ['E'], 'E': [] } + returns ['A': True, 'B': False, 'D': False, 'C': False, 'E': False]. + We can remove only A here, because we don't have any other modules depend on it. + """ + + logger.debug('directory: %s', directory) + + dep_tree = dependency_tree(directory) + + res_dict = {} + for ext in dep_tree: + can_remove = True + for dep in dep_tree.values(): + if ext in dep: + # At least one ext depends on it, so can't remove + can_remove = False + break + + res_dict[ext] = can_remove + + logger.debug('res_dict: %s', res_dict) + + return res_dict + + if __name__ == '__main__': if len(sys.argv) == 2: dir_size_str(sys.argv[1]) @@ -411,6 +451,7 @@ if __name__ == '__main__': logger.info('ext_list: %s', ext_list) ext_by_name(sys.argv[1]) ext_info_dict(sys.argv[1]) + ext_canremove_flags(sys.argv[1]) elif len(sys.argv) == 3: arg_1, arg_2 = sys.argv[1:] # pylint: disable=unbalanced-tuple-unpacking ext_size_str(arg_1, arg_2) -- 2.39.2