Allow ranges to be used when selecting multiple patches (eg "1-3,6-12")
authorSteve Fink <sfink@mozilla.com>
Tue, 24 Jan 2012 09:02:26 -0800
changeset 68 6237bc0a91fa
parent 67 f302ad097f33
child 69 d2f36f9b40d9
push id49
push usersfink@mozilla.com
push dateTue, 24 Jan 2012 17:03:39 +0000
Allow ranges to be used when selecting multiple patches (eg "1-3,6-12")
bzhandler.py
--- a/bzhandler.py
+++ b/bzhandler.py
@@ -1,15 +1,16 @@
 # std python modules
 import urllib2
 try:
   import cStringIO as StringIO
 except ImportError:
   import StringIO
 import os
+import re
 
 # qimportbz modules
 import bz
 
 # Patch list
 delayed_imports = []
 
 # (Patch * path) list
@@ -87,31 +88,33 @@ class Handler(urllib2.BaseHandler):
         else:
           if 'y' != self.ui.prompt("Only found one patch and it is obsolete. Import anyways? [Default is 'y']", default='y'):
             return
       if len(patches) == 1:
         patch = patches[0]
       elif len(patches) > 0:
         for i, p in enumerate(patches):
           flags = p.joinFlags(False)
-          self.ui.write("%s: %s%s\n" % (i + 1, p.desc, "\n%s" % flags if flags else ""))
+          self.ui.write("%s: %s%s\n" % (i + 1, p.desc, "\n  %s" % flags if flags else ""))
         choicestr = ' '.join([str(n) for n in xrange(1,len(patches)+1)])
-        choicestr = choicestr if self.autoChoose else self.ui.prompt("Which patches do you want to import? [Default is '1']", default="1")
+        choicestr = choicestr if self.autoChoose else self.ui.prompt("Which patches do you want to import? [Default is '1', use '1-%d' for all]" % len(patches), default="1")
         for choice in (s.strip() for t in choicestr.split(',') for s in t.split()):
           try:
-            if int(choice) <= 0:
-              raise IndexError()
-            p = patches[int(choice) - 1]
+            m = re.match(r'(\d+)-(\d+)$', choice)
+            if m:
+              delayed_imports.extend([ patches[p] for p in xrange(int(m.group(1)) - 1, int(m.group(2))) ])
+            else:
+              if int(choice) <= 0:
+                raise IndexError()
+              delayed_imports.append(patches[int(choice) - 1])
           except (ValueError, IndexError):
             self.ui.warn("Invalid patch number = '%s'\n" % choice)
             continue
-          if not patch:
-            patch = p
-          else:
-            delayed_imports.append(p)
+        if not patch and len(delayed_imports) > 0:
+          patch = delayed_imports.pop(0)
 
     # and finally return the response
     if patch:
       imported_patches.append((patch, req.get_full_url()))
       return PatchResponse(patch)
 
 # interface reverse engineered from urllib.addbase
 class PatchResponse(object):