on 'lgp build' failure some temporary directories are kept (Closes: #8367)

authorJulien Jehannet <julien.jehannet@logilab.fr>
changesetc223dbb56323
branchdefault
phasepublic
hiddenno
parent revision#f81bdddf22f8 raise an error if a file is missing
child revision#d0825471b3c8 replace post-treatment by pbuilder hooks
files modified by this revision
lgp/setupinfo.py
# HG changeset patch
# User Julien Jehannet <julien.jehannet@logilab.fr>
# Date 1244125834 -7200
# Thu Jun 04 16:30:34 2009 +0200
# Node ID c223dbb56323c33bfe7dabf74bf9ce2b47687007
# Parent f81bdddf22f86c10f1622d5219b5c36283b7ac78
on 'lgp build' failure some temporary directories are kept (Closes: #8367)

diff --git a/lgp/setupinfo.py b/lgp/setupinfo.py
@@ -31,11 +31,11 @@
1  from subprocess import Popen, PIPE
2  from subprocess import check_call, CalledProcessError
3 
4  from logilab.common.configuration import Configuration
5  from logilab.common.logging_ext import ColorFormatter
6 -from logilab.common.shellutils import cp
7 +from logilab.common.shellutils import cp, mv
8 
9  from logilab.devtools.lib.pkginfo import PackageInfo
10  from logilab.devtools.lib import TextReporter
11  from logilab.devtools.lgp.exceptions import LGPException, LGPCommandException
12  from logilab.devtools.lgp.utils import get_distributions, get_architectures, cached
@@ -375,54 +375,57 @@
13          dist_dir = os.path.dirname(self.get_distrib_dir())
14          fileparts = (self.get_upstream_name(), self.get_upstream_version())
15          # directory containing the debianized source tree
16          # (i.e. with a debian sub-directory and maybe changes to the original files)
17          # origpath is depending of the upstream convention
18 -        origpath = "%s-%s" % fileparts
19 +        origpath = os.path.join(self._tmpdir, "%s-%s" % fileparts)
20          tarball = '%s_%s.orig.tar.gz' % fileparts
21          upstream_tarball = '%s-%s.tar.gz' % fileparts
22 
23          if self.config.orig_tarball is None:
24 -            logging.debug("creating a new source archive (tarball)...")
25 -
26 +            copy_command = mv
27 +            logging.info("create a new source archive (tarball) from upstream release")
28              try:
29                  self.check_debian_revision()
30 -                self._run_command("sdist", dist_dir=dist_dir)
31 +                self._run_command("sdist", dist_dir=self._tmpdir)
32              except CalledProcessError, err:
33                  logging.error("creation of the source archive failed")
34                  logging.error("check if the version '%s' is really tagged in"\
35                                    " your repository" % self.get_upstream_version())
36                  raise LGPCommandException("source distribution wasn't properly built", err)
37 -
38 +            upstream_tarball = os.path.join(self._tmpdir, upstream_tarball)
39          else:
40 +            copy_command = cp
41              expected = [upstream_tarball, tarball]
42              if os.path.basename(self.config.orig_tarball) not in expected:
43 -                logging.error("the provided tarball hasn't one of the expected formats (%s)"
44 +                logging.error("the provided archive hasn't one of the expected formats (%s)"
45                                % ','.join(expected))
46 -            upstream_tarball = os.path.expanduser(self.config.orig_tarball)
47 +            upstream_tarball = os.path.abspath(os.path.expanduser(self.config.orig_tarball))
48 +            logging.info("use provided archive '%s' as original source archive (tarball)"
49 +                         % upstream_tarball)
50 
51 -        # rewrite to full paths
52 -        tarball = os.path.join(self._tmpdir, tarball)
53 -        upstream_tarball = os.path.join(dist_dir, upstream_tarball)
54 -        origpath = os.path.join(self._tmpdir, origpath)
55 +        assert os.path.isfile(upstream_tarball), 'original source archive (tarball) not found'
56 
57 -        logging.info("get '%s' as original source archive (tarball)" % upstream_tarball)
58 -        if not os.path.isfile(upstream_tarball):
59 -            raise LGPException('the original source archive (tarball) not found in %s' % dist_dir)
60 +        # exit if asked by command-line
61 +        if self.config.get_orig_source:
62 +            try:
63 +                cp(upstream_tarball, tarball)
64 +                logging.info('a new original source archive (tarball) in current directory (%s)'
65 +                             % tarball)
66 +                sys.exit()
67 +            except shutil.Error, err:
68 +                raise LGPException(err)
69 
70 -        # FIXME use one copy of the upstream tarball
71 -        # note the renaming of the new tarball filename
72          # dpkg-source expects the  original source as a tarfile
73          # by default: package_upstream-version.orig.tar.extension
74          logging.debug("rename '%s' to '%s'" % (upstream_tarball, tarball))
75 -        cp(upstream_tarball, tarball)
76 +        tarball = os.path.join(self._tmpdir, tarball) # rewrite with absolute path
77 +        copy_command(upstream_tarball, tarball)
78 
79          # test and extracting the .orig.tar.gz
80          try:
81 -            # FIXME use one copy of the upstream tarball
82 -            #cmd = 'tar xzf %s -C %s' % (tarball, self._tmpdir)
83 -            cmd = 'tar xzf %s -C %s' % (upstream_tarball, self._tmpdir)
84 +            cmd = 'tar xzf %s -C %s' % (tarball, self._tmpdir)
85              check_call(cmd.split(), stdout=sys.stdout,
86                                      stderr=sys.stderr)
87          except CalledProcessError, err:
88              raise LGPCommandException('an error occured while extracting the '
89                                        'upstream tarball', err)