fixed problem with language file unlocking, thanks Anders Roos
This commit is contained in:
@@ -1 +1 @@
|
||||
Version 1.99.4 (2012-01-12 14:04:26) stable
|
||||
Version 1.99.4 (2012-01-12 14:14:38) stable
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
<ul>
|
||||
<li>Alexey Nezhdanov (GAE and database performance)
|
||||
</li><li>Alvaro Justen (dynamical translations)
|
||||
</li><li>Anders Roos (file locking)
|
||||
</li><li>Andrew Willimott (documentation)
|
||||
</li><li>Angelo Compagnucci (mobile devices)
|
||||
</li><li>Anthony Bastardi (book, poweredby site, multiple contributions)
|
||||
|
||||
+13
-6
@@ -37,11 +37,18 @@ regex_language = \
|
||||
re.compile('^[a-zA-Z]{2}(\-[a-zA-Z]{2})?(\-[a-zA-Z]+)?$')
|
||||
|
||||
|
||||
class FilenoFile():
|
||||
""" Class to wrap a file descriptor like a file object does. """
|
||||
def __init__(self, fd):
|
||||
self.fd = fd
|
||||
|
||||
def fileno(self):
|
||||
return self.fd
|
||||
|
||||
def read_dict_aux(filename):
|
||||
fp = open(filename, 'r')
|
||||
portalocker.lock(fp, portalocker.LOCK_SH)
|
||||
lang_text = fp.read().replace('\r\n', '\n')
|
||||
portalocker.unlock(fp)
|
||||
fp.close()
|
||||
if not lang_text.strip():
|
||||
return {}
|
||||
@@ -91,20 +98,20 @@ def utf8_repr(s):
|
||||
|
||||
def write_dict(filename, contents):
|
||||
try:
|
||||
fp = open(filename, 'w')
|
||||
except IOError:
|
||||
fd = os.open(filename, os.O_RDWR | os.O_CREAT)
|
||||
except (IOError, OSError):
|
||||
if not is_gae:
|
||||
logging.warning('Unable to write to file %s' % filename)
|
||||
return
|
||||
portalocker.lock(fp, portalocker.LOCK_EX)
|
||||
portalocker.lock(FilenoFile(fd), portalocker.LOCK_EX)
|
||||
os.ftruncate(fd, 0)
|
||||
fp = os.fdopen(fd, 'w')
|
||||
fp.write('# coding: utf8\n{\n')
|
||||
for key in sorted(contents):
|
||||
fp.write('%s: %s,\n' % (utf8_repr(key), utf8_repr(contents[key])))
|
||||
fp.write('}\n')
|
||||
portalocker.unlock(fp)
|
||||
fp.close()
|
||||
|
||||
|
||||
class lazyT(object):
|
||||
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user