Got commit basics working for bzr
authorAaron Bentley <abentley@panoramicfeedback.com>
Fri, 3 Feb 2006 20:17:59 +0000 (15:17 -0500)
committerAaron Bentley <abentley@panoramicfeedback.com>
Fri, 3 Feb 2006 20:17:59 +0000 (15:17 -0500)
beweb/beweb/controllers.py
libbe/bzr.py
libbe/rcs.py

index cbd0816bfc006c8dd8903b64d757f6466bba51b3..912411672a0da0920d766695ca90fe2b10ca0411 100644 (file)
@@ -93,6 +93,9 @@ class Bug(PrestHandler):
             assigned = None
         bug.assigned = assigned
         bug.save()
+        bug.rcs.precommit(bug.path)
+        bug.rcs.commit(bug.path, "Auto-commit")
+        bug.rcs.postcommit(bug.path)
         raise cherrypy.HTTPRedirect(bug_list_url(bug_data["project"]))
 
     def instantiate(self, project, bug):
index 80b9e9bb37cfb5243e7e8949df9ea2a9a812aeed..ac1a8c44a960ea9e5882325a1ccb7ec1d1f8de37 100644 (file)
 #    You should have received a copy of the GNU General Public License
 #    along with this program; if not, write to the Free Software
 #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-from subprocess import Popen, PIPE
 import os
-import config
-
-def invoke(args):
-    q = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
-    output = q.stdout.read()
-    error = q.stderr.read()
-    status = q.wait()
-    if status >= 0:
-        return status, output, error
-    raise Exception("Command failed: %s" % error)
+import tempfile
 
+import config
+from rcs import invoke, CommandError
 
 def invoke_client(*args, **kwargs):
+    directory = kwargs.get('directory')
+    expect = kwargs.get('expect', (0, 1))
     cl_args = ["bzr"]
     cl_args.extend(args)
-    status,output,error = invoke(cl_args)
-    if status not in (0,):
-        raise Exception("Command failed: %s" % error)
-    return output
+    if directory:
+        old_dir = os.getcwd()
+        os.chdir(directory)
+    try:
+        status,output,error = invoke(cl_args, expect)
+    finally:
+        if directory:
+            os.chdir(old_dir)
+    return status, output
 
 def add_id(filename, paranoid=False):
     invoke_client("add", filename)
@@ -101,5 +100,25 @@ def detect(path):
         old_path = path
         path = os.path.dirname(path)
 
+def precommit(directory):
+    pass
 
+def commit(directory, summary, body=None):
+    if body is not None:
+        summary += '\n' + body
+    descriptor, filename = tempfile.mkstemp()
+    try:
+        temp_file = os.fdopen(descriptor, 'wb')
+        temp_file.write(summary)
+        temp_file.close()
+        try:
+            invoke_client('commit', '--unchanged', '--file', filename, 
+                          directory=directory)
+        except:
+            raise invoke_client('status', directory=directory)[1]
+    finally:
+        os.unlink(filename)
+
+def postcommit(directory):
+    pass
 name = "bzr"
index c0966f82f04619215431fcf2631cf8f62e906e47..ac9673457cc647ea5377a2935a89b1fe193ebaad 100644 (file)
@@ -14,6 +14,7 @@
 #    You should have received a copy of the GNU General Public License
 #    along with this program; if not, write to the Free Software
 #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+from subprocess import Popen, PIPE
 def rcs_by_name(rcs_name):
     """Return the module for the RCS with the given name"""
     if rcs_name == "Arch":
@@ -36,3 +37,18 @@ def detect(dir):
         return bzr
     import no_rcs
     return no_rcs
+
+class CommandError(Exception):
+    def __init__(self, err_str, status):
+        Exception.__init__(self, "Command failed (%d): %s" % (status, err_str))
+        self.err_str = err_str
+        self.status = status
+
+def invoke(args, expect=(0,)):
+    q = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
+    output = q.stdout.read()
+    error = q.stderr.read()
+    status = q.wait()
+    if status not in expect:
+        raise CommandError(error, status)
+    return status, output, error