diff options
author | Mathieu Bridon <bochecha@daitauha.fr> | 2017-10-30 18:03:03 +0100 |
---|---|---|
committer | Mathieu Bridon <bochecha@daitauha.fr> | 2017-11-03 14:57:24 +0800 |
commit | 958d118a380a4785e26f4542532216c33bad408d (patch) | |
tree | 30b0ae15a741e2d9820d07bdd17072e5261d00cf /tests/testutils/repo | |
parent | 3f25bb99437b17e627c26719c83c14294fe25e80 (diff) | |
download | buildstream-958d118a380a4785e26f4542532216c33bad408d.tar.gz |
Add a new zip sourcezip
This is equivalent to the tar source, but for Zip archives.
Diffstat (limited to 'tests/testutils/repo')
-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 |