part of --unique-md-filenames is complete. This lets createrepo
authorSeth Vidal <skvidal@fedoraproject.org>
Mon, 28 Jan 2008 21:57:37 +0000 (16:57 -0500)
committerSeth Vidal <skvidal@fedoraproject.org>
Mon, 28 Jan 2008 21:57:37 +0000 (16:57 -0500)
generate metadata files with the file's checksum included in the
filename. This helps it work more nicely with proxies. --update support will not
work with --unique-md-filenames at the moment. Need to read in repomd.xml to make that
work.

createrepo/__init__.py
genpkgmetadata.py

index d3f8534efa7143e170a91ef0e6d9af570566f512..429bb07f6cc49c7e4e73bea9fce4665bc886cbdf 100644 (file)
@@ -86,6 +86,7 @@ class MetaDataConfig(object):
         self.directory = None
         self.directories = []
         self.changelog_limit = None # needs to be an int or None
+        self.unique_md_filenames = False
         
 
 class SimpleMDCallBack(object):
@@ -292,7 +293,8 @@ class MetaDataGenerator:
         # function for the first dir passed to --split, not all of them
         # this needs to be fixed by some magic in readMetadata.py
         # using opts.pkgdirs as a list, I think.
-        
+        # FIXME - this needs to read the old repomd.xml to figure out where
+        # the files WERE to pass in the right fns.
         if self.conf.update:
             #build the paths
             primaryfile = os.path.join(self.conf.outputdir, self.conf.finaldir, self.conf.primaryfile)
@@ -496,7 +498,7 @@ class MetaDataGenerator:
             zfo.close()
             csum = misc.checksum(sumtype, complete_path)
             timestamp = os.stat(complete_path)[8]
-            
+
             db_csums = {}
             db_compressed_sums = {}
             
@@ -525,7 +527,7 @@ class MetaDataGenerator:
                 compressed_name = '%s.bz2' % good_name
                 result_compressed = os.path.join(repopath, compressed_name)
                 db_csums[ftype] = misc.checksum(sumtype, resultpath)
-                
+
                 # compress the files
                 bzipFile(resultpath, result_compressed)
                 # csum the compressed file
@@ -533,6 +535,13 @@ class MetaDataGenerator:
                 # remove the uncompressed file
                 os.unlink(resultpath)
 
+                if self.conf.unique_md_filenames:
+                    csum_compressed_name = '%s-%s.bz2' % (good_name, db_compressed_sums[ftype])
+                    csum_result_compressed =  os.path.join(repopath, csum_compressed_name)
+                    os.rename(result_compressed, csum_result_compressed)
+                    result_compressed = csum_result_compressed
+                    compressed_name = csum_compressed_name
+                    
                 # timestamp the compressed file
                 db_timestamp = os.stat(result_compressed)[8]
                 
@@ -558,15 +567,28 @@ class MetaDataGenerator:
                 
             data = reporoot.newChild(None, 'data', None)
             data.newProp('type', ftype)
-            location = data.newChild(None, 'location', None)
-            if self.conf.baseurl is not None:
-                location.newProp('xml:base', self.conf.baseurl)
-            location.newProp('href', os.path.join(self.conf.finaldir, file))
+
             checksum = data.newChild(None, 'checksum', csum)
             checksum.newProp('type', sumtype)
             timestamp = data.newChild(None, 'timestamp', str(timestamp))
             unchecksum = data.newChild(None, 'open-checksum', uncsum)
             unchecksum.newProp('type', sumtype)
+            location = data.newChild(None, 'location', None)
+            if self.conf.baseurl is not None:
+                location.newProp('xml:base', self.conf.baseurl)
+            if self.conf.unique_md_filenames:
+                res_file = '%s-%s.xml.gz' % (ftype, csum)
+                orig_file = os.path.join(repopath, file)
+                dest_file = os.path.join(repopath, res_file)
+                os.rename(orig_file, dest_file)
+                
+            else:
+                res_file = file
+
+            file = res_file #???
+            
+            location.newProp('href', os.path.join(self.conf.finaldir, file))
+
 
         if not self.conf.quiet and self.conf.database: self.callback.log('Sqlite DBs complete')        
         # if we've got a group file then checksum it once and be done
index e46b0a7885444e2d564c558fd38f8dbb1fd34f5f..6b9560f5857d4a1e3b15260135504635c2e36195 100755 (executable)
@@ -83,7 +83,11 @@ def parseArgs(args, conf):
                       help="ignore symlinks of packages")
     parser.add_option("--changelog-limit", dest="changelog_limit",
                       default=None, help="only import the last N changelog entries")
-
+    parser.add_option("--unique-md-filenames", dest="unique_md_filenames",
+                      default=False, action="store_true",
+                      help="include the file's checksum in the filename, helps" \
+                           "with proxies")
+                           
     (opts, argsleft) = parser.parse_args()
     if len(argsleft) > 1 and not opts.split:
         errorprint(_('Error: Only one directory allowed per run.'))