You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@subversion.apache.org by Tino Schwarze <su...@tisc.de> on 2010/03/25 14:17:42 UTC
Question regarding the python binding
Hi there,
I'm currently implementing commit hooks and struggling with the python
bindings. I took the contributed pre-commit example which uses the "svn"
python module which maps more or less directly to libsvn functions.
Background: We want to enforce certain global ignores, MIME types etc.
The most coherent way should be to just read our default .svn/config
file and verify against it's settings. BTW: Has anybody done something
similar already?
Back to python: I managed to use the Python bindings to get a value from
the config file (I didn't want to reinvent the wheel) like this:
***
from svn import repos, fs, delta, core, client
def main(pool, repos_dir):
# for now, store client configuration in repository root
cfgfile = repos_dir+'/conf/client.conf'
svncfg = core.svn_config_read (cfgfile, True, pool)
global_ignores = core.svn_config_get (svncfg, core.SVN_CONFIG_SECTION_GLOBAL, core.SVN_CONFIG_OPTION_GLOBAL_IGNORES, None)
***
Now I'd like to verify our default set of required MIME types, so I need
to get the contents of the [auto-props] section from the config file.
libsvn provides the following function which should be suitable for my
needs:
svn_config_enumerate2(svn_config_t cfg, char section,
svn_config_enumerator2_t callback, void baton, apr_pool_t pool) -> int
Two questions arise:
1. How do I define an appropiate callback in Python? Looking at the SWIG
documentation, I see examples on how to implement Python callbacks but
they don't seem to match the current SVN bindings. I tried passing a
Python method, deriving from svn_config_enumerator2_t etc. -> Segfault.
2. What's the baton good for? Is it just some kind of additional data, I
don't need to care about?
Maybe the devel list is more appropiate for such questions, but I wanted
to try here first.
Thanks,
Tino.
--
"What we nourish flourishes." - "Was wir nähren erblüht."
www.lichtkreis-chemnitz.de
www.tisc.de
Re: Question regarding the python binding
Posted by Роман Донченко <DX...@yandex.ru>.
Tino Schwarze <su...@tisc.de> писал в своём письме Thu, 25 Mar
2010 17:32:35 +0300:
> Additional question: I can't seem to find an equivalent of "svnlook cat"
> anywhere... I wanted to avoid calling external programs - commits are
> slow enough already...
>
> Thanks,
>
> Tino.
You basically need to apply repos.open, then repos.fs, then
fs.revision_root, then fs.file_contents.
Roman.
Re: Question regarding the python binding
Posted by Tino Schwarze <su...@tisc.de>.
Additional question: I can't seem to find an equivalent of "svnlook cat"
anywhere... I wanted to avoid calling external programs - commits are
slow enough already...
Thanks,
Tino.
On Thu, Mar 25, 2010 at 03:17:42PM +0100, Tino Schwarze wrote:
> Hi there,
>
> I'm currently implementing commit hooks and struggling with the python
> bindings. I took the contributed pre-commit example which uses the "svn"
> python module which maps more or less directly to libsvn functions.
>
> Background: We want to enforce certain global ignores, MIME types etc.
> The most coherent way should be to just read our default .svn/config
> file and verify against it's settings. BTW: Has anybody done something
> similar already?
>
> Back to python: I managed to use the Python bindings to get a value from
> the config file (I didn't want to reinvent the wheel) like this:
>
> ***
> from svn import repos, fs, delta, core, client
>
> def main(pool, repos_dir):
>
> # for now, store client configuration in repository root
> cfgfile = repos_dir+'/conf/client.conf'
>
> svncfg = core.svn_config_read (cfgfile, True, pool)
>
> global_ignores = core.svn_config_get (svncfg, core.SVN_CONFIG_SECTION_GLOBAL, core.SVN_CONFIG_OPTION_GLOBAL_IGNORES, None)
>
> ***
>
> Now I'd like to verify our default set of required MIME types, so I need
> to get the contents of the [auto-props] section from the config file.
>
> libsvn provides the following function which should be suitable for my
> needs:
>
> svn_config_enumerate2(svn_config_t cfg, char section,
> svn_config_enumerator2_t callback, void baton, apr_pool_t pool) -> int
>
> Two questions arise:
>
> 1. How do I define an appropiate callback in Python? Looking at the SWIG
> documentation, I see examples on how to implement Python callbacks but
> they don't seem to match the current SVN bindings. I tried passing a
> Python method, deriving from svn_config_enumerator2_t etc. -> Segfault.
>
> 2. What's the baton good for? Is it just some kind of additional data, I
> don't need to care about?
>
> Maybe the devel list is more appropiate for such questions, but I wanted
> to try here first.
>
> Thanks,
>
> Tino.
>
> --
> "What we nourish flourishes." - "Was wir nähren erblüht."
>
> www.lichtkreis-chemnitz.de
> www.tisc.de
--
"What we nourish flourishes." - "Was wir nähren erblüht."
www.lichtkreis-chemnitz.de
www.tisc.de
Re: Question regarding the python binding
Posted by Роман Донченко <DX...@yandex.ru>.
Tino Schwarze <su...@tisc.de> писал в своём письме Fri, 26 Mar
2010 12:27:27 +0300:
> Hi Роман,
>
>> > Additional question: I can't seem to find an equivalent of "svnlook
>> > cat" anywhere... I wanted to avoid calling external programs - commits
>> > are slow enough already...
>>
>> You basically need to apply repos.open, then repos.fs, then
>> fs.revision_root, then fs.file_contents.
>
> I'm seeing the following example code:
>
> fs_ptr = repos.svn_repos_fs(repos.svn_repos_open(repos_dir, pool))
> root = fs.txn_root(fs.open_txn(fs_ptr, txn, pool), pool)
> cc = repos.ChangeCollector(fs_ptr, root, pool)
>
> -> shall I use fs.txn_root or fs.revision_root (the revision is not
> complete yet, it's just being committed)
If you want the behaviour of svnlook cat -t XXX, then sure, use txn_root.
When in doubt, read svnlook's source - it's rather trivial.
HTH,
Roman.
Re: Question regarding the python binding
Posted by Tino Schwarze <su...@tisc.de>.
Hi Роман,
On Thu, Mar 25, 2010 at 06:56:26PM +0300, Роман Донченко wrote:
>> Back to python: I managed to use the Python bindings to get a value from
>> the config file (I didn't want to reinvent the wheel) like this:
>>
>> ***
>> from svn import repos, fs, delta, core, client
>>
>> def main(pool, repos_dir):
>>
>> # for now, store client configuration in repository root
>> cfgfile = repos_dir+'/conf/client.conf'
>>
>> svncfg = core.svn_config_read (cfgfile, True, pool)
>>
>> global_ignores = core.svn_config_get (svncfg,
>> core.SVN_CONFIG_SECTION_GLOBAL, core.SVN_CONFIG_OPTION_GLOBAL_IGNORES,
>> None)
>>
>> ***
>>
>> Now I'd like to verify our default set of required MIME types, so I need
>> to get the contents of the [auto-props] section from the config file.
>>
>> libsvn provides the following function which should be suitable for my
>> needs:
>>
>> svn_config_enumerate2(svn_config_t cfg, char section,
>> svn_config_enumerator2_t callback, void baton, apr_pool_t pool) -> int
>>
>> Two questions arise:
>>
>> 1. How do I define an appropiate callback in Python? Looking at the SWIG
>> documentation, I see examples on how to implement Python callbacks but
>> they don't seem to match the current SVN bindings. I tried passing a
>> Python method, deriving from svn_config_enumerator2_t etc. -> Segfault.
>
> I took a look, and unfortunately this callback is not supported. The
> reason for that is that SWIG can't automatically figure out how to call
> Python callbacks, so a chunk of boring code must be written for each
> callback type - and I guess no developers needed to scratch this
> particular itch.
>
> If it was supported, however, the call would look like this (and it
> *will* look like this, after I become un-busy again and implement it):
>
> def enumerator(name, value, pool):
> print "%s: %s" % (name, value)
>
> core.svn_config_enumerate2(svncfg, core.SVN_CONFIG_SECTION_AUTO_PROPS,
> enumerator)
Thanks a lot for the answer - I already suspected something like this... ;-|
So, back to good old "do it yourself"... ;-) Not that it's complicated,
I just wanted to stay within Subversion as far as possible. :-)
>> 2. What's the baton good for? Is it just some kind of additional data, I
>> don't need to care about?
>
> The baton argument is used up by the bindings themselves, you neither
> should nor can supply your own (this applies to all callbacks).
> > Additional question: I can't seem to find an equivalent of "svnlook
> > cat" anywhere... I wanted to avoid calling external programs - commits
> > are slow enough already...
>
> You basically need to apply repos.open, then repos.fs, then
> fs.revision_root, then fs.file_contents.
I'm seeing the following example code:
fs_ptr = repos.svn_repos_fs(repos.svn_repos_open(repos_dir, pool))
root = fs.txn_root(fs.open_txn(fs_ptr, txn, pool), pool)
cc = repos.ChangeCollector(fs_ptr, root, pool)
-> shall I use fs.txn_root or fs.revision_root (the revision is not
complete yet, it's just being committed)
Thanks again,
Tino.
--
"What we nourish flourishes." - "Was wir nähren erblüht."
www.lichtkreis-chemnitz.de
www.tisc.de
Re: Question regarding the python binding
Posted by Роман Донченко <DX...@yandex.ru>.
Tino Schwarze <su...@tisc.de> писал в своём письме Thu, 25 Mar
2010 17:17:42 +0300:
> Hi there,
>
> Back to python: I managed to use the Python bindings to get a value from
> the config file (I didn't want to reinvent the wheel) like this:
>
> ***
> from svn import repos, fs, delta, core, client
>
> def main(pool, repos_dir):
>
> # for now, store client configuration in repository root
> cfgfile = repos_dir+'/conf/client.conf'
>
> svncfg = core.svn_config_read (cfgfile, True, pool)
>
> global_ignores = core.svn_config_get (svncfg,
> core.SVN_CONFIG_SECTION_GLOBAL, core.SVN_CONFIG_OPTION_GLOBAL_IGNORES,
> None)
>
> ***
>
> Now I'd like to verify our default set of required MIME types, so I need
> to get the contents of the [auto-props] section from the config file.
>
> libsvn provides the following function which should be suitable for my
> needs:
>
> svn_config_enumerate2(svn_config_t cfg, char section,
> svn_config_enumerator2_t callback, void baton, apr_pool_t pool) -> int
>
> Two questions arise:
>
> 1. How do I define an appropiate callback in Python? Looking at the SWIG
> documentation, I see examples on how to implement Python callbacks but
> they don't seem to match the current SVN bindings. I tried passing a
> Python method, deriving from svn_config_enumerator2_t etc. -> Segfault.
I took a look, and unfortunately this callback is not supported. The
reason for that is that SWIG can't automatically figure out how to call
Python callbacks, so a chunk of boring code must be written for each
callback type - and I guess no developers needed to scratch this
particular itch.
If it was supported, however, the call would look like this (and it *will*
look like this, after I become un-busy again and implement it):
def enumerator(name, value, pool):
print "%s: %s" % (name, value)
core.svn_config_enumerate2(svncfg, core.SVN_CONFIG_SECTION_AUTO_PROPS,
enumerator)
> 2. What's the baton good for? Is it just some kind of additional data, I
> don't need to care about?
The baton argument is used up by the bindings themselves, you neither
should nor can supply your own (this applies to all callbacks).
> Maybe the devel list is more appropiate for such questions, but I wanted
> to try here first.
Not really, since this is a use question. 8=]
> Thanks,
>
> Tino.
Roman.
Re: Question regarding the python binding
Posted by Tino Schwarze <su...@tisc.de>.
Additional question: I can't seem to find an equivalent of "svnlook cat"
anywhere... I wanted to avoid calling external programs - commits are
slow enough already...
Thanks,
Tino.
On Thu, Mar 25, 2010 at 03:17:42PM +0100, Tino Schwarze wrote:
> Hi there,
>
> I'm currently implementing commit hooks and struggling with the python
> bindings. I took the contributed pre-commit example which uses the "svn"
> python module which maps more or less directly to libsvn functions.
>
> Background: We want to enforce certain global ignores, MIME types etc.
> The most coherent way should be to just read our default .svn/config
> file and verify against it's settings. BTW: Has anybody done something
> similar already?
>
> Back to python: I managed to use the Python bindings to get a value from
> the config file (I didn't want to reinvent the wheel) like this:
>
> ***
> from svn import repos, fs, delta, core, client
>
> def main(pool, repos_dir):
>
> # for now, store client configuration in repository root
> cfgfile = repos_dir+'/conf/client.conf'
>
> svncfg = core.svn_config_read (cfgfile, True, pool)
>
> global_ignores = core.svn_config_get (svncfg, core.SVN_CONFIG_SECTION_GLOBAL, core.SVN_CONFIG_OPTION_GLOBAL_IGNORES, None)
>
> ***
>
> Now I'd like to verify our default set of required MIME types, so I need
> to get the contents of the [auto-props] section from the config file.
>
> libsvn provides the following function which should be suitable for my
> needs:
>
> svn_config_enumerate2(svn_config_t cfg, char section,
> svn_config_enumerator2_t callback, void baton, apr_pool_t pool) -> int
>
> Two questions arise:
>
> 1. How do I define an appropiate callback in Python? Looking at the SWIG
> documentation, I see examples on how to implement Python callbacks but
> they don't seem to match the current SVN bindings. I tried passing a
> Python method, deriving from svn_config_enumerator2_t etc. -> Segfault.
>
> 2. What's the baton good for? Is it just some kind of additional data, I
> don't need to care about?
>
> Maybe the devel list is more appropiate for such questions, but I wanted
> to try here first.
>
> Thanks,
>
> Tino.
>
> --
> "What we nourish flourishes." - "Was wir nähren erblüht."
>
> www.lichtkreis-chemnitz.de
> www.tisc.de
--
"What we nourish flourishes." - "Was wir nähren erblüht."
www.lichtkreis-chemnitz.de
www.tisc.de