diff options
author | Chandan Singh <csingh43@bloomberg.net> | 2019-04-24 22:53:19 +0100 |
---|---|---|
committer | Chandan Singh <csingh43@bloomberg.net> | 2019-05-21 12:41:18 +0100 |
commit | 070d053e5cc47e572e9f9e647315082bd7a15c63 (patch) | |
tree | 7fb0fdff52f9b5f8a18ec8fe9c75b661f9e0839e /src/buildstream/plugins/sources/deb.py | |
parent | 6c59e7901a52be961c2a1b671cf2b30f90bc4d0a (diff) | |
download | buildstream-070d053e5cc47e572e9f9e647315082bd7a15c63.tar.gz |
Move source from 'buildstream' to 'src/buildstream'
This was discussed in #1008.
Fixes #1009.
Diffstat (limited to 'src/buildstream/plugins/sources/deb.py')
-rw-r--r-- | src/buildstream/plugins/sources/deb.py | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/buildstream/plugins/sources/deb.py b/src/buildstream/plugins/sources/deb.py new file mode 100644 index 000000000..e45994951 --- /dev/null +++ b/src/buildstream/plugins/sources/deb.py @@ -0,0 +1,83 @@ +# Copyright (C) 2017 Codethink Limited +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. If not, see <http://www.gnu.org/licenses/>. +# +# Authors: +# Phillip Smyth <phillip.smyth@codethink.co.uk> +# Jonathan Maw <jonathan.maw@codethink.co.uk> +# Richard Maw <richard.maw@codethink.co.uk> + +""" +deb - stage files from .deb packages +==================================== + +**Host dependencies:** + + * arpy (python package) + +**Usage:** + +.. code:: yaml + + # Specify the deb source kind + kind: deb + + # Specify the deb url. Using an alias defined in your project + # configuration is encouraged. 'bst source track' will update the + # sha256sum in 'ref' to the downloaded file's sha256sum. + url: upstream:foo.deb + + # Specify the ref. It's a sha256sum of the file you download. + ref: 6c9f6f68a131ec6381da82f2bff978083ed7f4f7991d931bfa767b7965ebc94b + + # Specify the basedir to return only the specified dir and its children + base-dir: '' + +See :ref:`built-in functionality doumentation <core_source_builtins>` for +details on common configuration options for sources. +""" + +import tarfile +from contextlib import contextmanager +import arpy # pylint: disable=import-error + +from .tar import TarSource + + +class DebSource(TarSource): + # pylint: disable=attribute-defined-outside-init + + def configure(self, node): + super().configure(node) + + self.base_dir = self.node_get_member(node, str, 'base-dir', None) + + def preflight(self): + return + + @contextmanager + def _get_tar(self): + with open(self._get_mirror_file(), 'rb') as deb_file: + arpy_archive = arpy.Archive(fileobj=deb_file) + arpy_archive.read_all_headers() + data_tar_arpy = [v for k, v in arpy_archive.archived_files.items() if b"data.tar" in k][0] + # ArchiveFileData is not enough like a file object for tarfile to use. + # Monkey-patching a seekable method makes it close enough for TarFile to open. + data_tar_arpy.seekable = lambda *args: True + tar = tarfile.open(fileobj=data_tar_arpy, mode="r:*") + yield tar + + +def setup(): + return DebSource |