[Rpm-metadata] createrepo/__init__.py createrepo/readMetadata.py createrepo/yumbased.py

Seth Vidal skvidal at linux.duke.edu
Wed Jan 9 04:01:15 UTC 2008


 createrepo/__init__.py     |   22 ++++++++++++++--------
 createrepo/readMetadata.py |   25 +++++++++++++++++++------
 createrepo/yumbased.py     |   17 ++++++++---------
 3 files changed, 41 insertions(+), 23 deletions(-)

New commits:
commit 1ab5b8214208aee0a4b9fe8b6c954dfda3fa1abe
Author: Seth Vidal <skvidal at fedoraproject.org>
Date:   Tue Jan 8 22:59:28 2008 -0500

    fix up a lot of xml creation errors and make --update work again

diff --git a/createrepo/__init__.py b/createrepo/__init__.py
index e12ae58..d834352 100644
--- a/createrepo/__init__.py
+++ b/createrepo/__init__.py
@@ -190,7 +190,7 @@ class MetaDataGenerator:
         primaryfilepath = os.path.join(self.conf.outputdir, self.conf.tempdir, self.conf.primaryfile)
         fo = _gzipOpen(primaryfilepath, 'w')
         fo.write('<?xml version="1.0" encoding="UTF-8"?>\n')
