Coverage for snapcraft/sources : 76%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*- # # Copyright (C) 2015 Canonical Ltd # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3 as # published by the Free Software Foundation. # # This program 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>.
A part that uses common source options can have these keyword entries:
- source: (string) A path to some source tree to build. It can be either remote or local, and either a directory tree or a tarball. - source-type: (string) In some cases the source is not enough to identify the version control system or compression algorithim. This hints the system into what to do, the valid values are:
- bzr - mercurial - hg - git - tar
- source-branch: (string) A specific branch from the source tree. This will result in an error if used with a bazaar source type. - source-tag: (string) A specific tag from the source tree. - source-subdir: (string) A source directory within a repository or tarfile to enter and build from. """
source_branch=None):
source_branch=None): 'can\'t specify a source-branch for a bzr source')
[self.source, '-d', self.source_dir] else: [self.source, self.source_dir]
source_branch=None): 'can\'t specify both source-tag and source-branch for ' 'a git source')
else: self.source_tag or self.source_branch] [self.source, self.source_dir]
source_branch=None): 'can\'t specify both source-tag and source-branch for a ' 'mercurial source')
else:
source_branch=None): 'can\'t specify a source-tag for a tar source') 'can\'t specify a source-branch for a tar source')
raise EnvironmentError('unexpected http status code when ' 'downloading {}'.format(req.status_code))
# TODO add unit tests. if snapcraft.common.isurl(self.source): tarball = os.path.join( self.source_dir, os.path.basename(self.source)) else: tarball = os.path.abspath(self.source)
if clean_target: tmp_tarball = tempfile.NamedTemporaryFile().name shutil.move(tarball, tmp_tarball) shutil.rmtree(dst) os.makedirs(dst) shutil.move(tmp_tarball, tarball)
self._extract(tarball, dst)
with tarfile.open(tarball) as tar: def filter_members(tar): """Filters members and member names: - strips common prefix - bans dangerous names""" members = tar.getmembers() common = os.path.commonprefix([m.name for m in members])
# commonprefix() works a character at a time and will # consider "d/ab" and "d/abc" to have common prefix "d/ab"; # check all members either start with common dir for m in members: if not (m.name.startswith(common + '/') or m.isdir() and m.name == common): # commonprefix() didn't return a dir name; go up one # level common = os.path.dirname(common) break
for m in members: if m.name == common: continue if m.name.startswith(common + '/'): m.name = m.name[len(common + '/'):] # strip leading '/', './' or '../' as many times as needed m.name = re.sub(r'^(\.{0,2}/)*', r'', m.name) # We mask all files to be writable to be able to easily # extract on top. m.mode = m.mode | 0o200 yield m
tar.extractall(members=filter_members(tar), path=dst)
os.remove(self.source_dir) else:
"""Populate sourcedir and builddir from parameters defined in options.
:param str sourcedir: The source directory to use. :param str builddir: The build directory to use. :param options: source options. """
source_branch)
'bzr': Bazaar, 'git': Git, 'hg': Mercurial, 'mercurial': Mercurial, 'tar': Tar, }
source_type = 'bzr' source_type = 'git'
|