comparison upmana/mercurial/lock.py @ 28:ff154cf3350c ornery-orc

Traipse 'OpenRPG' {100203-00} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user. Update Summary (Stable) New Features: New Bookmarks Feature New 'boot' command to remote admin New confirmation window for sent nodes Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG New Zoom Mouse plugin added New Images added to Plugin UI Switching to Element Tree New Map efficiency, from FlexiRPG New Status Bar to Update Manager New TrueDebug Class in orpg_log (See documentation for usage) New Portable Mercurial New Tip of the Day, from Core and community New Reference Syntax added for custom PC sheets New Child Reference for gametree New Parent Reference for gametree New Gametree Recursion method, mapping, context sensitivity, and effeciency.. New Features node with bonus nodes and Node Referencing help added New Dieroller structure from Core New DieRoller portability for odd Dice New 7th Sea die roller; ie [7k3] = [7d10.takeHighest(3).open(10)] New 'Mythos' System die roller added New vs. die roller method for WoD; ie [3v3] = [3d10.vs(3)]. Included for Mythos roller also New Warhammer FRPG Die Roller (Special thanks to Puu-san for the support) New EZ_Tree Reference system. Push a button, Traipse the tree, get a reference (Beta!) New Grids act more like Spreadsheets in Use mode, with Auto Calc Fixes: Fix to allow for portability to an OpenSUSE linux OS Fix to mplay_client for Fedora and OpenSUSE Fix to Text based Server Fix to Remote Admin Commands Fix to Pretty Print, from Core Fix to Splitter Nodes not being created Fix to massive amounts of images loading, from Core Fix to Map from gametree not showing to all clients Fix to gametree about menus Fix to Password Manager check on startup Fix to PC Sheets from tool nodes. They now use the tabber_panel Fix to Whiteboard ID to prevent random line or text deleting. Fixes to Server, Remote Server, and Server GUI Fix to Update Manager; cleaner clode for saved repositories Fixes made to Settings Panel and now reactive settings when Ok is pressed Fixes to Alternity roller's attack roll. Uses a simple Tuple instead of a Splice Fix to Use panel of Forms and Tabbers. Now longer enters design mode Fix made Image Fetching. New fetching image and new failed image Fix to whiteboard ID's to prevent non updated clients from ruining the fix. default_manifest.xml renamed to default_upmana.xml
author sirebral
date Wed, 03 Feb 2010 22:16:49 -0600
parents
children
comparison
equal deleted inserted replaced
27:51428d30c59e 28:ff154cf3350c
1 # lock.py - simple locking scheme for mercurial
2 #
3 # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com>
4 #
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2, incorporated herein by reference.
7
8 import util, error
9 import errno, os, socket, time
10 import warnings
11
12 class lock(object):
13 # lock is symlink on platforms that support it, file on others.
14
15 # symlink is used because create of directory entry and contents
16 # are atomic even over nfs.
17
18 # old-style lock: symlink to pid
19 # new-style lock: symlink to hostname:pid
20
21 _host = None
22
23 def __init__(self, file, timeout=-1, releasefn=None, desc=None):
24 self.f = file
25 self.held = 0
26 self.timeout = timeout
27 self.releasefn = releasefn
28 self.desc = desc
29 self.lock()
30
31 def __del__(self):
32 if self.held:
33 warnings.warn("use lock.release instead of del lock",
34 category=DeprecationWarning,
35 stacklevel=2)
36
37 # ensure the lock will be removed
38 # even if recursive locking did occur
39 self.held = 1
40
41 self.release()
42
43 def lock(self):
44 timeout = self.timeout
45 while 1:
46 try:
47 self.trylock()
48 return 1
49 except error.LockHeld, inst:
50 if timeout != 0:
51 time.sleep(1)
52 if timeout > 0:
53 timeout -= 1
54 continue
55 raise error.LockHeld(errno.ETIMEDOUT, inst.filename, self.desc,
56 inst.locker)
57
58 def trylock(self):
59 if self.held:
60 self.held += 1
61 return
62 if lock._host is None:
63 lock._host = socket.gethostname()
64 lockname = '%s:%s' % (lock._host, os.getpid())
65 while not self.held:
66 try:
67 util.makelock(lockname, self.f)
68 self.held = 1
69 except (OSError, IOError), why:
70 if why.errno == errno.EEXIST:
71 locker = self.testlock()
72 if locker is not None:
73 raise error.LockHeld(errno.EAGAIN, self.f, self.desc,
74 locker)
75 else:
76 raise error.LockUnavailable(why.errno, why.strerror,
77 why.filename, self.desc)
78
79 def testlock(self):
80 """return id of locker if lock is valid, else None.
81
82 If old-style lock, we cannot tell what machine locker is on.
83 with new-style lock, if locker is on this machine, we can
84 see if locker is alive. If locker is on this machine but
85 not alive, we can safely break lock.
86
87 The lock file is only deleted when None is returned.
88
89 """
90 locker = util.readlock(self.f)
91 try:
92 host, pid = locker.split(":", 1)
93 except ValueError:
94 return locker
95 if host != lock._host:
96 return locker
97 try:
98 pid = int(pid)
99 except:
100 return locker
101 if util.testpid(pid):
102 return locker
103 # if locker dead, break lock. must do this with another lock
104 # held, or can race and break valid lock.
105 try:
106 l = lock(self.f + '.break')
107 l.trylock()
108 os.unlink(self.f)
109 l.release()
110 except error.LockError:
111 return locker
112
113 def release(self):
114 if self.held > 1:
115 self.held -= 1
116 elif self.held is 1:
117 self.held = 0
118 if self.releasefn:
119 self.releasefn()
120 try:
121 os.unlink(self.f)
122 except: pass
123
124 def release(*locks):
125 for lock in locks:
126 if lock is not None:
127 lock.release()
128