Пример #1
0
def overlay(repository, files, version, debug=False):
    """
    Overlay files from the specified repository/version into the given
    directory and return None.

    :param repository: A string containing the path to the repository to be
     extracted.
    :param files: A list of `FileConfig` objects.
    :param version: A string containing the branch/tag/sha to be exported.
    :param debug: An optional bool to toggle debug output.
    :return: None
    """
    with util.saved_cwd():
        os.chdir(repository)
        _get_version(version, debug)

        for fc in files:
            if '*' in fc.src:
                for filename in glob.glob(fc.src):
                    util.copy(filename, fc.dst)
                    msg = '  - copied ({}) {} to {}'.format(
                        version, filename, fc.dst)
                    util.print_info(msg)
            else:
                if os.path.isdir(fc.dst) and os.path.isdir(fc.src):
                    shutil.rmtree(fc.dst)
                util.copy(fc.src, fc.dst)
                msg = '  - copied ({}) {} to {}'.format(
                    version, fc.src, fc.dst)
                util.print_info(msg)
Пример #2
0
def extract(repository, destination, version, debug=False):
    """
    Extract the specified repository/version into the given directory and
    return None.

    :param repository: A string containing the path to the repository to be
     extracted.
    :param destination: A string containing the directory to clone the
     repository into.  Relative to the directory ``gilt`` is running
     in. Must end with a '/'.
    :param version: A string containing the branch/tag/sha to be exported.
    :param debug: An optional bool to toggle debug output.
    :return: None
    """
    with util.saved_cwd():
        if os.path.isdir(destination):
            shutil.rmtree(destination)

        os.chdir(repository)
        _get_version(version, debug)
        cmd = sh.git.bake(
            'checkout-index', force=True, all=True, prefix=destination)
        util.run_command(cmd, debug=debug)
        msg = '  - extracting ({}) {} to {}'.format(version, repository,
                                                    destination)
        util.print_info(msg)
Пример #3
0
def test_saved_cwd_contextmanager(temp_dir):
    workdir = os.path.join(temp_dir.strpath, 'workdir')

    os.mkdir(workdir)

    with util.saved_cwd():
        os.chdir(workdir)
        assert workdir == os.getcwd()

    assert temp_dir.strpath == os.getcwd()