# Copyright (C) 2005-2025 Splunk Inc. All Rights Reserved. import os import shutil def _get_object_order(object_type): """ Return the weight of different object types. This is needed when perform copying object back to kvstore. In order to restore the service object, certain set of objects have to be restored first, the following order indicates such dependencies. @type object_type: basestring @param object_type: object_type @return: int, priority of the object type """ if object_type == 'team': return 0 elif object_type == 'entity': return 1 elif object_type == 'kpi_template': return 2 elif object_type == 'kpi_base_search': return 3 elif object_type == 'kpi_threshold_template': return 4 elif object_type == 'base_service_template': return 5 elif object_type == 'service': return 6 elif object_type == 'glass_table_images': return 99 elif object_type == 'glass_table_icons': return 100 else: return 7 def remove_file(path, logger): ''' Util function to remove files. if it throws permission denied error(OSError) we should handle at the place where we call the function :param path: path to the file including the file name itself :return: ''' if path: if os.path.exists(path): os.remove(path) else: logger.debug('Given file path {} does not exist'.format(path)) else: logger.debug('Given file path {} is Invalid'.format(path)) def remove_folder(path, logger): ''' Util function to remove folder. if it throws permission denied error(OSError) we should handle at the place where we call the function :param path: path to the folder including the folder name itself :return: ''' if path: if os.path.exists(path): shutil.rmtree(path) else: logger.debug('Given folder path {} does not exist'.format(path)) else: logger.debug('Given folder path {} is Invalid'.format(path))