forked from flags/Reactor-3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocks.py
More file actions
31 lines (20 loc) · 696 Bytes
/
locks.py
File metadata and controls
31 lines (20 loc) · 696 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from globals import LOCKS
def create_lock(name, locked=False):
if name in LOCKS:
raise Exception('Lock with name \'%s\' already exists.' % name)
LOCKS[name] = {'locked': locked, 'lock_reason': ''}
return LOCKS[name]
def get_lock(lock_name):
if not lock_name in LOCKS:
raise Exception('Lock with name \'%s\' doest not exist.' % lock_name)
return LOCKS[lock_name]
def is_locked(lock_name):
return get_lock(lock_name)['locked']
def lock(lock_name, reason=''):
get_lock(lock_name)['locked'] = True
if reason:
print '%s: %s' % (lock_name, reason)
def unlock(lock_name, reason=''):
get_lock(lock_name)['locked'] = False
if reason:
print '%s: %s' % (lock_name, reason)