Exemplo n.º 1
0
def config_reset(store_type, config_template):
    """Resets the given store_type to a default type (or to a selected configuration template)

    For more information about configuration templates see :ref:`config-templates`.

    :param str store_type: name of the store (local or global) which we are resetting
    :param str config_template: name of the template that we are resetting to
    :raises NotPerunRepositoryException: raised when we are outside of any perun scope
    """
    if store_type in ('shared', 'global'):
        shared_location = perun_config.lookup_shared_config_dir()
        perun_config.init_shared_config_at(shared_location)
    else:
        vcs_config = {
            'vcs': {
                'url': pcs.get_vcs_path(),
                'type': pcs.get_vcs_type()
            }
        }
        perun_config.init_local_config_at(pcs.get_path(), vcs_config,
                                          config_template)
    perun_log.info("{} configuration reset{}".format(
        'global' if store_type in ('shared', 'global') else 'local',
        " to {}".format(config_template) if store not in ("shared",
                                                          "global") else ""))
Exemplo n.º 2
0
def checkout(minor_version):
    """Checks out the new working directory corresponding to the given minor version.

    According to the supplied minor version, this command should remake the working directory
    so it corresponds to the state defined by the minor version.

    :param str minor_version: minor version that will be checked out
    """
    vcs_type, vcs_path = pcs.get_vcs_type(), pcs.get_vcs_path()
    massaged_minor_version = massage_parameter(minor_version)
    dynamic_module_function_call('perun.vcs', vcs_type, '_checkout', vcs_path,
                                 massaged_minor_version)
Exemplo n.º 3
0
def walk_major_versions():
    """Generator of major versions for the current wrapped repository.

    This function is currently unused, but will be needed in the future.

    :returns: iterable stream of major version representation
    """
    vcs_type, vcs_path = pcs.get_vcs_type(), pcs.get_vcs_path()
    perun_log.msg_to_stdout(
        "Walking major versions of type {}".format(vcs_type), 1)
    return dynamic_module_function_call('perun.vcs', vcs_type,
                                        '_walk_major_versions', vcs_path)
Exemplo n.º 4
0
def save_state():
    """Saves the state of the repository in case it is dirty.

    When saving the state of the repository one should store all of the uncommited changes to
    the working directory and index. Any issues while this process happens should be handled by
    user itself, hence no workarounds and mending should take place in this function.

    :return:
    """
    # Todo: Check the vcs.fail_when_dirty and log error in the case
    vcs_type, vcs_path = pcs.get_vcs_type(), pcs.get_vcs_path()
    return dynamic_module_function_call('perun.vcs', vcs_type, '_save_state',
                                        vcs_path)
Exemplo n.º 5
0
def restore_state(saved, state):
    """Restores the previous state of the the repository

    When restoring the state of the repository one should pop the stored changes from the stash
    and reapply them on the current directory. This make sure, that after the performance testing,
    the project is in the previous state and developer can continue with his work.

    :param bool saved: whether the stashed was something
    :param str state: the previous state of the repository
    """
    vcs_type, vcs_path = pcs.get_vcs_type(), pcs.get_vcs_path()
    dynamic_module_function_call('perun.vcs', vcs_type, '_restore_state',
                                 vcs_path, saved, state)
Exemplo n.º 6
0
def get_head_major_version():
    """Returns the string representation of current major version of the
    wrapped repository.

    Major version is displayed during the ``perun status`` output, which shows
    the current working major version of the project.

    :returns: string representation of the major version
    """
    vcs_type, vcs_path = pcs.get_vcs_type(), pcs.get_vcs_path()
    perun_log.msg_to_stdout(
        "Getting head major version of type {}".format(vcs_type), 1)
    return dynamic_module_function_call('perun.vcs', vcs_type,
                                        '_get_head_major_version', vcs_path)
Exemplo n.º 7
0
def is_dirty():
    """Tests whether the wrapped repository is dirty.

    By dirty repository we mean a repository that has either a submitted changes to its index (i.e.
    we are in the middle of commit) or any unsubmitted changes to tracked files in the current
    working directory.

    Note that this is crucial for performance testing, as any uncommited changes may skew
    the profiled data and hence the resulting profiles would not correctly represent the performance
    of minor versions.

    :return: whether the given repository is dirty or not
    """
    vcs_type, vcs_path = pcs.get_vcs_type(), pcs.get_vcs_path()
    return dynamic_module_function_call('perun.vcs', vcs_type, '_is_dirty',
                                        vcs_path)
