Пример #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 test_copy_dir(temp_dir):
    src_dir = os.path.join(temp_dir.strpath, 'src')
    dst_dir = os.path.join(temp_dir.strpath, 'dst')

    os.mkdir(src_dir)
    os.mkdir(dst_dir)

    d = os.path.join(dst_dir, 'src')
    util.copy(src_dir, d)

    assert os.path.exists(d)
Пример #3
0
def test_copy_dir(temp_dir):
    src_dir = os.path.join(temp_dir.strpath, "src")
    dst_dir = os.path.join(temp_dir.strpath, "dst")

    os.mkdir(src_dir)
    os.mkdir(dst_dir)

    d = os.path.join(dst_dir, "src")
    util.copy(src_dir, d)

    assert os.path.exists(d)
Пример #4
0
def test_copy_file(temp_dir):
    dst_dir = os.path.join(temp_dir.strpath, 'dst')

    os.mkdir(dst_dir)

    src = os.path.join(temp_dir.strpath, 'foo')
    open(src, 'a').close()

    util.copy(src, dst_dir)

    dst = os.path.join(dst_dir, 'foo')
    assert os.path.exists(dst)
Пример #5
0
def test_copy_file(temp_dir):
    dst_dir = os.path.join(temp_dir.strpath, "dst")

    os.mkdir(dst_dir)

    src = os.path.join(temp_dir.strpath, "foo")
    open(src, "a").close()

    util.copy(src, dst_dir)

    dst = os.path.join(dst_dir, "foo")
    assert os.path.exists(dst)
Пример #6
0
def test_copy_raises(temp_dir):
    with pytest.raises(OSError):
        util.copy('invalid-src', 'invalid-dst')
Пример #7
0
def test_copy_raises(temp_dir):
    with pytest.raises(OSError):
        util.copy("invalid-src", "invalid-dst")