Using Bazaar programatically
Gertjan Klein
gklein at xs4all.nl
Fri Feb 8 11:44:43 GMT 2008
Hi,
I am trying to write a programmatic interface to bazaar from a database
application, where the items to bring under version control are not in
the filesystem. There is a default source control menu in this
application, which I find difficult to translate to bazaar terminology.
I am seeking assistance for this translation.
The source control menu consists of:
- AddToSourceControl: adds a new item to source control
- CheckOut: work on this item, locking it for others
- UndoCheckout: cancel working on item and restore previous version
- CheckIn: store new version in source control and unlock
- GetLatest: get possibly newer version (checked in by others)
Is it possible to make bazaar operate in this way? (For testing my code,
I currently ignore how to let others work on the code base, i.e., for
now it is just me using this.)
I have written a small program with an attempt to add an item to source
control and commit it, and it gives me an exception. I created a
versioned directory "c:\dev\bzr\cache" and initialized it from the
command line with "bzr init". I manually copied a text file to this
directory, and ran the following program:
from bzrlib import workingtree
def test():
dir = r'C:\dev\bzr\cache'
file = r'C:\dev\bzr\cache\test.txt'
files = [file]
message = "Test commit"
wtree = workingtree.WorkingTree.open(dir)
wtree.smart_add(files)
wtree.commit(message, specific_files=files)
if __name__ == '__main__':
test()
This gives me an exception:
>Traceback (most recent call last):
> File "C:\Temp\commit_test.py", line 13, in <module>
> test()
> File "C:\Temp\commit_test.py", line 10, in test
> wtree.commit(message, specific_files=files)
> File "<string>", line 4, in commit_write_locked
> File "C:\dev\Python\Python25\Lib\site-packages\bzrlib\workingtree_4.py", line 246, in commit
> result = WorkingTree3.commit(self, message, revprops, *args, **kwargs)
> File "<string>", line 4, in commit_write_locked
> File "C:\dev\Python\Python25\Lib\site-packages\bzrlib\mutabletree.py", line 187, in commit
> revprops=revprops, *args, **kwargs)
> File "C:\dev\Python\Python25\Lib\site-packages\bzrlib\commit.py", line 315, in commit
> specific_files, [self.basis_tree, self.work_tree])
> File "C:\dev\Python\Python25\Lib\site-packages\bzrlib\tree.py", line 596, in find_ids_across_trees
> require_versioned)
> File "C:\dev\Python\Python25\Lib\site-packages\bzrlib\tree.py", line 623, in _find_ids_across_trees
> raise errors.PathsNotVersionedError(not_versioned)
>bzrlib.errors.PathsNotVersionedError: Path(s) are not versioned: C:\dev\bzr\cache\test.txt
Oddly, smart_add() seems to accept the file, but commit doesn't. Any
ideas?
Versions:
ActivePython 2.5.1.1 (ActiveState Software Inc.) based on
Python 2.5.1 (r251:54863, May 1 2007, 17:47:05) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import bzrlib
>>> bzrlib.__version__
'1.1.0'
Working on Windows XP Pro SP2.
Thanks,
Gertjan.
--
Gertjan Klein <gklein at xs4all.nl>
More information about the bazaar
mailing list