tags 348755 + patch
thanks

Re: Thomas Viehmann 2006-01-20 <[EMAIL PROTECTED]>
> Hi Christoph,
> 
> thank you for your suggestion for improving dput.
> 
> Christoph Berg wrote:
> > It would be very useful if dput would check if the Distribution: field
> > in the .changes file matches an (optional) list of allowed
> > distributions in the config file. That would prevent me uploading
> > backports (Distribution: sarge-backports) to ftp-master all the time.
> > (Thanks there is dcut...)
> 
> > The same config option could also be used to guess the upload host
> > more reliably when none is given.
> 
> Sounds cool to me. I'll see how to best do this.

I implemented this, patch is attached. The local upload queue here at
Debcamp in Oaxtepec is already using this and the other patches and it
works nicely (with the right .dput.cf including the backports.org
host).

('quilt graph' tells me that this patch doesn't apply without the 
preceding patches from my other bug report (sorry, no number yet), so
please apply these first.)

Thanks for considering,
Christoph
Index: dput-0.9.2.21/dput
===================================================================
--- dput-0.9.2.21.orig/dput     2006-05-09 16:11:12.000000000 -0500
+++ dput-0.9.2.21/dput  2006-05-10 13:36:42.000000000 -0500
@@ -91,6 +91,7 @@ def read_configs(extra_config, debug):
     config.set('DEFAULT', 'method', 'scp')
     config.set('DEFAULT', 'hash', 'md5')
     config.set('DEFAULT', 'allow_unsigned_uploads', '0')
+    config.set('DEFAULT', 'distributions', '')
     config.set('DEFAULT', 'run_lintian', '0')
     config.set('DEFAULT', 'run_dinstall', '0')
     config.set('DEFAULT', 'unlink_files', '0')
@@ -423,6 +424,8 @@ def run_lintian_test(changes_file):
 # on information from the changes file.
 def guess_upload_host(path, filename):
     non_us = 0
+    distribution = ""
+    dist_re = re.compile(r'^Distribution: (.*)')
 
     name_of_file = filename
     changes_file = os.path.join(path, name_of_file)
@@ -434,9 +437,23 @@ def guess_upload_host(path, filename):
         sys.exit(1)
     lines = changes_file_fd.readlines()
     for line in lines:
+        match = dist_re.search(line)
+        if match:
+            distribution = match.group(1)
         if line.find('non-US/') != -1 or line.find('non-us/') != -1:
             non_us = 1
-            break
+    
+    # Try to guess a host based on the Distribution: field
+    if distribution:
+        for section in config.sections():
+            host_dists = config.get(section, 'distributions')
+            if not host_dists:
+                continue
+            for host_dist in host_dists.split(','):
+                if distribution == host_dist.strip():
+                    if debug:
+                        print "D: guessing host %s based on distribution %s" % 
(section, host_dist)
+                    return section
 
     if non_us:
         if len(config.get('DEFAULT', 'default_host_non-us')) != 0:
@@ -694,8 +711,13 @@ def main():
         print "Default Method: %s" % config.get('DEFAULT','method')
         print
         for section in config.sections():
-            print "%s => %s  (Upload method: %s)" % (section, \
-                config.get(section,'fqdn'), config.get(section,'method'))
+            distributions = ""
+            if config.get(section,'distributions'):
+                distributions = ", distributions: %s" % \
+                        config.get(section,'distributions')
+            print "%s => %s  (Upload method: %s%s)" % (section, \
+                config.get(section,'fqdn'), config.get(section,'method'), \
+                distributions)
         print
         sys.exit(0)
 
Index: dput-0.9.2.21/dput.cf.5
===================================================================
--- dput-0.9.2.21.orig/dput.cf.5        2006-05-09 16:11:12.000000000 -0500
+++ dput-0.9.2.21/dput.cf.5     2006-05-10 13:36:42.000000000 -0500
@@ -74,6 +74,10 @@ use the sha algorithm for calculation
 This defines if you are allowed to upload files without a GnuPG
 signature to this host or not.
 .TP
+.B distributions
+This defines a comma-separated list of distributions that this host accepts,
+used to guess the host to use when none is given on the command line.
+.TP
 .B run_lintian
 This option defines if lintian should be run before the package will 
 be uploaded or not. If the package is not lintian clean, the upload will

Attachment: signature.asc
Description: Digital signature

Reply via email to