Back to index

plone3  3.1.7
utils.py
Go to the documentation of this file.
00001 from UserDict import UserDict
00002 import sys, os
00003 
00004 import logging
00005 logger = logging.getLogger('PlacelessTranslationService')
00006 
00007 class Registry(UserDict):
00008 
00009     def register(self, name, value):
00010         self[name] = value
00011 
00012 def log(msg, severity=logging.DEBUG, detail='', error=None):
00013     if isinstance(msg, unicode):
00014         msg = msg.encode(sys.getdefaultencoding(), 'replace')
00015     if isinstance(detail, unicode):
00016         detail = detail.encode(sys.getdefaultencoding(), 'replace')
00017     logger.log(severity, '%s \n%s', msg, detail)
00018 
00019 def make_relative_location(popath):
00020     # return ("INSTANCE_HOME", stripped po path)
00021     # when po is located below INSTANCE_HOME
00022     # and return ("ZOPE_HOME", stripped po path) 
00023     # when po is located below ZOPE_HOME
00024 
00025     popath = os.path.normpath(popath)
00026     instance_home = os.path.normpath(INSTANCE_HOME) + os.sep
00027     client_home = os.path.normpath(CLIENT_HOME) + os.sep
00028     zope_home = os.path.normpath(ZOPE_HOME) + os.sep
00029 
00030     if popath.startswith(client_home):
00031         return ("CLIENT_HOME", popath[len(client_home):])
00032     elif popath.startswith(instance_home):
00033         return ("INSTANCE_HOME", popath[len(instance_home):])
00034     elif popath.startswith(zope_home):
00035         return ("ZOPE_HOME", popath[len(zope_home):])
00036     else:
00037         return ("ABSOLUTE", popath)
00038