annotate roundup/backends/locking.py @ 703:8d2cb0d09da4 search_indexing-0-4-2-branch

Fixed small bug that prevented indexes from being generated.
author Roche Compaan <rochecompaan@users.sourceforge.net>
date Thu, 02 May 2002 11:52:12 +0000
parents 3d8ce8e2dcee
children 54333751e98d 32e41ddf2edb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
691
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
1 #! /usr/bin/env python
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
2 # Copyright (c) 2002 ekit.com Inc (http://www.ekit-inc.com/)
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
3 #
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
4 # Permission is hereby granted, free of charge, to any person obtaining a copy
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
5 # of this software and associated documentation files (the "Software"), to deal
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
6 # in the Software without restriction, including without limitation the rights
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
7 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
8 # copies of the Software, and to permit persons to whom the Software is
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
9 # furnished to do so, subject to the following conditions:
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
10 #
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
11 # The above copyright notice and this permission notice shall be included in
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
12 # all copies or substantial portions of the Software.
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
13 #
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
20 # SOFTWARE.
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
21
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
22 # $Id: locking.py,v 1.1 2002-04-15 23:25:15 richard Exp $
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
23
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
24 '''This module provides a generic interface to acquire and release
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
25 exclusive access to a file.
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
26
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
27 It should work on Unix and Windows.
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
28 '''
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
29
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
30 import portalocker
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
31
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
32 def acquire_lock(path, block=1):
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
33 '''Acquire a lock for the given path
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
34 '''
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
35 import portalocker
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
36 file = open(path, 'w')
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
37 if block:
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
38 portalocker.lock(file, portalocker.LOCK_EX)
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
39 else:
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
40 portalocker.lock(file, portalocker.LOCK_EX|portalocker.LOCK_NB)
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
41 return file
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
42
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
43 def release_lock(file):
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
44 '''Release our lock on the given path
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
45 '''
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
46 portalocker.unlock(file)
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
47
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
48 #
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
49 # $Log: not supported by cvs2svn $
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
50 #
3d8ce8e2dcee [[Metadata associated with this commit was garbled during conversion from CVS
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
diff changeset
51 #

Roundup Issue Tracker: http://roundup-tracker.org/