def load_profile_from_args(profile_name, minor_version): """ :param Profile profile_name: profile that will be stored for the minor version :param str minor_version: SHA-1 representation of the minor version :returns dict: loaded profile represented as dictionary """ # If the profile is in raw form if not store.is_sha1(profile_name): _, minor_index_file = store.split_object_name( pcs.get_object_directory(), minor_version) # If there is nothing at all in the index, since it is not even created ;) # we returning nothing otherwise we lookup entries in index if not os.path.exists(minor_index_file): return None with open(minor_index_file, 'rb') as minor_handle: lookup_pred = lambda entry: entry.path == profile_name profiles = store.lookup_all_entries_within_index( minor_handle, lookup_pred) else: profiles = [profile_name] # If there are more profiles we should chose if not profiles: return None chosen_profile = profiles[0] # Peek the type if the profile is correct and load the json _, profile_name = store.split_object_name(pcs.get_object_directory(), chosen_profile.checksum) profile_type = store.peek_profile_type(profile_name) if profile_type == PROFILE_MALFORMED: perun_log.error("malformed profile {}".format(profile_name)) loaded_profile = profile.load_profile_from_file(profile_name, False) return loaded_profile
def open_index(pcs_path, minor_version): """Helper function for opening handle of the index This encapsulates obtaining the full path to the given index Arguments: pcs_path(str): path to the pcs minor_version(str): sha minor version representation """ assert store.is_sha1(minor_version) object_dir_path = os.path.join(pcs_path, 'objects') _, minor_version_index = store.split_object_name(object_dir_path, minor_version) return open(minor_version_index, 'rb+')
def load_list_for_minor_version(minor_version): """Returns profiles assigned to the given minor version. :param str minor_version: identification of the commit (preferably sha1) :returns list: list of ProfileInfo parsed from index of the given minor_version """ # Compute the profiles = store.get_profile_list_for_minor(pcs.get_object_directory(), minor_version) profile_info_list = [] for index_entry in profiles: _, profile_name = store.split_object_name(pcs.get_object_directory(), index_entry.checksum) profile_info \ = ProfileInfo(index_entry.path, profile_name, index_entry.time) profile_info_list.append(profile_info) return profile_info_list
def get_minor_version_profiles(pcs, minor_version): """Returns profiles assigned to the given minor version. Arguments: pcs(PCS): performance control system minor_version(str): identification of the commit (preferably sha1) Returns: list: list of ProfileInfo parsed from index of the given minor_version """ # Compute the profiles = store.get_profile_list_for_minor(pcs.get_object_directory(), minor_version) profile_info_list = [] for index_entry in profiles: _, profile_name = store.split_object_name(pcs.get_object_directory(), index_entry.checksum) profile_info \ = profile.ProfileInfo(index_entry.path, profile_name, index_entry.time) profile_info_list.append(profile_info) return profile_info_list