cc-4105: locale fixes, more exceptions, routine to touch index file

This commit is contained in:
Rudi Grinberg 2012-07-23 14:12:59 -04:00
parent 6fd1dff60a
commit f40b076b46
4 changed files with 55 additions and 9 deletions

View file

@ -27,6 +27,15 @@ class MMConfig(Loggable):
"""
raise ConfigAccessViolation(key)
def last_ran():
return 123456
def update_last_run():
pass
def set_last_run_now():
pass
def save(self): self.cfg.write()
# Remove this after debugging...

View file

@ -20,3 +20,11 @@ class FailedToObtainLocale(Exception):
self.path = path
self.cause = cause
def __str__(self): return "Failed to obtain locale from '%s'" % self.path
class CouldNotCreateIndexFile(Exception):
"""exception whenever index file cannot be created"""
def __init__(self, path, cause):
self.path = path
self.cause = cause
def __str__(self): return "Failed to create touch file '%s'" % self.path

View file

@ -229,11 +229,13 @@ def file_md5(path,max_length=100):
else: raise ValueError("'%s' must exist to find its md5")
def encode_to(obj, encoding='utf-8'):
# TODO : add documentation + unit tests for this function
if isinstance(obj, unicode):
obj = obj.encode(encoding)
return obj
def convert_dict_value_to_utf8(md):
# TODO : add documentation + unit tests for this function
return dict([(item[0], encode_to(item[1], "utf-8")) for item in md.items()])
def get_system_locale(locale_path='/etc/default/locale'):
@ -266,6 +268,15 @@ def configure_locale(config):
if current_locale_encoding not in ['utf-8', 'utf8']:
raise FailedToSetLocale()
def fondle(path,times=None):
# TODO : write unit tests for this
"""
touch a file to change the last modified date. Beware of calling this function on the
same file from multiple threads.
"""
with file(path, 'a'):
os.utime(path, times)
if __name__ == '__main__':
import doctest
doctest.testmod()