summaryrefslogtreecommitdiff
path: root/tests/testutils/repo/tar.py
blob: 158a04891e3d5af97980d9d4ae773b3df4ee2523 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import os
import tarfile
import hashlib

from buildstream.utils import sha256sum

from .repo import Repo


class Tar(Repo):

    def create(self, directory):
        tarball = os.path.join(self.repo, 'file.tar.gz')

        old_dir = os.getcwd()
        os.chdir(directory)
        with tarfile.open(tarball, "w:gz") as tar:
            tar.add(".")
        os.chdir(old_dir)

        return sha256sum(tarball)

    def source_config(self, ref=None):
        tarball = os.path.join(self.repo, 'file.tar.gz')
        config = {
            'kind': 'tar',
            'url': 'file://' + tarball,
            'directory': '',
            'base-dir': ''
        }
        if ref is not None:
            config['ref'] = ref

        return config