Style and PEP8 fixes

This commit is contained in:
Sayamindu Dasgupta 2010-02-08 23:45:39 +05:30
parent 415f3a3066
commit 85840b269f

View File

@ -30,6 +30,7 @@ import time
_MO_BIG_ENDIAN = 0xde120495
_MO_LITTLE_ENDIAN = 0x950412de
def _readbin(handle, fmt, bytecount):
read_bytes = handle.read(bytecount)
retvalue = struct.unpack(fmt, read_bytes)
@ -38,6 +39,7 @@ def _readbin(handle, fmt, bytecount):
else:
return retvalue
def _extract_header(filepath):
header = ''
handle = open(filepath, 'rb')
@ -50,7 +52,7 @@ def _extract_header(filepath):
else:
raise IOError('File does not seem to be valid MO file')
version, numofstrings = _readbin(handle, fmt, 8)
version_, numofstrings = _readbin(handle, fmt, 8)
msgids_hash_offset, msgstrs_hash_offset = _readbin(handle, fmt, 8)
handle.seek(msgids_hash_offset)
@ -78,6 +80,7 @@ def _extract_header(filepath):
handle.close()
return header
def _extract_modification_time(filepath):
header = _extract_header(filepath)
items = header.split('\n')
@ -113,9 +116,9 @@ def get_locale_path(bundle_id):
candidate_dirs[os.environ['SUGAR_LOCALEDIR']] = 2
gconf_client = gconf.client_get_default()
packdir = gconf_client.get_string("/desktop/sugar/i18n/langpackdir")
if packdir is not None or packdir is not '':
candidate_dirs[packdir] = 1
package_dir = gconf_client.get_string("/desktop/sugar/i18n/langpackdir")
if package_dir is not None or package_dir is not '':
candidate_dirs[package_dir] = 1
candidate_dirs[os.path.join(sys.prefix, 'share', 'locale')] = 0
@ -133,5 +136,6 @@ def get_locale_path(bundle_id):
# Set lowest priority
candidate_dirs[candidate_dir] = -1
# Fancy way to sort the dictionary by value
return sorted(candidate_dirs.iteritems(), key=lambda (k, v): (v, k), \
reverse=True)[0][0]