[build] add support for suffix option in rpm (closes #289137)

authorDavid Douard <david.douard@logilab.fr>
changesetecb16898cf4e
branchdefault
phasepublic
hiddenno
parent revision#2f0a0bb0d9e0 [pkg] fix tests under virtualenv
child revision#7545f2bea4a1 [pkg] 1.1.0
files modified by this revision
lgp/build.py
# HG changeset patch
# User David Douard <david.douard@logilab.fr>
# Date 1426860240 -3600
# Fri Mar 20 15:04:00 2015 +0100
# Node ID ecb16898cf4e544790f9090bcb86d923ddf2fdad
# Parent 2f0a0bb0d9e04d744f9d825838357ffdb9e4c2bf
[build] add support for suffix option in rpm (closes #289137)

diff --git a/lgp/build.py b/lgp/build.py
@@ -320,10 +320,22 @@
1                  else:
2                      self.logger.error("more than one spec file found")
3                  self.logger.error("please use the '--specfile' option")
4                  raise LGPException("cannot build source distribution")
5          specfile = osp.abspath(specfile)
6 +        if self.config.suffix is not None:
7 +            # patch the spec file to inject the ~revision in the version
8 +            suffix = self.config.suffix or '+%s' % int(time.time())
9 +            with tempfile.NamedTemporaryFile() as out:
10 +                for line in open(specfile):
11 +                    if line.lower().startswith('release:'):
12 +                        line = line.strip() + suffix + '\n'
13 +                    out.write(line)
14 +                out.flush()
15 +                shutil.move(out.name, specfile)
16 +                out.delete = False
17 +                os.chmod(specfile, 0o644)
18 
19          # change directory to build source package
20          # note: call os.chdir() HERE is needed in make_rpm_binary_package() below
21          os.chdir(tmpdir)
22          try: