diff options
| author | Harry (Open ERP) <hmo@tinyerp.com> | 2009-11-24 20:14:05 +0530 |
|---|---|---|
| committer | Harry (Open ERP) <hmo@tinyerp.com> | 2009-11-24 20:14:05 +0530 |
| commit | d8ce3f1e2a5a55f0c28eb1cf8cb4cfcd2d6d5dab (patch) | |
| tree | f1dbd61528db0d90cebb5f2b5e4e836f00f71aef /bin/tools | |
| parent | dda5ed6bb1710e4690c1e01fe4265cc7db147068 (diff) | |
[FIX] replaced <TAB> with four white space.
bzr revid: hmo@tinyerp.com-20091124144405-9mzd91chohvf0uu7
Diffstat (limited to 'bin/tools')
| -rw-r--r-- | bin/tools/config.py | 42 | ||||
| -rw-r--r-- | bin/tools/misc.py | 18 | ||||
| -rw-r--r-- | bin/tools/safe_eval.py | 58 | ||||
| -rw-r--r-- | bin/tools/translate.py | 102 |
4 files changed, 110 insertions, 110 deletions
diff --git a/bin/tools/config.py b/bin/tools/config.py index 770fdea7de1..2dd6b1131bf 100644 --- a/bin/tools/config.py +++ b/bin/tools/config.py @@ -66,7 +66,7 @@ class configmanager(object): 'import_partial': "", 'pidfile': None, 'logfile': None, - 'logrotate': '1', + 'logrotate': '1', 'smtp_server': 'localhost', 'smtp_user': False, 'smtp_port':25, @@ -82,8 +82,8 @@ class configmanager(object): 'login_message': False, 'list_db' : True, } - - self.misc = {} + + self.misc = {} hasSSL = check_ssl() @@ -135,7 +135,7 @@ class configmanager(object): group = optparse.OptionGroup(parser, "Logging Configuration") group.add_option("--logfile", dest="logfile", help="file where the server log will be stored") group.add_option("--no-logrotate", dest="logrotate", action="store_false", - default=None, help="do not rotate the logfile") + default=None, help="do not rotate the logfile") group.add_option("--syslog", action="store_true", dest="syslog", default=False, help="Send the log to the syslog server") group.add_option('--log-level', dest='log_level', type='choice', choices=self._LOGLEVELS.keys(), @@ -226,7 +226,7 @@ class configmanager(object): 'db_port', 'list_db', 'logfile', 'pidfile', 'smtp_port', 'cache_timeout', 'email_from', 'smtp_server', 'smtp_user', 'smtp_password', 'price_accuracy', 'netinterface', 'netport', 'db_maxconn', 'import_partial', 'addons_path', - 'netrpc', 'xmlrpc', 'syslog', 'without_demo'] + 'netrpc', 'xmlrpc', 'syslog', 'without_demo'] if hasSSL: keys.extend(['smtp_ssl', 'secure_cert_file', 'secure_pkey_file']) @@ -341,18 +341,18 @@ class configmanager(object): if value=='False' or value=='false': value = False self.options[name] = value - #parse the other sections, as well - for sec in p.sections(): - if sec == 'options': - continue - if not self.misc.has_key(sec): - self.misc[sec]= {} - for (name, value) in p.items(sec): - if value=='True' or value=='true': - value = True - if value=='False' or value=='false': - value = False - self.misc[sec][name] = value + #parse the other sections, as well + for sec in p.sections(): + if sec == 'options': + continue + if not self.misc.has_key(sec): + self.misc[sec]= {} + for (name, value) in p.items(sec): + if value=='True' or value=='true': + value = True + if value=='False' or value=='false': + value = False + self.misc[sec][name] = value except IOError: pass except ConfigParser.NoSectionError: @@ -369,10 +369,10 @@ class configmanager(object): p.set('options', opt, loglevelnames.get(self.options[opt], self.options[opt])) else: p.set('options', opt, self.options[opt]) - - for sec in self.misc.keys(): - for opt in self.misc[sec].keys(): - p.set(sec,opt,self.misc[sec][opt]) + + for sec in self.misc.keys(): + for opt in self.misc[sec].keys(): + p.set(sec,opt,self.misc[sec][opt]) # try to create the directories and write the file try: diff --git a/bin/tools/misc.py b/bin/tools/misc.py index 9e65a47031a..982287c0864 100644 --- a/bin/tools/misc.py +++ b/bin/tools/misc.py @@ -386,15 +386,15 @@ def email_send(email_from, email_to, subject, body, email_cc=None, email_bcc=Non smtp_server = config['smtp_server'] if smtp_server.startswith('maildir:/'): from mailbox import Maildir - maildir_path = smtp_server[8:] - try: - mdir = Maildir(maildir_path,factory=None, create = True) - mdir.add(msg.as_string(True)) - return True - except Exception,e: - netsvc.Logger().notifyChannel('email_send (maildir)', netsvc.LOG_ERROR, e) - return False - + maildir_path = smtp_server[8:] + try: + mdir = Maildir(maildir_path,factory=None, create = True) + mdir.add(msg.as_string(True)) + return True + except Exception,e: + netsvc.Logger().notifyChannel('email_send (maildir)', netsvc.LOG_ERROR, e) + return False + try: oldstderr = smtplib.stderr s = smtplib.SMTP() diff --git a/bin/tools/safe_eval.py b/bin/tools/safe_eval.py index 7c4da78375c..bfbc0b34fe9 100644 --- a/bin/tools/safe_eval.py +++ b/bin/tools/safe_eval.py @@ -29,38 +29,38 @@ __export_bis = {} import sys def __init_ebis(): - global __export_bis - - _evars = [ 'abs', 'all', 'any', 'basestring' , 'bool', - 'chr', 'cmp','complex', 'dict', 'divmod', 'enumerate', - 'float', 'frozenset', 'getattr', 'hasattr', 'hash', - 'hex', 'id','int', 'iter', 'len', 'list', 'long', 'map', 'max', - 'min', 'oct', 'ord','pow', 'range', 'reduce', 'repr', - 'reversed', 'round', 'set', 'setattr', 'slice','sorted', 'str', - 'sum', 'tuple','type', 'unichr','unicode', 'xrange', - 'True','False', 'None', 'NotImplemented', 'Ellipsis', ] - - if sys.version_info[0:2] >= (2,6): - _evars.extend(['bin', 'format', 'next']) - for v in _evars: - __export_bis[v] = __builtins__[v] - + global __export_bis + + _evars = [ 'abs', 'all', 'any', 'basestring' , 'bool', + 'chr', 'cmp','complex', 'dict', 'divmod', 'enumerate', + 'float', 'frozenset', 'getattr', 'hasattr', 'hash', + 'hex', 'id','int', 'iter', 'len', 'list', 'long', 'map', 'max', + 'min', 'oct', 'ord','pow', 'range', 'reduce', 'repr', + 'reversed', 'round', 'set', 'setattr', 'slice','sorted', 'str', + 'sum', 'tuple','type', 'unichr','unicode', 'xrange', + 'True','False', 'None', 'NotImplemented', 'Ellipsis', ] + + if sys.version_info[0:2] >= (2,6): + _evars.extend(['bin', 'format', 'next']) + for v in _evars: + __export_bis[v] = __builtins__[v] + __init_ebis() def safe_eval(expr,sglobals,slocals = None): - """ A little safer version of eval(). - This one, will use fewer builtin functions, so that only - arithmetic and logic expressions can really work """ - - global __export_bis + """ A little safer version of eval(). + This one, will use fewer builtin functions, so that only + arithmetic and logic expressions can really work """ + + global __export_bis - if not sglobals.has_key('__builtins__'): - # we copy, because we wouldn't want successive calls to safe_eval - # to be able to alter the builtins. - sglobals['__builtins__'] = __export_bis.copy() - - return eval(expr,sglobals,slocals) - -#eof
\ No newline at end of file + if not sglobals.has_key('__builtins__'): + # we copy, because we wouldn't want successive calls to safe_eval + # to be able to alter the builtins. + sglobals['__builtins__'] = __export_bis.copy() + + return eval(expr,sglobals,slocals) + +#eof diff --git a/bin/tools/translate.py b/bin/tools/translate.py index dcd7afbcff4..57b15002a4e 100644 --- a/bin/tools/translate.py +++ b/bin/tools/translate.py @@ -133,12 +133,12 @@ class GettextAlias(object): return source cr = frame.f_locals.get('cr') - try: - lang = (frame.f_locals.get('context') or {}).get('lang', False) - if not (lang and cr): - return source - except: - return source + try: + lang = (frame.f_locals.get('context') or {}).get('lang', False) + if not (lang and cr): + return source + except: + return source cr.execute('select value from ir_translation where lang=%s and type=%s and src=%s', (lang, 'code', source)) res_trans = cr.fetchone() @@ -154,7 +154,7 @@ class TinyPoFile(object): def __iter__(self): self.buffer.seek(0) self.lines = self._get_lines() - self.lines_count = len(self.lines); + self.lines_count = len(self.lines); self.first = True self.tnrs= [] @@ -170,7 +170,7 @@ class TinyPoFile(object): return lines def cur_line(self): - return (self.lines_count - len(self.lines)) + return (self.lines_count - len(self.lines)) def next(self): def unquote(str): @@ -185,30 +185,30 @@ class TinyPoFile(object): else: tmp_tnrs = [] line = None - fuzzy = False + fuzzy = False while (not line): if 0 == len(self.lines): raise StopIteration() line = self.lines.pop(0).strip() if line.startswith('#:'): - if ' ' in line[2:].strip(): - for lpart in line[2:].strip().split(' '): - tmp_tnrs.append(lpart.strip().split(':',2)) - else: + if ' ' in line[2:].strip(): + for lpart in line[2:].strip().split(' '): + tmp_tnrs.append(lpart.strip().split(':',2)) + else: tmp_tnrs.append( line[2:].strip().split(':',2) ) - elif line.startswith('#,') and (line[2:].strip() == 'fuzzy'): - fuzzy = True + elif line.startswith('#,') and (line[2:].strip() == 'fuzzy'): + fuzzy = True line = self.lines.pop(0).strip() while not line: # allow empty lines between comments and msgid line = self.lines.pop(0).strip() - if line.startswith('#~ '): - while line.startswith('#~ ') or not line.strip(): - if 0 == len(self.lines): + if line.startswith('#~ '): + while line.startswith('#~ ') or not line.strip(): + if 0 == len(self.lines): raise StopIteration() - line = self.lines.pop(0) - # This has been a deprecated entry, don't return anything - return self.next() + line = self.lines.pop(0) + # This has been a deprecated entry, don't return anything + return self.next() if not line.startswith('msgid'): @@ -242,9 +242,9 @@ class TinyPoFile(object): self.tnrs.append((t, n, r, source, trad)) self.first = False - - if name == None: - return self.next() + + if name == None: + return self.next() return type, name, res_id, source, trad def write_infos(self, modules): @@ -279,7 +279,7 @@ class TinyPoFile(object): def quote(s): return '"%s"' % s.replace('"','\\"') \ .replace('\n', '\\n"\n"') \ - .replace(' \\ ',' \\\\ ') + .replace(' \\ ',' \\\\ ') plurial = len(modules) > 1 and 's' or '' @@ -490,9 +490,9 @@ def trans_generate(lang, modules, dbname=None): } # export fields - if not result.has_key('fields'): - logger.notifyChannel("db",netsvc.LOG_WARNING,"res has no fields: %r" % result) - continue + if not result.has_key('fields'): + logger.notifyChannel("db",netsvc.LOG_WARNING,"res has no fields: %r" % result) + continue for field_name, field_def in result['fields'].iteritems(): res_name = name + ',' + field_name @@ -517,11 +517,11 @@ def trans_generate(lang, modules, dbname=None): push_translation(module, 'wizard_button', res_name, 0, button_label) elif model=='ir.model.fields': - try: + try: field_name = encode(obj.name) - except AttributeError, exc: - logger.notifyChannel("db", netsvc.LOG_ERROR, "name error in %s: %s" % (xml_name,str(exc))) - continue + except AttributeError, exc: + logger.notifyChannel("db", netsvc.LOG_ERROR, "name error in %s: %s" % (xml_name,str(exc))) + continue objmodel = pool.get(obj.model) if not objmodel or not field_name in objmodel._columns: continue @@ -578,28 +578,28 @@ def trans_generate(lang, modules, dbname=None): for field_name,field_def in pool.get(model)._columns.items(): if field_def.translate: name = model + "," + field_name - try: + try: trad = getattr(obj, field_name) or '' - except: - trad = '' + except: + trad = '' push_translation(module, 'model', name, xml_name, encode(trad)) # parse source code for _() calls def get_module_from_path(path,mod_paths=None): - if not mod_paths: - # First, construct a list of possible paths - def_path = os.path.abspath(os.path.join(tools.config['root_path'], 'addons')) # default addons path (base) - ad_paths= map(lambda m: os.path.abspath(m.strip()),tools.config['addons_path'].split(',')) - mod_paths=[def_path] - for adp in ad_paths: - mod_paths.append(adp) - if not adp.startswith('/'): - mod_paths.append(os.path.join(def_path,adp)) - elif adp.startswith(def_path): - mod_paths.append(adp[len(def_path)+1:]) - - for mp in mod_paths: - if path.startswith(mp) and (os.path.dirname(path) != mp): + if not mod_paths: + # First, construct a list of possible paths + def_path = os.path.abspath(os.path.join(tools.config['root_path'], 'addons')) # default addons path (base) + ad_paths= map(lambda m: os.path.abspath(m.strip()),tools.config['addons_path'].split(',')) + mod_paths=[def_path] + for adp in ad_paths: + mod_paths.append(adp) + if not adp.startswith('/'): + mod_paths.append(os.path.join(def_path,adp)) + elif adp.startswith(def_path): + mod_paths.append(adp[len(def_path)+1:]) + + for mp in mod_paths: + if path.startswith(mp) and (os.path.dirname(path) != mp): path = path[len(mp)+1:] return path.split(os.path.sep)[0] return 'base' # files that are not in a module are considered as being in 'base' module @@ -760,8 +760,8 @@ def trans_load_data(db_name, fileobj, fileformat, lang, strict=False, lang_name= # if the resource id (res_id) is in that list, use it, # otherwise use the whole list - if not ids: - ids = [] + if not ids: + ids = [] ids = (dic['res_id'] in ids) and [dic['res_id']] or ids for id in ids: dic['res_id'] = id |
