Rev 40: Add cia-submit --pending to submit pending CIA requests. in http://people.samba.org/bzr/jelmer/bzr-cia/trunk

Jelmer Vernooij jelmer at samba.org
Fri Oct 10 14:51:30 BST 2008


At http://people.samba.org/bzr/jelmer/bzr-cia/trunk

------------------------------------------------------------
revno: 40
revision-id: jelmer at samba.org-20081010135130-f2ohde85kro5urvl
parent: jelmer at samba.org-20081010133626-k3nimyhbvor23k7t
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: trunk
timestamp: Fri 2008-10-10 15:51:30 +0200
message:
  Add cia-submit --pending to submit pending CIA requests.
=== modified file '__init__.py'
--- a/__init__.py	2008-10-10 13:36:26 +0000
+++ b/__init__.py	2008-10-10 13:51:30 +0000
@@ -96,10 +96,15 @@
         saxutils.escape(revision.message))
 
 
+def cia_cache_dir():
+    from bzrlib.config import config_dir
+    import os
+    return os.path.join(config_dir(), "cia")
+
+
 def store_failed_message(revid, message):
-    from bzrlib.config import config_dir
     import os
-    cache_dir = os.path.join(config_dir(), "cia")
+    cache_dir = cia_cache_dir()
     if not os.path.isdir(cache_dir):
         os.mkdir(cache_dir)
     cache_file = os.path.join(cache_dir, revid)
@@ -108,6 +113,14 @@
     f.close()
 
 
+def cia_connect(config):
+    server = config.get_user_option('cia_server')
+    if server is None:
+        server = "http://cia.navi.cx"
+
+    return xmlrpclib.ServerProxy(server)
+
+
 def cia_submit(branch, revid, revno, dry_run=False):
     config = branch.get_config()
 
@@ -115,10 +128,6 @@
     if project is None:
         return
 
-    server = config.get_user_option('cia_server')
-    if server is None:
-        server = "http://cia.navi.cx"
-
     author = config.get_user_option('cia_user')
     quiet = config.get_user_option('cia_quiet')
 
@@ -135,7 +144,7 @@
     if not dry_run:
         error = None
         try:
-            xmlrpclib.ServerProxy(server).hub.deliver(msg)
+            cia_connect(config).hub.deliver(msg)
         except xmlrpclib.ProtocolError, e:
             error = e.errmsg
         except socket.gaierror, (_, errmsg):
@@ -172,34 +181,49 @@
     """
     takes_args = ['branch?']
     takes_options = ['revision', 
+        Option('pending', 
+            help="Submit all pending CIA submissions."),
         Option('dry-run', 
             help="Show what would be done, but don't actually do anything.")]
 
-    def run(self, branch='.', revision=None,dry_run=False):
-        br = Branch.open(branch)
-
-        if revision is None:
-            revs = [br.last_revision()]
-        elif len(revision) == 1:
-            revs = [revision[0].in_history(br).rev_id]
-        elif len(revision) == 2:
-            if revision[0].spec is None:
-                from_revno = 1
-            else:
-                from_revno = revision[0].in_history(br).revno
-
-            if revision[1].spec is None:
-                to_revno = br.revno()
-            else:
-                to_revno = revision[1].in_history(br).revno
-            revs = br.revision_history()[from_revno:to_revno]
+    def run(self, branch=None, revision=None, dry_run=False, pending=False):
+        if pending and (branch is not None or revision is not None):
+            raise BzrCommandError("--pending and specifying a branch are mutually exclusive")
+        if pending:
+            from bzrlib.config import GlobalConfig
+            import os
+            server = cia_connect(GlobalConfig())
+            cache_dir = cia_cache_dir()
+            for revid in os.listdir(cache_dir):
+                path = os.path.join(cache_dir, revid)
+                msg = open(path, 'r').read()
+                server.hub.deliver(msg)
+                os.path.remove(path)
         else:
-            raise BzrCommandError('bzr submit-cia --revision takes one or two arguments')
-
-        for rev_id in revs:
-            cia_submit(br, rev_id, br.revision_id_to_revno(rev_id), dry_run)
-        
-        return 0
+            if branch is not None:
+                branch = "."
+            br = Branch.open(branch)
+
+            if revision is None:
+                revs = [br.last_revision()]
+            elif len(revision) == 1:
+                revs = [revision[0].in_history(br).rev_id]
+            elif len(revision) == 2:
+                if revision[0].spec is None:
+                    from_revno = 1
+                else:
+                    from_revno = revision[0].in_history(br).revno
+
+                if revision[1].spec is None:
+                    to_revno = br.revno()
+                else:
+                    to_revno = revision[1].in_history(br).revno
+                revs = br.revision_history()[from_revno:to_revno]
+            else:
+                raise BzrCommandError('bzr submit-cia --revision takes one or two arguments')
+
+            for rev_id in revs:
+                cia_submit(br, rev_id, br.revision_id_to_revno(rev_id), dry_run)
 
 
 register_command(cmd_cia_project)




More information about the bazaar-commits mailing list