List Info

Thread: RE: Locking a file




RE: Locking a file
user name
2008-04-21 01:17:22
Thank you Barry for that answer!
I got one more thing for clarification tho:
Do all the functions in your API return the svn errors/messages (like the one you get when you try to lock a already locked file) as notify events? Maybe this is a dumb question (cause it might be stated somewhere in the documentation) but I assumed that those functions throw exceptions (as some of them do, but I don't think these are the "svn messages"). Thats why I was a bit confused with lock() not throwing an exception =)
As a work around I'm calling the lock() function now followed by an info2() to test which user is the lock owner of the file (to see whether the lock() of the current user was successfull )
 
Greetings
Dominique


From: Barry Scott [mailto:barrybarrys-emacs.org]
Sent: Samstag, 19. April 2008 14:21
To: userspysvn.tigris.org
Subject: Re: Locking a file



Hi everyone!

I want to lock a file within my svn client so that only one user (client) has write access. I'm a bit confused about the API description tho:

lock( url_or_path,
      lock_comment,
      force=False )

Does this mean I can pass a URL (to a file on the repository I guess) OR a path (to a file on the working copy)? But where's the difference then?

You can lock a file directly in the repos using the URL without needed to checkout a working copy.


If I give a path to a file in the working copy I can indeed lock the file (and other clients, like Tortoise for windows see this file correctly as locked). If I specifiy a URL to a file in the repo I get the following error:

Code: 175002 Message: Lock request failed: 405 Method Not Allowed (http://schbna6001)


You need to ask on the SVN user list what this means. I can lock using PATH of URL to my HTTP server.
Of course your SVN server needs to be of a new enough version to support locking.

Another thing is:
If I lock the file by giving a path and then another client attempts to lock that file as well no exception is thrown for that client!


You need to process the notify messages that lock() generates. Here is an example:

import pysvn
import pprint

def notify( event ):
    print 'Notify:'
    pprint.pprint( event )

c=pysvn.Client()
c.callback_notify = notify


And here is its output:

: [1] barryemotion $ python2.5 l.py
Notify:
{'action': <wc_notify_action.failed_lock>,
&nbsp;'content_state': <wc_notify_state.unknown>,
 'error': ("Path '/trunk/fred/Norway/testdok.txt' is already locked by user 'fred' in filesystem '/svn-library/barrys-test-lib/db'",
&nbsp;          [("Path '/trunk/fred/Norway/testdok.txt' is already locked by user 'fred' in filesystem '/svn-library/barrys-test-lib/db'",
&nbsp;            160035)]),
 'kind': <node_kind.unknown>,
&nbsp;'mime_type': None,
&nbsp;'path': 'testdok.txt',
&nbsp;'prop_state': <wc_notify_state.unknown>,
 'revision': <Revision kind=number -1>}

See the code that WorkBench uses for a full example:

Would be nice if someone could clarify the lock API for me



Barry

Re: Locking a file
user name
2008-04-22 14:31:05
On Apr 21, 2008, at 07:17, <Dominique.Holzwarthch.delarue.com>  
<Dominique.Holzwarthch.delarue.com> wrote:

> Thank you Barry for that answer!
> I got one more thing for clarification tho:
> Do all the functions in your API return the svn
errors/messages  
> (like the one you get when you try to lock a already
locked file)  
> as notify events?

pysvn reflects the API of SVN itself.
Most raise an error on failure, but some you need to process
the  
results or use call backs to get extra info.
You would need to ask the SVN developers for the reason.


> Maybe this is a dumb question (cause it might be stated
somewhere  
> in the documentation) but I assumed that those
functions throw  
> exceptions (as some of them do, but I don't think these
are the  
> "svn messages"). Thats why I was a bit
confused with lock() not  
> throwing an exception =)


The "messages" come from printing the values
passed to the notify  
callback.
See the pysvn example client for a python replacement for
the svn  
command that uses
almost ever part of pysvn.

> As a work around I'm calling the lock() function now
followed by an  
> info2() to test which user is the lock owner of the
file (to see  
> whether the lock() of the current user was successfull
)

Please read my previous message again. I gave you the code
to detect  
the error from the notify callback.

Barry

>
> Greetings
> Dominique
>
> From: Barry Scott [mailto:barrybarrys-emacs.org]
> Sent: Samstag, 19. April 2008 14:21
> To: userspysvn.tigris.org
> Subject: Re: Locking a file
>
>
> On Apr 17, 2008, at 16:12, <Dominique.Holzwarthch.delarue.com>  
> <Dominique.Holzwarthch.delarue.com> wrote:
>
>> Hi everyone!
>>
>> I want to lock a file within my svn client so that
only one user  
>> (client) has write access. I'm a bit confused about
the API  
>> description tho:
>>
>> lock( url_or_path,
>>       lock_comment,
>>       force=False )
>>
>> Does this mean I can pass a URL (to a file on the
repository I  
>> guess) OR a path (to a file on the working copy)?
But where's the  
>> difference then?
>
> You can lock a file directly in the repos using the URL
without  
> needed to checkout a working copy.
>
>>
>> If I give a path to a file in the working copy I
can indeed lock  
>> the file (and other clients, like Tortoise for
windows see this  
>> file correctly as locked). If I specifiy a URL to a
file in the  
>> repo I get the following error:
>>
>> Code: 175002 Message: Lock request failed: 405
Method Not Allowed  
>> (http://schbna6001)
>>
>
> You need to ask on the SVN user list what this means. I
can lock  
> using PATH of URL to my HTTP server.
> Of course your SVN server needs to be of a new enough
version to  
> support locking.
>
>> Another thing is:
>> If I lock the file by giving a path and then
another client  
>> attempts to lock that file as well no exception is
thrown for that  
>> client!
>>
>
> You need to process the notify messages that lock()
generates. Here  
> is an example:
>
> import pysvn
> import pprint
>
> def notify( event ):
>     print 'Notify:'
>     pprint.pprint( event )
>
> c=pysvn.Client()
> c.callback_notify = notify
> c.lock( 'h
ttp://liara/svn/barrys-test-lib/trunk/fred/Norway/ 
> testdok.txt', comment='x', force=0 )
>
>
> And here is its output:
>
> : [1] barryemotion $ python2.5 l.py
> Notify:
> {'action': <wc_notify_action.failed_lock>,
>  'content_state': <wc_notify_state.unknown>,
>  'error': ("Path '/trunk/fred/Norway/testdok.txt'
is already locked  
> by user 'fred' in filesystem
'/svn-library/barrys-test-lib/db'",
>            [("Path
'/trunk/fred/Norway/testdok.txt' is already  
> locked by user 'fred' in filesystem
'/svn-library/barrys-test-lib/ 
> db'",
>              160035)]),
>  'kind': <node_kind.unknown>,
>  'mime_type': None,
>  'path': 'testdok.txt',
>  'prop_state': <wc_notify_state.unknown>,
>  'revision': <Revision kind=number -1>}
>
> See the code that WorkBench uses for a full example:
> http://pysvn.tigris.org/svn/pysvn/trunk/pysvn/Wor
kBench/Source/ 
> wb_subversion_project_info.py
> around line 147
>
>
>> Would be nice if someone could clarify the lock API
for me 
>>
>>
>
> Barry
>


------------------------------------------------------------
---------
To unsubscribe, e-mail: users-unsubscribepysvn.tigris.org
For additional commands, e-mail: users-helppysvn.tigris.org


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )