reverted use of os.ftruncate in languages because not portable on windows but removed unlocking when locked shared, should be tested
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 1.99.4 (2012-01-12 22:51:51) stable
|
Version 1.99.4 (2012-01-13 23:00:13) stable
|
||||||
|
|||||||
+5
-12
@@ -37,18 +37,11 @@ regex_language = \
|
|||||||
re.compile('^[a-zA-Z]{2}(\-[a-zA-Z]{2})?(\-[a-zA-Z]+)?$')
|
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):
|
def read_dict_aux(filename):
|
||||||
fp = open(filename, 'r')
|
fp = open(filename, 'r')
|
||||||
portalocker.lock(fp, portalocker.LOCK_SH)
|
portalocker.lock(fp, portalocker.LOCK_SH)
|
||||||
lang_text = fp.read().replace('\r\n', '\n')
|
lang_text = fp.read().replace('\r\n', '\n')
|
||||||
|
# needed? portalocker.unlock(fp)
|
||||||
fp.close()
|
fp.close()
|
||||||
if not lang_text.strip():
|
if not lang_text.strip():
|
||||||
return {}
|
return {}
|
||||||
@@ -98,20 +91,20 @@ def utf8_repr(s):
|
|||||||
|
|
||||||
def write_dict(filename, contents):
|
def write_dict(filename, contents):
|
||||||
try:
|
try:
|
||||||
fd = os.open(filename, os.O_RDWR | os.O_CREAT)
|
fp = open(filename, 'w')
|
||||||
except (IOError, OSError):
|
except (IOError, OSError):
|
||||||
if not is_gae:
|
if not is_gae:
|
||||||
logging.warning('Unable to write to file %s' % filename)
|
logging.warning('Unable to write to file %s' % filename)
|
||||||
return
|
return
|
||||||
portalocker.lock(FilenoFile(fd), portalocker.LOCK_EX)
|
portalocker.lock(fp, portalocker.LOCK_EX)
|
||||||
os.ftruncate(fd, 0)
|
|
||||||
fp = os.fdopen(fd, 'w')
|
|
||||||
fp.write('# coding: utf8\n{\n')
|
fp.write('# coding: utf8\n{\n')
|
||||||
for key in sorted(contents):
|
for key in sorted(contents):
|
||||||
fp.write('%s: %s,\n' % (utf8_repr(key), utf8_repr(contents[key])))
|
fp.write('%s: %s,\n' % (utf8_repr(key), utf8_repr(contents[key])))
|
||||||
fp.write('}\n')
|
fp.write('}\n')
|
||||||
|
portalocker.unlock(fp)
|
||||||
fp.close()
|
fp.close()
|
||||||
|
|
||||||
|
|
||||||
class lazyT(object):
|
class lazyT(object):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user