Create or set a working tree uptodate using bzrlib!

Luís Soares los at di.uminho.pt
Sat Jun 23 17:16:47 BST 2007


Hello all,

  I am a newbie, when it comes to have things done through bzrlib  
directly, rather than the command line... This is the first time I am  
using bzrlib.

I have the following situation: I have this program that needs to  
check if there is a branch in a certain filesystem url. If the branch  
does not exist, it will clone a remote branch. If it does exist, than  
it will only pull/update the local copy.

Going through bzrlib, I combined snippets of code and came up with  
the following:

from bzrlib.builtins  import cmd_branch, cmd_pull
from bzrlib.workingtree import WorkingTree
from bzrlib.errors import NotBranchError
from bzrlib.tests import StringIOWrapper

def do_workingtree_refresh(remote, local):
	is_pull_needed = False
	
	res = StringIOWrapper()
	
	try:
		tree, relpath = WorkingTree.open_containing(local)
		is_pull_needed = True
	except NotBranchError:
		cmd=cmd_branch()
		cmd.outf = res
		cmd.run(from_location=remote, to_location=local)
		
	if is_pull_needed:
		cmd=cmd_pull()
		cmd.outf = res
		cmd.run(directory=local)
		
	return res.getvalue()


Is this the best way to do it?

los

---
Luís Soares
* los at di.uminho.pt * http://gsd.di.uminho.pt/members/los *
* gpg: C55B F036 E664 AFD3 40C8 7322 1978 6C65 E678 C223 *



-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.ubuntu.com/archives/bazaar/attachments/20070623/bf64f874/attachment.htm 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: This is a digitally signed message part
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20070623/bf64f874/attachment.pgp 


More information about the bazaar mailing list