diff options
| author | P. Christeas <p_christ@hol.gr> | 2009-01-06 11:40:17 +0200 |
|---|---|---|
| committer | P. Christeas <p_christ@hol.gr> | 2009-01-06 11:40:17 +0200 |
| commit | 1435d6d064defe203e41b918fa62f5fdb20069cd (patch) | |
| tree | 268966970dbe3efd01dbbc5f5e1e6096f7dd3125 /bin/tools | |
| parent | 12bcce44c451ea193c188c55b4cc3e979aeff004 (diff) | |
| parent | 20ad606d8b13338dbe53447e8b049548bc878288 (diff) | |
Merge branch 'master' of /home/panos/tmp/tinyerp/openobject-server/ into mdv-gpl3
bzr revid: p_christ@hol.gr-20090106094017-i26aufnjth5am64m
Diffstat (limited to 'bin/tools')
| -rw-r--r-- | bin/tools/__init__.py | 2 | ||||
| -rw-r--r-- | bin/tools/amount_to_text.py | 2 | ||||
| -rw-r--r-- | bin/tools/amount_to_text_en.py | 2 | ||||
| -rw-r--r-- | bin/tools/config.py | 2 | ||||
| -rw-r--r-- | bin/tools/convert.py | 2 | ||||
| -rw-r--r-- | bin/tools/func.py | 66 | ||||
| -rw-r--r-- | bin/tools/graph.py | 2 | ||||
| -rw-r--r-- | bin/tools/import_email.py | 2 | ||||
| -rw-r--r-- | bin/tools/maintenance.py | 62 | ||||
| -rw-r--r-- | bin/tools/misc.py | 167 | ||||
| -rw-r--r-- | bin/tools/osutil.py | 2 | ||||
| -rw-r--r-- | bin/tools/parse_version.py | 4 | ||||
| -rw-r--r-- | bin/tools/pdf_utils.py | 2 | ||||
| -rw-r--r-- | bin/tools/sql.py | 2 | ||||
| -rw-r--r-- | bin/tools/translate.py | 4 |
15 files changed, 227 insertions, 96 deletions
diff --git a/bin/tools/__init__.py b/bin/tools/__init__.py index 54c13704936..ad693e14aa1 100644 --- a/bin/tools/__init__.py +++ b/bin/tools/__init__.py @@ -2,7 +2,7 @@ ############################################################################## # # OpenERP, Open Source Management Solution -# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved +# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved # $Id$ # # This program is free software: you can redistribute it and/or modify diff --git a/bin/tools/amount_to_text.py b/bin/tools/amount_to_text.py index 3734c9617f5..f933ae263e7 100644 --- a/bin/tools/amount_to_text.py +++ b/bin/tools/amount_to_text.py @@ -2,7 +2,7 @@ ############################################################################## # # OpenERP, Open Source Management Solution -# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved +# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved # $Id$ # # This program is free software: you can redistribute it and/or modify diff --git a/bin/tools/amount_to_text_en.py b/bin/tools/amount_to_text_en.py index c8cf4cb0e94..3fcf5b20b4c 100644 --- a/bin/tools/amount_to_text_en.py +++ b/bin/tools/amount_to_text_en.py @@ -2,7 +2,7 @@ ############################################################################## # # OpenERP, Open Source Management Solution -# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved +# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved # $Id$ # # This program is free software: you can redistribute it and/or modify diff --git a/bin/tools/config.py b/bin/tools/config.py index e19c95e1660..0d9e31f7870 100644 --- a/bin/tools/config.py +++ b/bin/tools/config.py @@ -2,7 +2,7 @@ ############################################################################## # # OpenERP, Open Source Management Solution -# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved +# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved # $Id$ # # This program is free software: you can redistribute it and/or modify diff --git a/bin/tools/convert.py b/bin/tools/convert.py index 453a34b07d2..1c6cdda2323 100644 --- a/bin/tools/convert.py +++ b/bin/tools/convert.py @@ -2,7 +2,7 @@ ############################################################################## # # OpenERP, Open Source Management Solution -# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved +# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved # $Id$ # # This program is free software: you can redistribute it and/or modify diff --git a/bin/tools/func.py b/bin/tools/func.py index 96113e04072..7dd515b523d 100644 --- a/bin/tools/func.py +++ b/bin/tools/func.py @@ -1,8 +1,8 @@ # -*- encoding: utf-8 -*- ############################################################################## # -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved # $Id$ # # This program is free software: you can redistribute it and/or modify @@ -20,12 +20,60 @@ # ############################################################################## +__all__ = ['partial', 'wraps', 'update_wrapper'] + try: - from functools import wraps + from functools import partial, wraps, update_wrapper except ImportError: - # this module doesn't exist in python < 2.5 - # we define a identity decorator - def wraps(f): - def identity(x): - return x - return identity + # The functools module doesn't exist in python < 2.5 + # Code taken from python 2.5 + # http://svn.python.org/view/python/tags/r254/Lib/functools.py?view=markup + + def partial(fun, *args, **kwargs): + def _partial(*args2, **kwargs2): + return fun(*(args+args2), **dict(kwargs, **kwargs2)) + return _partial + + ### --- code from python 2.5 + + # update_wrapper() and wraps() are tools to help write + # wrapper functions that can handle naive introspection + + WRAPPER_ASSIGNMENTS = ('__module__', '__name__', '__doc__') + WRAPPER_UPDATES = ('__dict__',) + def update_wrapper(wrapper, + wrapped, + assigned = WRAPPER_ASSIGNMENTS, + updated = WRAPPER_UPDATES): + """Update a wrapper function to look like the wrapped function + + wrapper is the function to be updated + wrapped is the original function + assigned is a tuple naming the attributes assigned directly + from the wrapped function to the wrapper function (defaults to + functools.WRAPPER_ASSIGNMENTS) + updated is a tuple naming the attributes off the wrapper that + are updated with the corresponding attribute from the wrapped + function (defaults to functools.WRAPPER_UPDATES) + """ + for attr in assigned: + setattr(wrapper, attr, getattr(wrapped, attr)) + for attr in updated: + getattr(wrapper, attr).update(getattr(wrapped, attr, {})) + # Return the wrapper so this can be used as a decorator via partial() + return wrapper + + def wraps(wrapped, + assigned = WRAPPER_ASSIGNMENTS, + updated = WRAPPER_UPDATES): + """Decorator factory to apply update_wrapper() to a wrapper function + + Returns a decorator that invokes update_wrapper() with the decorated + function as the wrapper argument and the arguments to wraps() as the + remaining arguments. Default arguments are as for update_wrapper(). + This is a convenience function to simplify applying partial() to + update_wrapper(). + """ + return partial(update_wrapper, wrapped=wrapped, + assigned=assigned, updated=updated) + diff --git a/bin/tools/graph.py b/bin/tools/graph.py index 80853cd09ee..9d246e4037f 100644 --- a/bin/tools/graph.py +++ b/bin/tools/graph.py @@ -3,7 +3,7 @@ ############################################################################## # # OpenERP, Open Source Management Solution -# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved +# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved # $Id$ # # This program is free software: you can redistribute it and/or modify diff --git a/bin/tools/import_email.py b/bin/tools/import_email.py index cd8c470f96d..d6811350140 100644 --- a/bin/tools/import_email.py +++ b/bin/tools/import_email.py @@ -2,7 +2,7 @@ ############################################################################## # # OpenERP, Open Source Management Solution -# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved +# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved # $Id$ # # This program is free software: you can redistribute it and/or modify diff --git a/bin/tools/maintenance.py b/bin/tools/maintenance.py new file mode 100644 index 00000000000..959d9f7bf3c --- /dev/null +++ b/bin/tools/maintenance.py @@ -0,0 +1,62 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved +# $Id$ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +############################################################################## + +import xmlrpclib + +class remote_contract(object): + def __init__(self, contract_id, contract_password, modules=None): + self.__server = 'http://localhost:8069/xmlrpc/' + self.__db = "trunk" + self.__password = "admin" + self.__login = "admin" + + rpc = xmlrpclib.ServerProxy(self.__server + 'common') + self.__userid = rpc.login(self.__db, self.__login, self.__password) + + self.__rpc = xmlrpclib.ServerProxy(self.__server + 'object') + + + contract = { + 'name': contract_id, + 'password': contract_password, + } + if modules is None: + modules = [] + + info = self.check_contract(modules, contract) + for n in info: + setattr(self, n, info[n]) + + self.name = contract_id + self.contract_id = self.name + self.password = contract_password + + def __getattr__(self, fun): + def remote_call(*args, **kwargs): + return self.__rpc.execute(self.__db, self.__userid, self.__password, 'maintenance.maintenance', fun, *args, **kwargs) + return remote_call + + def __getitem__(self, item): + return getattr(self, item) + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: + diff --git a/bin/tools/misc.py b/bin/tools/misc.py index a9157541a99..6b366eec67f 100644 --- a/bin/tools/misc.py +++ b/bin/tools/misc.py @@ -2,7 +2,7 @@ ############################################################################## # # OpenERP, Open Source Management Solution -# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved +# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved # $Id$ # # This program is free software: you can redistribute it and/or modify @@ -549,26 +549,74 @@ class cache(object): self.multi = multi self.lasttime = time.time() self.cache = {} - + self.fun = None cache.__caches.append(self) - @classmethod - def clean_cache_for_db(cls, dbname): - def get_dbname_from_key(key): - for e in key: - if e[0] == 'dbname': - return e[1] - return None - - for cache in cls.__caches: - keys_to_del = [key for key in cache.cache if get_dbname_from_key(key) == dbname] - for key in keys_to_del: - del cache.cache[key] + + def _generate_keys(self, dbname, kwargs2): + """ + Generate keys depending of the arguments and the self.mutli value + """ + + def to_tuple(d): + i = d.items() + i.sort() + return tuple(i) + + if not self.multi: + key = (('dbname', dbname),) + to_tuple(kwargs2) + yield key, None + else: + multis = kwargs2[self.multi][:] + for id in multis: + kwargs2[self.multi] = [id] + key = (('dbname', dbname),) + to_tuple(kwargs2) + yield key, id + + def _unify_args(self, *args, **kwargs): + # Update named arguments with positional argument values (without self and cr) + kwargs2 = self.fun_default_values.copy() + kwargs2.update(kwargs) + kwargs2.update(dict(zip(self.fun_arg_names, args[self.skiparg-2:]))) + for k in kwargs2: + if isinstance(kwargs2[k], (list, dict, set)): + kwargs2[k] = tuple(kwargs2[k]) + elif not is_hashable(kwargs2[k]): + kwargs2[k] = repr(kwargs2[k]) + + return kwargs2 + + def clear(self, dbname, *args, **kwargs): + """clear the cache for database dbname + if *args and **kwargs are both empty, clear all the keys related to this database + """ + if not args and not kwargs: + keys_to_del = [key for key in self.cache if key[0][1] == dbname] + else: + kwargs2 = self._unify_args(*args, **kwargs) + keys_to_del = [key for key, _ in self._generate_keys(dbname, kwargs2) if key in self.cache] + + for key in keys_to_del: + del self.cache[key] + + @classmethod + def clean_caches_for_db(cls, dbname): + for c in cls.__caches: + c.clear(dbname) def __call__(self, fn): - arg_names = inspect.getargspec(fn)[0][self.skiparg:] - - def cached_result(self2, cr=None, *args, **kwargs): + if self.fun is not None: + raise Exception("Can not use a cache instance on more than one function") + self.fun = fn + + argspec = inspect.getargspec(fn) + self.fun_arg_names = argspec[0][self.skiparg:] + self.fun_default_values = {} + if argspec[3]: + self.fun_default_values = dict(zip(self.fun_arg_names[-len(argspec[3]):], argspec[3])) + debug(self.fun_default_values) + + def cached_result(self2, cr, *args, **kwargs): if time.time()-self.timeout > self.lasttime: self.lasttime = time.time() t = time.time()-self.timeout @@ -576,64 +624,36 @@ class cache(object): if self.cache[key][1]<t: del self.cache[key] - if cr is None: - self.cache = {} - return True - if ('clear_keys' in kwargs): - if (kwargs['clear_keys'] in self.cache): - del self.cache[kwargs['clear_keys']] - return True - - # Update named arguments with positional argument values (without self and cr) - kwargs2 = kwargs.copy() - kwargs2.update(dict(zip(arg_names, args[self.skiparg-2:]))) - for k in kwargs2: - if isinstance(kwargs2[k], (list, dict, set)): - kwargs2[k] = tuple(kwargs2[k]) - elif not is_hashable(kwargs2[k]): - kwargs2[k] = repr(kwargs2[k]) - - if self.multi: - kwargs3 = kwargs2.copy() - notincache = [] - result = {} - for id in kwargs3[self.multi]: - kwargs2[self.multi] = [id] - kwargs4 = kwargs2.items() - kwargs4.sort() - - # Work out key as a tuple of ('argname', value) pairs - key = (('dbname', cr.dbname),) + tuple(kwargs4) - if key in self.cache: - result[id] = self.cache[key][0] - else: - notincache.append(id) - - - - if notincache: - kwargs2[self.multi] = notincache - result2 = fn(self2, cr, *args[2:self.skip], **kwargs3) - for id in result2: - kwargs2[self.multi] = [id] - kwargs4 = kwargs2.items() - kwargs4.sort() - key = (('dbname', cr.dbname),) + tuple(kwargs4) - self.cache[key] = result2[id] - result.updat(result2) - return result - - kwargs2 = kwargs2.items() - kwargs2.sort() - - key = (('dbname', cr.dbname),) + tuple(kwargs2) - if key in self.cache: - return self.cache[key][0] + kwargs2 = self._unify_args(*args, **kwargs) - result = fn(self2, cr, *args, **kwargs) - - self.cache[key] = (result, time.time()) + result = {} + notincache = {} + for key, id in self._generate_keys(cr.dbname, kwargs2): + if key in self.cache: + result[id] = self.cache[key][0] + else: + notincache[id] = key + + if notincache: + if self.multi: + kwargs2[self.multi] = notincache.keys() + + result2 = fn(self2, cr, *args[2:self.skiparg], **kwargs2) + if not self.multi: + key = notincache[None] + self.cache[key] = (result2, time.time()) + result[None] = result2 + else: + for id in result2: + key = notincache[id] + self.cache[key] = (result2[id], time.time()) + result.update(result2) + + if not self.multi: + return result[None] return result + + cached_result.clear_cache = self.clear return cached_result def to_xml(s): @@ -688,6 +708,7 @@ def get_languages(): languages={ 'ar_AR': u'Arabic / الْعَرَبيّة', 'bg_BG': u'Bulgarian / български', + 'bs_BS': u'Bosnian / bosanski jezik', 'ca_ES': u'Catalan / Català', 'cs_CZ': u'Czech / Čeština', 'de_DE': u'German / Deutsch', diff --git a/bin/tools/osutil.py b/bin/tools/osutil.py index 1925f82f671..5c514417ec8 100644 --- a/bin/tools/osutil.py +++ b/bin/tools/osutil.py @@ -2,7 +2,7 @@ ############################################################################## # # OpenERP, Open Source Management Solution -# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved +# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved # $Id$ # # This program is free software: you can redistribute it and/or modify diff --git a/bin/tools/parse_version.py b/bin/tools/parse_version.py index 46236aa6080..f79e2bad458 100644 --- a/bin/tools/parse_version.py +++ b/bin/tools/parse_version.py @@ -2,7 +2,7 @@ ############################################################################## # # OpenERP, Open Source Management Solution -# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved +# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved # $Id$ # # This program is free software: you can redistribute it and/or modify @@ -83,7 +83,7 @@ def parse_version(s): if __name__ == '__main__': pvs = [] - for v in ('0', '4.2', '4.2.3.4', '5.0.0-alpha', '5.0.0-rc1', '5.0.0-rc1.1', '5.0.0_rc2', '5.0.0'): + for v in ('0', '4.2', '4.2.3.4', '5.0.0-alpha', '5.0.0-rc1', '5.0.0-rc1.1', '5.0.0_rc2', '5.0.0_rc3', '5.0.0'): pv = parse_version(v) print v, pv pvs.append(pv) diff --git a/bin/tools/pdf_utils.py b/bin/tools/pdf_utils.py index 7699177a1d6..5e58f2fdecc 100644 --- a/bin/tools/pdf_utils.py +++ b/bin/tools/pdf_utils.py @@ -2,7 +2,7 @@ ############################################################################## # # OpenERP, Open Source Management Solution -# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved +# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved # $Id$ # # This program is free software: you can redistribute it and/or modify diff --git a/bin/tools/sql.py b/bin/tools/sql.py index b186c649ef1..c0feed03f94 100644 --- a/bin/tools/sql.py +++ b/bin/tools/sql.py @@ -2,7 +2,7 @@ ############################################################################## # # OpenERP, Open Source Management Solution -# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved +# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved # $Id$ # # This program is free software: you can redistribute it and/or modify diff --git a/bin/tools/translate.py b/bin/tools/translate.py index 21add6df4ef..e668bfbc790 100644 --- a/bin/tools/translate.py +++ b/bin/tools/translate.py @@ -2,7 +2,7 @@ ############################################################################## # # OpenERP, Open Source Management Solution -# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved +# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved # $Id$ # # This program is free software: you can redistribute it and/or modify @@ -370,7 +370,7 @@ def trans_generate(lang, modules, dbname=None): continue obj = pool.get(model).browse(cr, uid, res_id) if model=='ir.ui.view': - d = xml.dom.minidom.parseString(obj.arch) + d = xml.dom.minidom.parseString(encode(obj.arch)) for t in trans_parse_view(d.documentElement): push_translation(module, 'view', encode(obj.model), 0, t) elif model=='ir.actions.wizard': |
