Re: [Patch] createrepo --check option

Hans-Peter Jansen <[email protected]>
Newsgroups gmane.linux.rpm.metadata
Message-ID <[email protected]>
and here's the missing patch :-(:

_______________________________________________
Rpm-metadata mailing list
[email protected]
https://lists.dulug.duke.edu/mailman/listinfo/rpm-metadata
createrepo-check-option.diff (text/x-diff, 5 KB)
--- genpkgmetadata.py.orig	2005-01-18 08:20:25.000000000 +0100
+++ genpkgmetadata.py	2005-05-12 11:19:11.418835767 +0200
@@ -48,6 +48,7 @@
      -x, --exclude = files globs to exclude, can be specified multiple times
      -q, --quiet = run quietly
      -g, --groupfile <filename> to point to for group information (precreated)
+     -c, --check = don't recreate repo metadata, if timestamps are up to date
      -v, --verbose = run verbosely
      -s, --checksum = md5 or sha - select type of checksum to use (default: sha)
      -h, --help = show this help
@@ -131,6 +132,7 @@
     cmds['excludes'] = []
     cmds['baseurl'] = None
     cmds['groupfile'] = None
+    cmds['check'] = 0
     cmds['sumtype'] = 'sha'
     cmds['pretty'] = 0
 #    cmds['updategroupsonly'] = 0
@@ -138,9 +140,9 @@
     cmds['dir-pattern-match'] = ['.*bin\/.*', '^\/etc\/.*']
 
     try:
-        gopts, argsleft = getopt.getopt(args, 'phqVvg:s:x:u:', ['help', 'exclude=', 
+        gopts, argsleft = getopt.getopt(args, 'phqVvg:cs:x:u:', ['help', 'exclude=', 
                                             'quiet', 'verbose',
-                                            'baseurl=', 'groupfile=', 'checksum=',
+                                            'baseurl=', 'groupfile=', 'check', 'checksum=',
                                             'version', 'pretty'])
     except getopt.error, e:
         errorprint(_('Options Error: %s.') % e)
@@ -190,6 +192,8 @@
                     else:
                         errorprint(_('Error: groupfile %s cannot be found.' % a))
                         usage()
+            elif arg in ['-c', '--check']:
+                cmds['check'] = 1
             elif arg in ['-x', '--exclude']:
                 cmds['excludes'].append(a)
             elif arg in ['-p', '--pretty']:
@@ -210,15 +214,9 @@
         
     return cmds, directory
 
-def doPkgMetadata(cmds, ts):
+def doPkgMetadata(files, cmds, ts):
     """all the heavy lifting for the package metadata"""
-
-    # rpms we're going to be dealing with
-    files = []
-    files = getFileList('./', '.rpm', files)
-    files = trimRpms(files, cmds['excludes'])
     pkgcount = len(files)
-    
     # setup the base metadata doc
     basedoc = libxml2.newDoc("1.0")
     baseroot =  basedoc.newChild(None, "metadata", None)
@@ -407,15 +405,54 @@
                     errorprint(_('error in must be able to write to metadata files:\n  -> %s') % filepath)
                     os.chdir(curdir)
                     usage()
-                    
+
+
+    # rpms we're going to be dealing with
+    rpmfiles = []
+    rpmfiles = getFileList('./', '.rpm', rpmfiles)
+    rpmfiles = trimRpms(rpmfiles, cmds['excludes'])
+
+
+    # check, if the repo metadata is up to date
+    if cmds['check']:
+        repots = 0
+        # find oldest metadata file
+        for filename in ['primaryfile', 'filelistsfile', 'otherfile', 'repomdfile', 'groupfile']:
+            if not cmds[filename]:  # groupfile may not used
+                continue
+            filepath = os.path.join(cmds['finaldir'], cmds[filename])
+            if not os.path.exists(filepath):
+                # some files don't exist: redo metadata
+                repots = 0
+                break
+            ts = os.path.getmtime(filepath)
+            if repots < ts:
+                repots = ts
+        if repots:
+            # any rpm newer then oldest metadata file?
+            for filename in rpmfiles:
+                ts = os.path.getmtime(filename)
+                if ts > repots:
+                    repots = 0
+                    break
+            if repots:
+                # we're done
+                if not cmds['quiet']:
+                    print _('Repo metadata is up to date')
+                os.chdir(curdir)
+                return
+
+
     ts = rpm.TransactionSet()
     try:
-        doPkgMetadata(cmds, ts)
+        doPkgMetadata(rpmfiles, cmds, ts)
     except:
         # always clean up your messes
         os.chdir(curdir)
         raise
-    
+
+    del rpmfiles
+
     try:
         doRepoMetadata(cmds)
     except:
--- docs/createrepo.8.orig	2005-01-18 08:20:25.000000000 +0100
+++ docs/createrepo.8	2005-05-12 11:29:56.727699696 +0200
@@ -1,4 +1,4 @@
-.TH "createrepo" "8" "2005 Jan 2" "Seth Vidal" ""
+.TH "createrepo" "8" "2005 May 12" "Seth Vidal" ""
 
 .SH "NAME"
 createrepo \- Create repomd (xml-rpm-metadata) repository
@@ -22,6 +22,8 @@
 A precreated xml filename to point to for group information.
 .br
 See examples section below for further explanation.
+.IP "\fB\-c --check\fP"
+Don't recreate repo metadata, if timestamps are up to date.
 .IP "\fB\-v --verbose\fP"
 Run verbosely.
 .IP "\fB\-s --checksum\fP <type>"
--- ChangeLog.orig	2005-01-18 08:20:25.000000000 +0100
+++ ChangeLog	2005-05-12 11:34:58.303146189 +0200
@@ -1,3 +1,9 @@
+2005-05-12 11:31  Hans-Peter Jansen <[email protected]>
+
+	* genpkgmetadata.py, docs/createrepo.8:
+	-c, --check option added to short cut metadata creation, if 
+	filestamps are up to date.
+
 2005-01-18 02:14  skvidal
 
 	* Makefile, docs/Makefile:
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.