~openerp-community/openobject-server/fix-1130010-toxml-escape-quot

« back to all changes in this revision

Viewing changes to openerp/tools/misc.py

  • Committer: Vo Minh Thu
  • Date: 2011-02-07 12:57:23 UTC
  • mto: This revision was merged to the branch mainline in revision 3351.
  • Revision ID: vmt@openerp.com-20110207125723-ooee7d7ng5elmkso
[IMP] openerp python module.

- Some logging code moved from netsvc.py to loglevels.py
- Changed imports to use the new openerp module
- config and netsvc initialization calls move to openerp-server.py
- Moved openerp-server.py outside the old bin directory
- Some imports in tools moved inside the methods to break mutual-dependencies

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
except ImportError:
56
56
    html2text = None
57
57
 
58
 
import netsvc
 
58
import openerp.loglevels as loglevels
59
59
from config import config
60
60
from lru import LRU
61
61
 
67
67
 
68
68
# initialize a database with base/base.sql
69
69
def init_db(cr):
70
 
    import addons
 
70
    import openerp.addons as addons
71
71
    f = addons.get_module_resource('base', 'base.sql')
72
72
    base_sql_file = file_open(f)
73
73
    try:
200
200
 
201
201
    @return: fileobject if pathinfo is False else (fileobject, filepath)
202
202
    """
203
 
    import addons
 
203
    import openerp.addons as addons
204
204
    adps = addons.ad_paths
205
205
    rtp = os.path.normcase(os.path.abspath(config['root_path']))
206
206
 
434
434
    """
435
435
    class WriteToLogger(object):
436
436
        def __init__(self):
437
 
            self.logger = netsvc.Logger()
 
437
            self.logger = loglevels.Logger()
438
438
 
439
439
        def write(self, s):
440
 
            self.logger.notifyChannel('email_send', netsvc.LOG_DEBUG, s)
 
440
            self.logger.notifyChannel('email_send', loglevels.LOG_DEBUG, s)
441
441
 
442
442
    if openobject_id:
443
443
        message['Message-Id'] = generate_tracking_message_id(openobject_id)
1077
1077
    return "%0.2f %s" % (s, units[i])
1078
1078
 
1079
1079
def logged(f):
1080
 
    from tools.func import wraps
 
1080
    from func import wraps
1081
1081
 
1082
1082
    @wraps(f)
1083
1083
    def wrapper(*args, **kwargs):
1094
1094
 
1095
1095
        vector.append('  result: %s' % pformat(res))
1096
1096
        vector.append('  time delta: %s' % (time.time() - timeb4))
1097
 
        netsvc.Logger().notifyChannel('logged', netsvc.LOG_DEBUG, '\n'.join(vector))
 
1097
        loglevels.Logger().notifyChannel('logged', loglevels.LOG_DEBUG, '\n'.join(vector))
1098
1098
        return res
1099
1099
 
1100
1100
    return wrapper
1104
1104
        self.fname = fname
1105
1105
 
1106
1106
    def __call__(self, f):
1107
 
        from tools.func import wraps
 
1107
        from func import wraps
1108
1108
 
1109
1109
        @wraps(f)
1110
1110
        def wrapper(*args, **kwargs):
1300
1300
    try:
1301
1301
        import pytz
1302
1302
    except Exception:
1303
 
        netsvc.Logger().notifyChannel("detect_server_timezone", netsvc.LOG_WARNING,
 
1303
        loglevels.Logger().notifyChannel("detect_server_timezone", loglevels.LOG_WARNING,
1304
1304
            "Python pytz module is not available. Timezone will be set to UTC by default.")
1305
1305
        return 'UTC'
1306
1306
 
1334
1334
        if value:
1335
1335
            try:
1336
1336
                tz = pytz.timezone(value)
1337
 
                netsvc.Logger().notifyChannel("detect_server_timezone", netsvc.LOG_INFO,
 
1337
                loglevels.Logger().notifyChannel("detect_server_timezone", loglevels.LOG_INFO,
1338
1338
                    "Using timezone %s obtained from %s." % (tz.zone,source))
1339
1339
                return value
1340
1340
            except pytz.UnknownTimeZoneError:
1341
 
                netsvc.Logger().notifyChannel("detect_server_timezone", netsvc.LOG_WARNING,
 
1341
                loglevels.Logger().notifyChannel("detect_server_timezone", loglevels.LOG_WARNING,
1342
1342
                    "The timezone specified in %s (%s) is invalid, ignoring it." % (source,value))
1343
1343
 
1344
 
    netsvc.Logger().notifyChannel("detect_server_timezone", netsvc.LOG_WARNING,
 
1344
    loglevels.Logger().notifyChannel("detect_server_timezone", loglevels.LOG_WARNING,
1345
1345
        "No valid timezone could be detected, using default UTC timezone. You can specify it explicitly with option 'timezone' in the server configuration.")
1346
1346
    return 'UTC'
1347
1347