Mercurial > traipse_dev
comparison upmana/mercurial/lock.py @ 121:496dbf12a6cb alpha
Traipse Alpha 'OpenRPG' {091030-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 (Cleaning up for Beta):
Adds Bookmarks (Alpha) with cool Smiley Star and Plus Symbol images!
Changes made to the map for increased portability. SnowDog has changes planned in
Core, though.
Added an initial push to the BCG. Not much to see, just shows off how it is
re-writing Main code.
Fix to remote admin commands
Minor fix to texted based server, works in /System/ folder
Some Core changes to gametree to correctly disply Pretty Print, thanks David!
Fix to Splitter Nodes not being created.
Added images to Plugin Control panel for Autostart feature
Fix to massive amounts of images loading; from Core
fix to gsclient so with_statement imports
Added 'boot' command to remote admin
Prep work in Pass tool for remote admin rankings and different passwords, ei,
Server, Admin, Moderator, etc.
Remote Admin Commands more organized, more prep work.
Added Confirmation window for sent nodes.
Minor changes to allow for portability to an OpenSUSE linux OS (hopefully without
breaking)
{091028}
Made changes to gametree to start working with Element Tree, mostly from Core
Minor changes to Map to start working with Element Tree, from Core
Preliminary changes to map efficiency, from FlexiRPG
Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG
Changes to main.py to start working with Element Tree
{091029}
Changes made to server to start working with Element Tree.
Changes made to Meta Server Lib. Prepping test work for a multi meta network
page.
Minor bug fixed with mini to gametree
Zoom Mouse plugin added.
{091030}
Getting ready for Beta. Server needs debugging so Alpha remains bugged.
Plugin UI code cleaned. Auto start works with a graphic, pop-up asks to enable or
disable plugin.
Update Manager now has a partially working Status Bar. Status Bar captures
terminal text, so Merc out put is visible. Manifest.xml file, will be renamed, is
now much cleaner.
Debug Console has a clear button and a Report Bug button. Prep work for a Term2Win
class in Debug Console.
Known: Current Alpha fails in Windows.
author | sirebral |
---|---|
date | Fri, 30 Oct 2009 22:21:40 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
120:d86e762a994f | 121:496dbf12a6cb |
---|---|
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 |