예제 #1
0
def _parse_commit(commit):
    """
    Arguments:
        commit(git.Commit): commit object

    Returns:
        MinorVersion: namedtuple of minor version (date author email checksum desc parents)
    """
    checksum = str(commit)
    commit_parents = [str(parent) for parent in commit.parents]

    commit_author_info = commit.author
    if not commit_author_info:
        perun_log.error("fatal: malform commit {}".format(checksum))

    author, email = commit_author_info.name, commit_author_info.email
    timestamp = commit.committed_date
    date = timestamps.timestamp_to_str(int(timestamp))

    commit_description = str(commit.message)
    if not commit_description:
        perun_log.error("fatal: malform commit {}".format(checksum))

    return MinorVersion(date, author, email, checksum, commit_description,
                        commit_parents)
예제 #2
0
def register_in_index(base_dir, minor_version, registered_file,
                      registered_file_checksum):
    """Registers file in the index corresponding to the minor_version

    If the index for the minor_version does not exist, then it is touched and initialized
    with empty prefix. Then the entry is added to the file.

    Arguments:
        base_dir(str): base directory of the minor version
        minor_version(str): sha-1 representation of the minor version of vcs (like e.g. commit)
        registered_file(path): filename that is registered
        registered_file_checksum(str): sha-1 representation fo the registered file
    """
    # Create the directory and index (if it does not exist)
    minor_dir, minor_index_file = split_object_name(base_dir, minor_version)
    touch_dir(minor_dir)
    touch_index(minor_index_file)

    modification_stamp = timestamps.timestamp_to_str(
        os.stat(registered_file).st_mtime)
    entry_name = os.path.split(registered_file)[-1]
    entry = IndexEntry(modification_stamp, registered_file_checksum,
                       entry_name, -1)
    write_entry_to_index(minor_index_file, entry)

    reg_rel_path = os.path.relpath(registered_file)
    perun_log.info(
        "'{}' successfully registered in minor version index".format(
            reg_rel_path))
예제 #3
0
def get_untracked_profiles(pcs):
    """Returns list untracked profiles, currently residing in the .perun/jobs directory.

    Arguments:
        pcs(PCS): performance control system

    Returns:
        list: list of ProfileInfo parsed from .perun/jobs directory
    """
    profile_list = []
    # Transform each profile of the path to the ProfileInfo object
    for untracked_path in os.listdir(pcs.get_job_directory()):
        if not untracked_path.endswith('perf'):
            continue

        real_path = os.path.join(pcs.get_job_directory(), untracked_path)
        time = timestamp.timestamp_to_str(os.stat(real_path).st_mtime)

        # Update the list of profiles and counters of types
        profile_info = profile.ProfileInfo(untracked_path,
                                           real_path,
                                           time,
                                           is_raw_profile=True)
        profile_list.append(profile_info)

    return profile_list
예제 #4
0
def profile_pool_to_info(profile_pool):
    """
    Arguments:
        profile_pool(list): list of profiles

    Returns:
        generator: yield profile information as tuple (type, split name, time)
    """
    for profile in profile_pool:
        with open(profile, 'r') as profile_handle:
            profile_contents = json.load(profile_handle)
            profile_time = timestamps.timestamp_to_str(os.stat(profile).st_mtime)
            yield (profile_contents['header']['type'],
                   profile_contents['collector_info']['name'],
                   profile_time)
예제 #5
0
    def read_entry():
        """
        :returns IndexEntry: one read index entry
        """
        # Rather nasty hack, but nothing better comes to my mind currently
        if index_handle.tell() + 24 >= last_position:
            return ''

        file_offset = index_handle.tell()
        file_time = timestamps.timestamp_to_str(timestamps.read_timestamp_from_file(index_handle))
        file_sha = binascii.hexlify(index_handle.read(20)).decode('utf-8')
        file_path, byte = "", read_char_from_handle(index_handle)
        while byte != '\0':
            file_path += byte
            byte = read_char_from_handle(index_handle)
        return IndexEntry(file_time, file_sha, file_path, file_offset)
예제 #6
0
파일: git.py 프로젝트: xlisci02/perun
def _parse_commit(commit):
    """
    :param git.Commit commit: commit object
    :returns MinorVersion: namedtuple of minor version (date author email checksum desc parents)
    """
    checksum = str(commit)
    commit_parents = [str(parent) for parent in commit.parents]

    commit_author_info = commit.author

    author, email = commit_author_info.name, commit_author_info.email
    timestamp = commit.committed_date
    date = timestamps.timestamp_to_str(int(timestamp))

    commit_description = str(commit.message)

    return MinorVersion(date, author, email, checksum, commit_description,
                        commit_parents)
예제 #7
0
def successfully_added_profile_in(index_handle, valid_profile):
    """Helper assert that checks if the @p valid_profile was successfully added to index
    Arguments:
        index_handle(file): index handle of the corresponding minor version
        valid_profile(str): name of the valid profile
    """
    profile_timestamp = timestamps.timestamp_to_str(os.stat(valid_profile).st_mtime)
    profile_name = os.path.split(valid_profile)[-1]
    try:
        profile_entry \
            = store.lookup_entry_within_index(index_handle,
                                              lambda entry: entry.path == profile_name)
        assert profile_entry.path == profile_name
        assert profile_entry.time == profile_timestamp
        return True
    # This sounds weird, but I want to use this function in asserts
    except EntryNotFoundException:
        return False
    except AssertionError:
        return False