re-enabled group files
authorSeth Vidal <skvidal@linux.duke.edu>
Tue, 20 Jul 2004 01:23:57 +0000 (01:23 +0000)
committerSeth Vidal <skvidal@linux.duke.edu>
Tue, 20 Jul 2004 01:23:57 +0000 (01:23 +0000)
documented it

dumpMetadata.py
genpkgmetadata.py

index 31c996798114fa3fe05a1bfc1cd8c9cf8062ba33..f892a0c317dd3796a5b8b814c31f0c7c86e24920 100644 (file)
@@ -81,7 +81,7 @@ def getChecksum(sumtype, file, CHUNK=2**16):
             
         return sum.hexdigest()
     except:
-        raise MDError, 'Error opening file for checksum'
+        raise MDError, 'Error opening file for checksum: %s' % file
 
 
 def utf8String(string):
@@ -639,8 +639,6 @@ def repoXML(node, cmds):
                  (cmds['filelistsfile'], 'filelists'),
                  (cmds['primaryfile'], 'primary')]
     
-    if cmds['groupfile'] is not None:
-        workfiles.append((cmds['groupfile'], 'group'))
     
     for (file, ftype) in workfiles:
         zfo = _gzipOpen(os.path.join(cmds['tempdir'], file))
@@ -657,6 +655,27 @@ def repoXML(node, cmds):
         checksum = data.newChild(None, 'checksum', csum)
         checksum.newProp('type', sumtype)
         timestamp = data.newChild(None, 'timestamp', str(timestamp))
-        unchecksum = unchecksum = data.newChild(None, 'open-checksum', uncsum)
+        unchecksum = data.newChild(None, 'open-checksum', uncsum)
         unchecksum.newProp('type', sumtype)
-        
+    
+    # if we've got a group file then checksum it once and be done
+    if cmds['groupfile'] is not None:
+        grpfile = cmds['groupfile']
+        timestamp = os.stat(grpfile)[8]
+        sfile = os.path.basename(grpfile)
+        fo = open(grpfile, 'r')
+        output = open(os.path.join(cmds['tempdir'], sfile), 'w')
+        output.write(fo.read())
+        output.close()
+        csum = getChecksum(sumtype, fo)
+        fo.close()
+
+        data = node.newChild(None, 'data', None)
+        data.newProp('type', 'group')
+        location = data.newChild(None, 'location', None)
+        if cmds['baseurl'] is not None:
+            location.newProp('xml:base', cmds['baseurl'])
+        location.newProp('href', os.path.join(cmds['finaldir'], grpfile))
+        checksum = data.newChild(None, 'checksum', csum)
+        checksum.newProp('type', sumtype)
+        timestamp = data.newChild(None, 'timestamp', str(timestamp))
index cc847fadcb4d3133f4aef9dcd78d969ed1ec8e7d..85a32d02858da879717042555ee90d793af499de 100755 (executable)
@@ -50,6 +50,7 @@ def usage():
      -u, --baseurl = optional base url location for all files
      -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)
      -v, --verbose = run verbosely
      -s, --checksum = md5 or sha - select type of checksum to use (default: md5)
      -h, --help = show this help
@@ -188,13 +189,16 @@ def parseArgs(args):
                     usage()
                 else:
                     cmds['baseurl'] = a
-#            elif arg in ['-g', '--groupfile']:
-#                if cmds['groupfile'] is not None:
-#                    errorprint(_('Error: Only one groupfile allowed.'))
-#                    usage()
-#                else:
-#                    cmds['groupfile'] = a
-                    
+            elif arg in ['-g', '--groupfile']:
+                if cmds['groupfile'] is not None:
+                    errorprint(_('Error: Only one groupfile allowed.'))
+                    usage()
+                else:
+                    if os.path.exists(a):
+                        cmds['groupfile'] = a
+                    else:
+                        errorprint(_('Error: groupfile %s cannot be found.' % a))
+                        usage()
             elif arg in ['-x', '--exclude']:
                 cmds['excludes'].append(a)
             elif arg in ['-p', '--pretty']:
@@ -402,13 +406,6 @@ def main(args):
         errorprint(_('Old data directory exists, please remove: %s') % cmds['olddir'])
         sys.exit(1)
         
-    # check out the group file if specified
-#    if cmds['groupfile'] is not None:
-#        grpfile = os.path.join(directory, cmds['groupfile'])
-#        if not os.access(grpfile, os.R_OK):
-#            errorprint(_('Groupfile %s must exist and be readable') % grpfile)
-#            usage()
-
     # change to the basedir to work from w/i the path - for relative url paths
     os.chdir(directory)
 
@@ -453,9 +450,12 @@ def main(args):
         os.chdir(curdir)
         sys.exit(1)
         
-
-    for file in ['primaryfile', 'filelistsfile', 'otherfile', 'repomdfile']:
-        oldfile = os.path.join(cmds['olddir'], cmds[file])
+    for file in ['primaryfile', 'filelistsfile', 'otherfile', 'repomdfile', 'groupfile']:
+        if cmds[file]:
+            fn = os.path.basename(cmds[file])
+        else:
+            continue
+        oldfile = os.path.join(cmds['olddir'], fn)
         if os.path.exists(oldfile):
             try:
                 os.remove(oldfile)
@@ -464,6 +464,7 @@ def main(args):
                 errorprint(_('Error was %s') % e)
                 os.chdir(curdir)
                 sys.exit(1)
+            
     try:
         os.rmdir(cmds['olddir'])
     except OSError, e: