post_commit hook write a file?
Alexander Belchenko
bialix at ukr.net
Sat May 21 08:58:32 UTC 2011
Chris Hecker пишет:
>
> Hi, I've never tried to write a plugin before, and my python skills are
> at the barely-literate level, so I'm wondering if someone who knows the
> bzr api inside and out can tell me if I'm doing this right.
>
> I'm trying to write a post_commit hook that will put the new revno in a
> file at the root of the branch, if that file already exists. Here's
> what I have so far, does this look right? It seems to work.
>
> This is to update a version resource in an executable. Visual Studio is
> totally broken in the way it handles build events and custom build
> steps, so I can't use bzr revno or version-info because I need a file
> that changes on every commit, sadly.
>
> Thanks,
> Chris
>
>
> revno_commit_file.py:
>
> import bzrlib.branch
>
> def post_commit_hook(local, master, old_revno, old_revid, new_revno,
> new_revid):
> import bzrlib.urlutils
> import os.path
> p = bzrlib.urlutils.local_path_from_url(master.base) + 'revno'
> if os.path.isfile(p):
> f = open(p,'w')
> f.write(str(new_revno))
> f.close()
>
Well, actually you should check that local branch is None, otherwise you
have bound branch situation and master will point to possible remote branch.
So, you may improve your plugin as following:
def post_commit_hook(local, master, old_revno, old_revid, new_revno,
new_revid):
import os
from bzrlib import urlutils
if local:
br = local
else:
br = master
base = urlutils.local_path_from_url(br.base)
p = os.path.join(base, 'revno')
if os.path.isfile(p):
f = open(p,'w')
f.write(str(new_revno))
f.close()
More information about the bazaar
mailing list