Exemplo n.º 8
0
def check_minor_version_validity(minor_version):
    """Checks whether the given minor version specification corresponds to the
    wrapped version control system, and is not in wrong format.

    Minor version validity is mostly checked during the lookup of the minor
    versions from the command line interface.

    :param str minor_version: the specification of minor version (in form of
        sha e.g.) for which we are checking the validity
    :raises VersionControlSystemException: when the given minor version is
        invalid in the context of the wrapped version control system.
    """
    vcs_type, vcs_path = pcs.get_vcs_type(), pcs.get_vcs_path()
    dynamic_module_function_call('perun.vcs', vcs_type,
                                 '_check_minor_version_validity', vcs_path,
                                 minor_version)
Exemplo n.º 9
0
def init(vcs_init_params):
    """Calls the implementation of initialization of wrapped underlying version
    control system.

    The initialization should take care of both reinitialization of existing
    version control system instances and newly created instances. Init is
    called during the ``perun init`` command from command line interface.

    :param dict vcs_init_params: dictionary of keyword arguments passed to
        initialization method of the underlying vcs module
    :return: true if the underlying vcs was successfully initialized
    """
    vcs_type, vcs_path = pcs.get_vcs_type(), pcs.get_vcs_path()
    perun_log.msg_to_stdout(
        "Initializing {} version control params {} and {}".format(
            vcs_type, vcs_path, vcs_init_params), 1)
    return dynamic_module_function_call('perun.vcs', vcs_type, '_init',
                                        vcs_path, vcs_init_params)
Exemplo n.º 10
0
def massage_parameter(parameter, parameter_type=None):
    """Conversion function for massaging (or unifying different representations
    of objects) the parameters for version control systems.

    Massaging is mainly executed during from the command line interface, when
    one can e.g. use the references (like ``HEAD``) to specify concrete minor
    versions. Massing then unifies e.g. the references or proper hash
    representations, to just one representation for internal processing.

    :param str parameter: vcs parameter (e.g. revision, minor or major version)
        which will be massaged, i.e. transformed to unified representation
    :param str parameter_type: more detailed type of the parameter
    :returns: string representation of parameter
    """
    vcs_type, vcs_path = pcs.get_vcs_type(), pcs.get_vcs_path()
    return dynamic_module_function_call('perun.vcs', vcs_type,
                                        '_massage_parameter', vcs_path,
                                        parameter, parameter_type)
Exemplo n.º 11
0
def walk_minor_versions(head_minor_version):
    """Generator of minor versions for the given major version, which yields
    the ``MinorVersion`` named tuples containing the following information:
    ``date``, ``author``, ``email``, ``checksum`` (i.e. the hash representation
    of the minor version), ``commit_description`` and ``commit_parents`` (i.e.
    other minor versions).

    Minor versions are walked through this function during the ``perun log``
    command.

    :param str head_minor_version: the root minor versions which is the root
        of the walk.
    :returns: iterable stream of minor version representation
    """
    vcs_type, vcs_path = pcs.get_vcs_type(), pcs.get_vcs_path()
    perun_log.msg_to_stdout(
        "Walking minor versions of type {}".format(vcs_type), 1)
    return dynamic_module_function_call('perun.vcs', vcs_type,
                                        '_walk_minor_versions', vcs_path,
                                        head_minor_version)
Exemplo n.º 12
0
def get_minor_head():
    """Returns the string representation of head of current major version, i.e.
    for git this returns the massaged HEAD reference.

    This function is called mainly during the outputs of ``perun log`` and
    ``perun status`` but also during the automatic generation of profiles
    (either by ``perun run`` or ``perun collect``), where the retrieved
    identification is used as :preg:`origin`.

    :returns: unique string representation of current head (usually in SHA)
    :raises ValueError: if the head cannot be retrieved from the current
        context
    """
    try:
        return dynamic_module_function_call('perun.vcs', pcs.get_vcs_type(),
                                            '_get_minor_head',
                                            pcs.get_vcs_path())
    except ValueError as value_error:
        perun_log.error(
            "could not obtain head minor version: {}".format(value_error))
Exemplo n.º 13
0
def get_minor_version_info(minor_version):
    """Yields the specification of concrete minor version in form of
    the ``MinorVersion`` named tuples containing the following information:
    ``date``, ``author``, ``email``, ``checksum`` (i.e. the hash representation
    of the minor version), ``commit_description`` and ``commit_parents`` (i.e.
    other minor versions).

    This function is a non-generator alternative of
    :func:`perun.vcs.walk_minor_versions` and is used during the ``perun
    status`` output to display the specifics of minor version.

    :param str minor_version: the specification of minor version (in form of
        sha e.g.) for which we are retrieving the details
    :returns: minor version named tuple
    """
    vcs_type, vcs_path = pcs.get_vcs_type(), pcs.get_vcs_path()
    perun_log.msg_to_stdout(
        "Getting minor version info of type {} and args {}, {}".format(
            vcs_type, vcs_path, minor_version), 1)
    return dynamic_module_function_call('perun.vcs', vcs_type,
                                        '_get_minor_version_info', vcs_path,
                                        minor_version)