From 7c894bd5084493546872cce636ea38d6af6a0524 Mon Sep 17 00:00:00 2001 From: Jesse Keating Date: Fri, 21 Jan 2011 17:02:47 -0800 Subject: Regenerate the srpm if spec file is newer (ticket #84) Compare the modification times of the spec and the srpm if it exists and see if we need to re-generate due to a spec change. Most of this code comes from Gianluca Sforna with modifications from me. --- src/pyfedpkg/__init__.py | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/pyfedpkg/__init__.py b/src/pyfedpkg/__init__.py index 1d954de..f78cee0 100644 --- a/src/pyfedpkg/__init__.py +++ b/src/pyfedpkg/__init__.py @@ -227,6 +227,15 @@ def _verify_file(file, hash, hashtype): return True return False +def _newer(file1, file2): + """Compare the last modification time of the given files + + Returns True is file1 is newer than file2 + + """ + + return os.path.getmtime(file1) > os.path.getmtime(file2) + def _get_build_arches_from_srpm(srpm, arches): """Given the path to an srpm, determine the possible build arches @@ -1527,21 +1536,14 @@ class PackageModule: """ # Make sure we have an srpm to run on - srpm = os.path.join(self.path, - "%s-%s-%s.src.rpm" % (self.module, - self.ver, self.rel)) - # See if we need to build the srpm - if not os.path.exists(srpm): - # This should figure out the hashtype to use - log.debug('No srpm found, building one.') - self.srpm() + self.srpm() # setup the command cmd = ['mock'] cmd.extend(mockargs) cmd.extend(['-r', self.mockconfig, '--resultdir', os.path.join(self.path, self.module, self.ver, self.rel), - '--rebuild', srpm]) + '--rebuild', self.srpmname]) # Run the command _run_command(cmd) return @@ -1699,6 +1701,17 @@ class PackageModule: """ + self.srpmname = os.path.join(self.path, + "%s-%s-%s.src.rpm" % (self.module, + self.ver, self.rel)) + # See if we need to build the srpm + if not os.path.exists(self.srpmname): + log.debug('No srpm found, building one.') + elif _newer(self.srpmname, self.spec): + log.debug('srpm is up-to-date, skip rebuilding') + # srpm is newer, don't redo it + return + cmd = ['rpmbuild'] cmd.extend(self.rpmdefines) # Figure out which hashtype to use, if not provided one -- cgit