On Thu, 2008-08-21 at 10:17 +0200, Didier Trosset wrote:
> In the middle of a python script, I am willing to get the revision number of
> the current directory. I have tried to get into the SWIG svn-python
> bindings, but they look so huge, I am having difficulties to know what to
> start with.
>
> I ended up writing the following that uses the command line:
>
> # Get revision from svn command line on repository
> revision = 0
> fileRev = popen("svn info .", "r")
> for line in fileRev:
> if 'Revision' in line:
> revision = match("Revision: (\d+)", line).group(1)
>
>
> It works and I am pretty happy with it. But could someone indicate me what
> would be the code to do the same thing using the python-subversion bindings.
>
> Didier
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_subversion.tigris.org
> For additional commands, e-mail: users-help_at_subversion.tigris.org
>
I wrote a little C program to do this if that will help. I probably
can arrange to put it on our web site if anybody wants it. It was
basically intended to be run from inside a make file in order to
generate an ASCII string with the version number that could be
passed to a compilation via a -D so the application being compiled
could then report the revision number to its users. But you can
run it from the command line, or, presumably, your python script.
I was concerned with the notion that in our group, we may copy a
working directory to another machine where people just want to
build the program but not make changes and not work with subversion.
So my program does this: First checks whether there is a .svn
subdirectory in the cwd. If yes, it thinks it is running in the
real working directory, so it then tries to run "svnversion".
If it gets an answer back, it returns this to the invoker via stdout.
It also writes this information to a hidden file with currently the
fixed name ".gnrsvvsn" (you could easily replace my initials with
yours). It is presumed that this file will get copied along
with the source code when the program is made available to others.
So now, when the program is run and it does not find the .svn subdir,
it thinks it is in a distributed copy. It looks for the file .gnrsvvsn
and if that is found, it writes its contents to stdout. If that file
is also not found, then it writes the string "Unknown" to stdout.
BTW, you could simplify you python script above by calling "svnversion"
instead of "svn info" and having to parse the reply.
George Reeke, Ph.D.
Head, Laboratory of Biological Modelling
The Rockefeller University
1230 York Avenue
New York, NY 10065
email: reeke_at_rockefeller.edu
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_subversion.tigris.org
For additional commands, e-mail: users-help_at_subversion.tigris.org
Received on 2008-08-21 17:45:24 CEST