You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@subversion.apache.org by Rishabh Manocha <rm...@gmail.com> on 2008/03/24 14:27:42 UTC

Python SWIG bindings help

Hello All,

I'm not sure if this question has been answered before (I could not
find anything in the mailing list archives) so please excuse me if it
has.

I was starting some work on my local SVN repository - trying to access
it via Python, similar to what ViewVC or Trac do. I followed the intro
to the API at http://jtauber.com/python_subversion_binding/ but am now
stuck at trying to figure out a way to get the directory listing for
the ROOT. All I want to know is how to get a full listing of folders
or files under a given path (for example, if my repository resides
under /opt/svn/repos, I want python to return me a list of items under
that folder). This might be trivial to do, but I have been unable to
figure it out for the past couple of days. Some help would be greatly
appreciated.

Best,

R

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

Re: Python SWIG bindings help

Posted by Hari Kodungallur <hk...@gmail.com>.
On Thu, Mar 27, 2008 at 12:25 AM, Rishabh Manocha <rm...@gmail.com>
wrote:

> Hari,
>
> Thanks a lot. That does just what I wanted it to do. I had also, in
> the meantime figured out how to do something similar using pysvn -
>
> import pysvn
> path = svn+ssh://rmanocha@myhost/opt/svn/repos
> client = pysvn.Client()
> entries = client.ls(path)
>
> I will look into both these methods in some more detail and see which
> one I would rather use. Do you have any suggestions?? One problem I
> did have with using pysvn was that I have to login using my password
> everytime using the above code (even though I defined a login callback
> function and assigned it as per the documentation on pysvn's site).



If you can get the info that you need from the client (like your example
above), I would definitely suggest using pysvn because its interfaces and
documentation are in much cleaner shape. [I have not used pysvn, even though
I have wanted to. But from the docs and form what I have read, it is much
easier to use than the bindings]



>
>
> Also, is there any source of documentation/tutorials for the python
> svn SWIG bindings (I don't mind reading c header files too if someone
> can just show me how to :)).



