I am paranoid about the obsoleting functionality, so add a -i (--interactive) flag for confirming. It should probably be used for other things too.
authorSteve Fink <sfink@mozilla.com>
Fri, 20 Jan 2012 11:34:52 -0800
changeset 57 677a987865e530fe5a6de1dd1a3988bffaa0b9fb
parent 56 d41339105650390517f114cacf5c4c8aaf5742dc
child 58 b54caaabd7eab36da0b5d2a91911b1476b105cbb
push id33
push usersfink@mozilla.com
push dateWed, 01 Feb 2012 20:22:14 +0000
I am paranoid about the obsoleting functionality, so add a -i (--interactive) flag for confirming. It should probably be used for other things too.
bzexport.py
--- a/bzexport.py
+++ b/bzexport.py
@@ -425,17 +425,17 @@ def get_default_version(ui, api_server, 
         raise util.Abort(_("Product %s has no versions") % product)
     if versions:
         return versions[-1]
 
 class PUTRequest(urllib2.Request):
     def get_method(self):
         return "PUT"
 
-def obsolete_old_patches(ui, api_server, token, bug, filename, ignore_id):
+def obsolete_old_patches(ui, api_server, token, bug, filename, ignore_id, interactive = False):
     url = api_server + "bug/%s/attachment?%s" % (bug, token.auth()) 
     req = urllib2.Request(url, None,
                           {"Accept": "application/json",
                            "Content-Type": "application/json"})
     conn = urlopen(ui, req)
     try:
         bug = json.load(conn)
     except Exception, e:
@@ -445,16 +445,19 @@ def obsolete_old_patches(ui, api_server,
     patches = [p for p in bug["attachments"] if p["is_patch"] and not p["is_obsolete"] and p["file_name"] == filename and int(p["id"]) != int(ignore_id)]
     if not len(patches):
         return True
 
     for p in patches:
         #TODO: "?last_change_time=" + p["last_change_time"] to avoid conflicts?
         url = api_server + "attachment/%s?%s" % (str(p["id"]), token.auth())
 
+        if interactive and ui.prompt(_("Obsolete patch %s (%s) - %s") % (url, p["file_name"], p["description"])) != 'y':
+          continue
+
         attachment_data = p
         attachment_data["is_obsolete"] = True
         attachment_json = json.dumps(attachment_data)
         req = PUTRequest(url, attachment_json,
                          {"Accept": "application/json",
                           "Content-Type": "application/json"})
         conn = urlopen(ui, req)
         try:
@@ -1028,17 +1031,17 @@ def bzexport(ui, repo, *args, **opts):
                                comment=values['ATTACHCOMMENT'],
                                reviewers=reviewers)
     result = json.load(attach)
     attachment_url = urlparse.urljoin(bugzilla,
                                       "attachment.cgi?id=" + result["id"] + "&action=edit")
     print "%s uploaded as %s" % (rev, attachment_url)
     result_id = result["id"]
 
-    if not result_id or not obsolete_old_patches(ui, api_server, auth, bug, filename, result_id):
+    if not result_id or not obsolete_old_patches(ui, api_server, auth, bug, filename, result_id, opts['interactive']):
         return
 
 def newbug(ui, repo, *args, **opts):
     """
     Create a new bug in bugzilla
 
     A menu will be displayed for the product and component unless a default has
     been set in the [bzexport] section of the config file (keys are 'product'
@@ -1088,16 +1091,18 @@ cmdtable = {
          [('d', 'description', '', 'Bugzilla attachment description'),
           ('c', 'comment', '', 'Comment to add with the attachment'),
           ('e', 'edit', False,
            'Open a text editor to modify bug fields'),
           ('r', 'review', '',
            'List of users to request review from (comma-separated search strings), or "auto" to parse the reviewers out of the patch comment'),
           ('', 'new', False,
            'Create a new bug'),
+          ('i', 'interactive', False,
+           'Interactive -- request confirmation before obsoleting patches'),
           ('', 'title', '',
            'New bug title'),
           ('', 'product', '',
            'New bug product'),
           ('C', 'component', '',
            'New bug component'),
           ('', 'prodversion', '',
            'New bug product version'),