diff options
Diffstat (limited to 'tests/testutils')
-rw-r--r-- | tests/testutils/repo/__init__.py | 2 | ||||
-rw-r--r-- | tests/testutils/repo/zip.py | 40 |
2 files changed, 42 insertions, 0 deletions
diff --git a/tests/testutils/repo/__init__.py b/tests/testutils/repo/__init__.py index 3516679aa..1123d6f5e 100644 --- a/tests/testutils/repo/__init__.py +++ b/tests/testutils/repo/__init__.py @@ -6,12 +6,14 @@ from .git import Git from .bzr import Bzr from .ostree import OSTree from .tar import Tar +from .zip import Zip ALL_REPO_KINDS = OrderedDict() ALL_REPO_KINDS['git'] = Git ALL_REPO_KINDS['bzr'] = Bzr ALL_REPO_KINDS['ostree'] = OSTree ALL_REPO_KINDS['tar'] = Tar +ALL_REPO_KINDS['zip'] = Zip # create_repo() diff --git a/tests/testutils/repo/zip.py b/tests/testutils/repo/zip.py new file mode 100644 index 000000000..47c402421 --- /dev/null +++ b/tests/testutils/repo/zip.py @@ -0,0 +1,40 @@ +import hashlib +import os +import zipfile + +from buildstream.utils import sha256sum + +from .repo import Repo + + +class Zip(Repo): + + def create(self, directory): + archive = os.path.join(self.repo, 'file.zip') + + old_dir = os.getcwd() + os.chdir(directory) + with zipfile.ZipFile(archive, "w") as zip: + for root, dirs, files in os.walk('.'): + names = dirs + files + names = [os.path.join(root, name) for name in names] + + for name in names: + zip.write(name) + + os.chdir(old_dir) + + return sha256sum(archive) + + def source_config(self, ref=None): + archive = os.path.join(self.repo, 'file.zip') + config = { + 'kind': 'zip', + 'url': 'file://' + archive, + 'directory': '', + 'base-dir': '' + } + if ref is not None: + config['ref'] = ref + + return config |