-        fo.write('<metadata xmlns="http://linux.duke.edu/metadata/common" xmlns:rpm="http://linux.duke.edu/metadata/rpm" packages="%s">\n' %
+        fo.write('<metadata xmlns="http://linux.duke.edu/metadata/common" xmlns:rpm="http://linux.duke.edu/metadata/rpm" packages="%s">' %
                        self.pkgcount)
         return fo
 
@@ -199,7 +199,7 @@ class MetaDataGenerator:
         filelistpath = os.path.join(self.conf.outputdir, self.conf.tempdir, self.conf.filelistsfile)
         fo = _gzipOpen(filelistpath, 'w')
         fo.write('<?xml version="1.0" encoding="UTF-8"?>\n')
-        fo.write('<filelists xmlns="http://linux.duke.edu/metadata/filelists" packages="%s">\n' %
+        fo.write('<filelists xmlns="http://linux.duke.edu/metadata/filelists" packages="%s">' %
                        self.pkgcount)
         return fo
         
@@ -208,7 +208,7 @@ class MetaDataGenerator:
         otherfilepath = os.path.join(self.conf.outputdir, self.conf.tempdir, self.conf.otherfile)
         fo = _gzipOpen(otherfilepath, 'w')
         fo.write('<?xml version="1.0" encoding="UTF-8"?>\n')
-        fo.write('<otherdata xmlns="http://linux.duke.edu/metadata/other" packages="%s">\n' %
+        fo.write('<otherdata xmlns="http://linux.duke.edu/metadata/other" packages="%s">' %
                        self.pkgcount)
         return fo
         
@@ -230,7 +230,7 @@ class MetaDataGenerator:
             current+=1
             recycled = False
             sep = '-'
-            
+            print pkg
             # look to see if we can get the data from the old repodata
             # if so write this one out that way
             if self.conf.update:
@@ -254,8 +254,10 @@ class MetaDataGenerator:
                 self.flfile.write(po.do_filelists_xml_dump())
                 self.otherfile.write(po.do_other_xml_dump())
             else:
+                if self.conf.verbose:
+                    print "Using data from old metadata for %s" % pkg
                 sep = '*'
-                primarynode, filenode, othernode = nodes    
+                (primarynode, filenode, othernode) = nodes    
 
                 for node, outfile in ((primarynode,self.primaryfile),
                                       (filenode,self.flfile),
@@ -263,10 +265,14 @@ class MetaDataGenerator:
                     if node is None:
                         break
                     output = node.serialize('UTF-8', self.conf.pretty)
-                    outfile.write(output)
+                    if output:
+                        outfile.write(output)
+                    else:
+                        if self.conf.verbose:
+                            print "empty serialize on write to %s in %s" % (outfile, pkg)
                     outfile.write('\n')
-  
-                    self.oldData.freeNodes(pkg)
+
+                self.oldData.freeNodes(pkg)
 
             if not self.conf.quiet:
                 if self.conf.verbose:
diff --git a/createrepo/readMetadata.py b/createrepo/readMetadata.py
index 0d9dacf..5074f80 100644
--- a/createrepo/readMetadata.py
+++ b/createrepo/readMetadata.py
@@ -47,10 +47,10 @@ class MetadataIndex(object):
         self.pkg_ids = {}
         if self.opts.get('verbose'):
             print _("Scanning old repo data")
-        for file in self.files.values():
-            if not os.path.exists(file):
+        for fn in self.files.values():
+            if not os.path.exists(fn):
                 #cannot scan
-                errorprint(_("Previous repo file missing: %s") % file)
+                errorprint(_("Previous repo file missing: %s") % fn)
                 return
         root = libxml2.parseFile(self.files['base']).getRootElement()
         self._scanPackageNodes(root, self._handleBase)
@@ -193,6 +193,19 @@ class MetadataIndex(object):
 
 
 if __name__ == "__main__":
-    #test code - attempts to read a repo in working directory
-    idx = MetadataIndex(".", "repodata/primary.xml.gz", "repodata/filelists.xml.gz",
-                        "repodata/other.xml.gz", {'verbose':1})
+    cwd = os.getcwd()
+    p = os.path.join(cwd, "repodata/primary.xml.gz")     
+    f = os.path.join(cwd, "repodata/filelists.xml.gz")
+    o = os.path.join(cwd, "repodata/other.xml.gz")
+    opts = {'verbose':1, 
+            'pkgdir': cwd}
+            
+    idx = MetadataIndex(".", p, f, o, opts)
+    for fn in idx.basenodes.keys():
+       a,b,c, = idx.getNodes(fn)
+       a.serialize()
+       b.serialize()
+       c.serialize()
+       idx.freeNodes(fn)
+
+                            
diff --git a/createrepo/yumbased.py b/createrepo/yumbased.py
index 144153a..237e968 100644
--- a/createrepo/yumbased.py
+++ b/createrepo/yumbased.py
@@ -132,18 +132,17 @@ class CreateRepoPackage(YumLocalPackage):
   <packager>%s</packager>
   <url>%s</url>
   <time file="%s" build="%s"/>
-  <size package="%s" installed="%s" archive="%s"/>
-
-  """ % (self.name, self.arch, self.epoch, self.ver, self.rel, self.checksum, 
+  <size package="%s" installed="%s" archive="%s"/>""" % (self.name, 
+         self.arch, self.epoch, self.ver, self.rel, self.checksum, 
          self._xml(self.summary), self._xml(self.description), packager, 
          url, self.filetime, self.buildtime, self.packagesize, self.size, 
          self.archivesize)
          
 
         if baseurl:
-            msg += """<location xml:base="%s" href="%s"/>\n""" % (self._xml(baseurl), relpath)
+            msg += """<location xml:base="%s" href="%s"/>""" % (self._xml(baseurl), relpath)
         else:
-            msg += """<location href="%s"/>\n""" % relpath
+            msg += """<location href="%s"/>""" % relpath
             
         return msg
 
@@ -166,7 +165,7 @@ class CreateRepoPackage(YumLocalPackage):
         msg += self._dump_pco('conflicts')         
         msg += self._dump_pco('obsoletes')         
         msg += self._dump_files(True)
-        msg += """\n  </format>\n"""
+        msg += """\n  </format>"""
         return msg
 
     def _dump_pco(self, pcotype):
@@ -217,7 +216,7 @@ class CreateRepoPackage(YumLocalPackage):
         
         
     def _dump_files(self, primary=False):
-        msg ="\n"
+        msg =""
         if not primary:
             files = self.returnFileEntries('file')
             dirs = self.returnFileEntries('dir')
@@ -301,7 +300,7 @@ class CreateRepoPackage(YumLocalPackage):
         msg = """\n<package type="rpm">"""
         msg += self._dump_base_items(basedir, baseurl)
         msg += self._dump_format_items()
-        msg += """\n</package>\n"""
+        msg += """\n</package>"""
         return msg
 
     def do_filelists_xml_dump(self):
@@ -309,7 +308,7 @@ class CreateRepoPackage(YumLocalPackage):
     <version epoch="%s" ver="%s" rel="%s"/>\n""" % (self.checksum, self.name, 
                                      self.arch, self.epoch, self.ver, self.rel)
         msg += self._dump_files()
-        msg += "\n</package>\n"
+        msg += "</package>\n"
         return msg
 
     def do_other_xml_dump(self):   



More information about the Rpm-metadata mailing list