Rev 22: Clean up 'release.py' a little bit for newer coding conventions in http://bzr.arbash-meinel.com/plugins/ezbzr-jam

John Arbash Meinel john at arbash-meinel.com
Mon Feb 12 20:49:45 GMT 2007


At http://bzr.arbash-meinel.com/plugins/ezbzr-jam

------------------------------------------------------------
revno: 22
revision-id: john at arbash-meinel.com-20070212204943-mjjntx4227n2tkbo
parent: john at arbash-meinel.com-20070212204249-yk9418a2pntj6yoj
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: ezbzr
timestamp: Mon 2007-02-12 14:49:43 -0600
message:
  Clean up 'release.py' a little bit for newer coding conventions
modified:
  release.py                     release.py-20060116232304-34bf27069b463966
-------------- next part --------------
=== modified file 'release.py'
--- a/release.py	2006-04-07 16:33:35 +0000
+++ b/release.py	2007-02-12 20:49:43 +0000
@@ -23,59 +23,73 @@
 import sre
 import urlparse
 
-import bzrlib
-
-class ConflictsExist(bzrlib.errors.BzrNewError):
-    """A conflict has been detected.  Please do the following:
+from bzrlib import (
+    branch as _mod_branch,
+    builtins,
+    commands,
+    errors,
+    osutils,
+    )
+
+
+class ConflictsExist(errors.BzrError):
+
+    _fmt = """A conflict has been detected.  Please do the following:
         1. Change into directory '%(branch)s'
         2. Resolve the conflicts
         3. Commit those changes (ie. 'bzr commit -m "<commit_message>"')
         4. Push those changes back to the branch (just do 'bzr push')
         5. You may remove '%(tmpdir)s' when you are done"""
 
-class cmd_release(bzrlib.commands.Command):
+    def __init__(self, branch, tmpdir):
+        errors.BzrError.__init__(self)
+        self.branch = branch
+        self.tmpdir = tmpdir
+
+
+class cmd_release(commands.Command):
     """'Releases' the current branch to a remote branch.
-    
+
     This is acomplished by branching a (temporary) local copy of the remote branch,
-    merging this branch into the local copy of the remote branch and then pushing 
+    merging this branch into the local copy of the remote branch and then pushing
     the local copy to the remote location.  Also works with local branches.
-    
+
     The syntax is one of the following:
         1. bzr release <remote_uri> ...
         2. bzr release <release_nickname> ...
-        
-    Release nicknames are stored in the '.bzrrelease' file in your working tree. 
-    This file allows you to use nicknames that resolve to URIs. The syntax for 
+
+    Release nicknames are stored in the '.bzrrelease' file in your working tree.
+    This file allows you to use nicknames that resolve to URIs. The syntax for
     this file is:
         "nickname|URI"
     """
     takes_args = ['nick_or_uri*']
-    takes_options = ['root', 'message', 'revision', bzrlib.commands.Option('yes',
+    takes_options = ['root', 'message', 'revision', commands.Option('yes',
                       help="Assume yes to all prompts (dangerous!)")]
 
-    @bzrlib.commands.display_command
+    @commands.display_command
     def run(self, root=None, message=None, revision=None, yes=False, nick_or_uri_list=[]):
-        
+
         # Open branch
         if root == None:
             root = "."
-        branch = bzrlib.branch.Branch.open_containing(root)[0]
-        
+        branch = _mod_branch.Branch.open_containing(root)[0]
+
         # Load in our nicks file
         nicks = {}
         try:
-            release_file = open(bzrlib.osutils.joinpath([branch.base, ".bzrrelease"]))
+            release_file = open(osutils.joinpath([branch.base, ".bzrrelease"]))
             for line in release_file:
                 nick, uri = line.strip().split("|", 1)
                 nicks[nick] = uri
             release_file.close()
         except IOError:
             pass
-        
-        # Do the release    
-        curdir = bzrlib.osutils.getcwd()
+
+        # Do the release
+        curdir = osutils.getcwd()
         for destination in nick_or_uri_list:
-            
+
             # Get the remote URI
             uri = nicks.get(destination, destination)
             split = urlparse.urlparse(uri)[2].split("/")
@@ -83,54 +97,54 @@
                 localnick = split.pop()
                 if localnick != "":
                     break
-                
+
             try:
                 # Get the absolute path of the branch
-                dest_branch = bzrlib.branch.Branch.open(uri)
+                dest_branch = _mod_branch.Branch.open(uri)
                 uri = dest_branch.base
-                
+
                 # Create a temp dir
-                tmpdir = bzrlib.osutils.mkdtemp()
-                localcache = bzrlib.osutils.pathjoin(tmpdir, localnick)
-                
+                tmpdir = osutils.mkdtemp()
+                localcache = osutils.pathjoin(tmpdir, localnick)
+
                 # Create a local copy of the remote branch
                 print " * Creating temporary branch from %s..." % uri
-                bzrlib.builtins.cmd_branch().run(from_location=branch.base, to_location=localcache)
+                builtins.cmd_branch().run(from_location=branch.base, to_location=localcache)
                 os.chdir(localcache)
-                bzrlib.builtins.cmd_pull().run(location=uri, overwrite=True)
-
-                
+                builtins.cmd_pull().run(location=uri, overwrite=True)
+
+
                 # Set the push variable for when we push back the changes
                 # We save this in case of a conflict error, that way, the user
                 # never needs to know the actual url and can just type 'bzr push'
-                localbranch = bzrlib.branch.Branch.open_containing(u'.')[0]
+                localbranch = _mod_branch.Branch.open_containing(u'.')[0]
                 localbranch.set_push_location(uri)
-                
+
                 # Merge my changes into the local copy of the remote branch
                 print " * Merging in changes from %s..." % branch.base
-                bzrlib.builtins.cmd_merge().run(branch=branch.base, revision=revision)
-                
+                builtins.cmd_merge().run(branch=branch.base, revision=revision)
+
                 # Check for conflicts
                 for conflict in localbranch.working_tree().iter_conflicts():
-                    raise ConflictsExist(branch=bzrlib.osutils.joinpath([tmpdir, localnick]), 
+                    raise ConflictsExist(branch=osutils.joinpath([tmpdir, localnick]),
                                 tmpdir=tmpdir)
-                
-		if not yes:
-	                # Show the user the results of the merge
-	                print " * Displaying changes..."
-			os.system("bzr diffstatus")
-                
-	                # Prompt to continue
-	                val = raw_input(" * Okay to commit [y/N]? ")
+
+                if not yes:
+                        # Show the user the results of the merge
+                        print " * Displaying changes..."
+                        os.system("bzr diffstatus")
+
+                        # Prompt to continue
+                        val = raw_input(" * Okay to commit [y/N]? ")
 
                 if yes or val.lower() in ("y", "yes"):
                     print " * Committing changes..."
-                    
+
                     # Commit the merged changes
-                    bzrlib.builtins.cmd_commit().run(message=message, verbose=False)
-                
+                    builtins.cmd_commit().run(message=message, verbose=False)
+
                     # Push back the changes from our local copy
-                    bzrlib.builtins.cmd_push().run()
+                    builtins.cmd_push().run()
                 else:
                     print " * Abandoning changes!"
 
@@ -144,11 +158,11 @@
                 os.chdir(curdir)
                 shutil.rmtree(tmpdir)
                 raise
-                
+
             # Clean up
             print " * Cleaning up..."
             os.chdir(curdir)
             shutil.rmtree(tmpdir)
 
-bzrlib.commands.register_command(cmd_release)
+commands.register_command(cmd_release)
 



More information about the bazaar-commits mailing list