I have not found a good documentation resource for the SWIG bindings. You
could obviously read the C header files within the source distribution. But
it is quite complicated. Moreover, I learn faster using examples and so I
started off by looking at the two short examples in the book (
http://svnbook.red-bean.com/en/1.1/ch08s02.html) and also the
svnlook.pyfile in the distribution (in the tools/examples folder).

The subversion/bindings/swig/python/test folder also includes code from the
trac project. The code within it is a good primer on how to use the
bindings.

These examples do not replace documentation, but if you just want to
experiment with the usage of python bindings, these resources will help you
a lot.


<snip>

Re: Python SWIG bindings help

Posted by Rishabh Manocha <rm...@gmail.com>.
Hari,

Thanks a lot. That does just what I wanted it to do. I had also, in
the meantime figured out how to do something similar using pysvn -

import pysvn
path = svn+ssh://rmanocha@myhost/opt/svn/repos
client = pysvn.Client()
entries = client.ls(path)

I will look into both these methods in some more detail and see which
one I would rather use. Do you have any suggestions?? One problem I
did have with using pysvn was that I have to login using my password
everytime using the above code (even though I defined a login callback
function and assigned it as per the documentation on pysvn's site).

Also, is there any source of documentation/tutorials for the python
svn SWIG bindings (I don't mind reading c header files too if someone
can just show me how to :)).

Best,

R


On Thu, Mar 27, 2008 at 12:39 AM, Hari Kodungallur
<hk...@gmail.com> wrote:
>
>
> On Wed, Mar 26, 2008 at 2:07 AM, Rishabh Manocha <rm...@gmail.com> wrote:
> > Any suggestions here - I'm still unable to wrap my head around this
> problem.
> >
> > R
> >
> >
> >
> >
> > On Tue, Mar 25, 2008 at 11:19 AM, Rishabh Manocha <rm...@gmail.com>
> wrote:
> > > Paul,
> > >
> > >  I did take a look at pysvn and from what I gathered, it was more of a
> > >  client side library. I want to work directly with the server/local
> > >  repository (again, something like viewcv or trac) instead of having to
> > >  checkout a version of the repository before being able to work with
> > >  it. Am I getting pysvn wrong here??
> > >
> > >  Thanks,
> > >
> > >  R
> > >
> > >
> > >
> > >  On Mon, Mar 24, 2008 at 9:56 PM, Paul Koning <Pa...@dell.com>
> wrote:
> > >  > >>>>> "Rishabh" == Rishabh Manocha <rm...@gmail.com> writes:
> > >  >
> > >  >   Rishabh> Hello All, I'm not sure if this question has been answered
> > >  >   Rishabh> before (I could not find anything in the mailing list
> > >  >   Rishabh> archives) so please excuse me if it has.
> > >  >
> > >  >   Rishabh> I was starting some work on my local SVN repository -
> trying
> > >  >   Rishabh> to access it via Python, similar to what ViewVC or Trac
> > >  >   Rishabh> do. ...
> >
>
>
> Here's a very very basic code that you can start with:
>
>
> from svn import fs, core, repos
>
> mypool  = core.svn_pool_create(None)
> myrepo  = repos.open("/opt/svn/repos")
>  myfs    = repos.fs(myrepo)
> myyoung = fs.youngest_rev(myfs, None)
>  myroot  = fs.revision_root(myfs, myyoung, None)
>
> def entries(path):
>      listing = fs.dir_entries(myroot, path, mypool).values()
>     return [ x.name for x in listing ]
>
> print entries("")
> print entries("trunk")
>  # etc..
>
>
>
> Hope this helps.
>
> regards,
> -Hari
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

Re: Python SWIG bindings help

Posted by Hari Kodungallur <hk...@gmail.com>.
On Wed, Mar 26, 2008 at 2:07 AM, Rishabh Manocha <rm...@gmail.com> wrote:

> Any suggestions here - I'm still unable to wrap my head around this
> problem.
>
> R
>
> On Tue, Mar 25, 2008 at 11:19 AM, Rishabh Manocha <rm...@gmail.com>
> wrote:
> > Paul,
> >
> >  I did take a look at pysvn and from what I gathered, it was more of a
> >  client side library. I want to work directly with the server/local
> >  repository (again, something like viewcv or trac) instead of having to
> >  checkout a version of the repository before being able to work with
> >  it. Am I getting pysvn wrong here??
> >
> >  Thanks,
> >
> >  R
> >
> >
> >
> >  On Mon, Mar 24, 2008 at 9:56 PM, Paul Koning <Pa...@dell.com>
> wrote:
> >  > >>>>> "Rishabh" == Rishabh Manocha <rm...@gmail.com> writes:
> >  >
> >  >   Rishabh> Hello All, I'm not sure if this question has been answered
> >  >   Rishabh> before (I could not find anything in the mailing list
> >  >   Rishabh> archives) so please excuse me if it has.
> >  >
> >  >   Rishabh> I was starting some work on my local SVN repository -
> trying
> >  >   Rishabh> to access it via Python, similar to what ViewVC or Trac
> >  >   Rishabh> do. ...
>


Here's a very very basic code that you can start with:


from svn import fs, core, repos

mypool  = core.svn_pool_create(None)
myrepo  = repos.open("/opt/svn/repos")
myfs    = repos.fs(myrepo)
myyoung = fs.youngest_rev(myfs, None)
myroot  = fs.revision_root(myfs, myyoung, None)

def entries(path):
    listing = fs.dir_entries(myroot, path, mypool).values()
    return [ x.name for x in listing ]

print entries("")
print entries("trunk")
# etc..



Hope this helps.

regards,
-Hari

Re: Python SWIG bindings help

Posted by Rishabh Manocha <rm...@gmail.com>.
Any suggestions here - I'm still unable to wrap my head around this problem.

R

On Tue, Mar 25, 2008 at 11:19 AM, Rishabh Manocha <rm...@gmail.com> wrote:
> Paul,
>
>  I did take a look at pysvn and from what I gathered, it was more of a
>  client side library. I want to work directly with the server/local
>  repository (again, something like viewcv or trac) instead of having to
>  checkout a version of the repository before being able to work with
>  it. Am I getting pysvn wrong here??
>
>  Thanks,
>
>  R
>
>
>
>  On Mon, Mar 24, 2008 at 9:56 PM, Paul Koning <Pa...@dell.com> wrote:
>  > >>>>> "Rishabh" == Rishabh Manocha <rm...@gmail.com> writes:
>  >
>  >   Rishabh> Hello All, I'm not sure if this question has been answered
>  >   Rishabh> before (I could not find anything in the mailing list
>  >   Rishabh> archives) so please excuse me if it has.
>  >
>  >   Rishabh> I was starting some work on my local SVN repository - trying
>  >   Rishabh> to access it via Python, similar to what ViewVC or Trac
>  >   Rishabh> do. ...
>  >
>  >  For what it's worth: you might take a look at pysvn.  I've used both,
>  >  and found pysvn easier to work with.
>  >
>  >     paul
>  >
>  >
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

Re: Python SWIG bindings help

Posted by Rishabh Manocha <rm...@gmail.com>.
Paul,

I did take a look at pysvn and from what I gathered, it was more of a
client side library. I want to work directly with the server/local
repository (again, something like viewcv or trac) instead of having to
checkout a version of the repository before being able to work with
it. Am I getting pysvn wrong here??

Thanks,

R

On Mon, Mar 24, 2008 at 9:56 PM, Paul Koning <Pa...@dell.com> wrote:
> >>>>> "Rishabh" == Rishabh Manocha <rm...@gmail.com> writes:
>
>   Rishabh> Hello All, I'm not sure if this question has been answered
>   Rishabh> before (I could not find anything in the mailing list
>   Rishabh> archives) so please excuse me if it has.
>
>   Rishabh> I was starting some work on my local SVN repository - trying
>   Rishabh> to access it via Python, similar to what ViewVC or Trac
>   Rishabh> do. ...
>
>  For what it's worth: you might take a look at pysvn.  I've used both,
>  and found pysvn easier to work with.
>
>     paul
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

Re: Python SWIG bindings help

Posted by Paul Koning <Pa...@dell.com>.
>>>>> "Rishabh" == Rishabh Manocha <rm...@gmail.com> writes:

 Rishabh> Hello All, I'm not sure if this question has been answered
 Rishabh> before (I could not find anything in the mailing list
 Rishabh> archives) so please excuse me if it has.

 Rishabh> I was starting some work on my local SVN repository - trying
 Rishabh> to access it via Python, similar to what ViewVC or Trac
 Rishabh> do. ...

For what it's worth: you might take a look at pysvn.  I've used both,
and found pysvn easier to work with.

    paul


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org