lgp: uscan invocation in `make_orig_tarball()`

New:
* new option to uscan invocation:
--rename: no use of symlink (keep just one file)
--destdir: retrieve pristine in specified directory

Changes:
* reformat logging strings
* set a valid tmpdir by default (for consistency)
* don't close stderr for uscan (quiet by default)

authorJulien Jehannet <julien.jehannet@logilab.fr>
changesetc29b109b2cb4
branchdefault
phasepublic
hiddenno
parent revision#2161e76dc7fe lgp: use generic mirror url in pbuilderrc.local example
child revision#96e3f50fa541 lgp: set instance variables before trying to merge them
files modified by this revision
lgp/build.py
# HG changeset patch
# User Julien Jehannet <julien.jehannet@logilab.fr>
# Date 1309272509 -7200
# Tue Jun 28 16:48:29 2011 +0200
# Node ID c29b109b2cb4e967f9e580fae2bdeaa4dc1a317c
# Parent 2161e76dc7fe5c696dd0e63df723e49a6a9d9728
lgp: uscan invocation in `make_orig_tarball()`

New:
* new option to uscan invocation:
--rename: no use of symlink (keep just one file)
--destdir: retrieve pristine in specified directory

Changes:
* reformat logging strings
* set a valid tmpdir by default (for consistency)
* don't close stderr for uscan (quiet by default)

diff --git a/lgp/build.py b/lgp/build.py
@@ -169,59 +169,67 @@
1                  raise exc
2              finally:
3                  self.destroy_tmp_context()
4              return self.build_status
5 
6 -    def make_orig_tarball(self, tmpdir=None):
7 +    def make_orig_tarball(self, tmpdir="."):
8          """make upstream pristine tarballs (Debian way)
9 
10 -        Start by calling uscan.
11 -        If not possible, failback to a local creation
12 +        Create the tarball from working directory for the initial revision.
13 +        For later ones call uscan to download the source tarball by looking at
14 +        debian/watch (if the tarball wasn't passed on the command line).
15 +
16 +        Finally copy pristine tarball with expected Debian filename convention.
17 
18 -        A call to move_package_files() will reset instance variable
19 -        config.orig_tarball to its new name for later reuse
20 +        This method is responsible for setting config.orig_tarball to its right
21 +        location.
22 
23 -        See:
24 -        http://www.debian.org/doc/debian-policy/ch-source.html
25 -        http://hg.logilab.org/<upstream_name>/archive/<upstream_version>.tar.gz
26 +        .. see::
27 +            http://www.debian.org/doc/debian-policy/ch-source.html
28          """
29          self._check_version_mismatch()
30 +        if self.config.orig_tarball and self.is_initial_debian_revision():
31 +            self.logger.error("you are passing a pristine tarball in command "
32 +                              "line for an initial Debian revision")
33 
34          fileparts = (self.get_upstream_name(), self.get_upstream_version())
35 +        # note: tarball format can be guaranteed by uscan's repack option
36          tarball = '%s_%s.orig.tar.gz' % fileparts
37          upstream_tarball = '%s-%s.tar.gz' % fileparts
38 
39          # run uscan to download the source tarball by looking at debian/watch
40          if self.config.orig_tarball is None and not self.is_initial_debian_revision():
41 -            self.logger.info('trying to retrieve pristine tarball remotely...')
42 +            self.logger.info('running uscan to download the source tarball by '
43 +                             'looking at debian/watch')
44              try:
45 -                cmd = ["uscan", "--noconf", "--download-current-version"]
46 -                check_call(cmd, stderr=file(os.devnull, "w"))
47 -                assert osp.isfile(osp.join('..', tarball))
48 -                self.config.orig_tarball = osp.abspath(osp.join('..', tarball))
49 +                cmd = ["uscan", "--noconf", "--download-current-version",
50 +                       "--rename", "--destdir", tmpdir]
51 +                check_call(cmd)
52 +                assert osp.isfile(osp.join(tmpdir, tarball))
53 +                self.config.orig_tarball = osp.abspath(osp.join(tmpdir, tarball))
54              except CalledProcessError, err:
55                  self.logger.warn("run '%s' without success" % ' '.join(cmd))
56 
57          if self.config.orig_tarball is None:
58              # Make a coherence check about the pristine tarball
59              if not self.is_initial_debian_revision():
60 +                debian_name     = self.get_debian_name()
61                  debian_revision = self.get_debian_version().rsplit('-', 1)[1]
62                  self.logger.error("Debian source archive (pristine tarball) is required when you "
63                                    "don't build the first revision of a debian package "
64                                    "(use '--orig-tarball' option)")
65                  self.logger.info("If you haven't the original tarball version, you could run: "
66 -                                 "'apt-get source --tar-only %s'"
67 -                                 % self.get_debian_name())
68 +                                 "'apt-get source --tar-only %s'" % debian_name)
69                  raise LGPException('unable to build upstream tarball of %s package '
70                                     'for Debian revision "%s"'
71 -                                   % (self.get_debian_name(), debian_revision))
72 +                                   % (debian_name, debian_revision))
73              try:
74                  self._run_command("sdist", dist_dir=tmpdir)
75              except CalledProcessError, err:
76                  self.logger.error("creation of the source archive failed")
77 -                self.logger.error("check if the version '%s' is really tagged in"\
78 -                                  " your repository" % self.get_upstream_version())
79 +                self.logger.error("check if the version '%s' is really tagged in "
80 +                                  "your repository" % self.get_upstream_version())
81                  raise LGPCommandException("source distribution wasn't properly built", err)
82              self.config.orig_tarball = osp.join(tmpdir, upstream_tarball)
83              msg = "create new Debian source archive (pristine tarball) from working directory: %s"
84          else:
85              msg = "retrieve original Debian source archive (pristine tarball): %s"