From 587828161d84b829e03eb312d962b4dd9b40300f Mon Sep 17 00:00:00 2001 From: "Rvo (Open ERP)" Date: Thu, 11 Mar 2010 14:19:41 +0530 Subject: [PATCH 1/2] [ADD]:suppot for __openerp__.py or __terp__.py bzr revid: rvo@tinyerp.co.in-20100311084941-1l92enpyz1a98hrr --- bin/addons/__init__.py | 32 +++++++++++++++++++------------- bin/addons/base/module/module.py | 5 ++++- bin/addons/module_graph.py | 13 +++++++++---- bin/tools/config.py | 16 ++++++++-------- bin/tools/misc.py | 10 ++++++++-- setup.py | 8 ++++++-- 6 files changed, 54 insertions(+), 30 deletions(-) diff --git a/bin/addons/__init__.py b/bin/addons/__init__.py index bdd3da46bbf..4e939bf01dc 100644 --- a/bin/addons/__init__.py +++ b/bin/addons/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2009 Tiny SPRL (). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . +# along with this program. If not, see . # ############################################################################## @@ -89,7 +89,7 @@ class Graph(dict): ## and we update the default values with values from the database additional_data.update(dict([(x.pop('name'), x) for x in cr.dictfetchall()])) - + for package in self.values(): for k, v in additional_data[package.name].items(): setattr(package, k, v) @@ -221,7 +221,7 @@ def get_module_as_zip_from_module_directory(module_directory, b64enc=True, src=T base = os.path.basename(path) for f in tools.osutil.listdir(path, True): bf = os.path.basename(f) - if not RE_exclude.search(bf) and (src or bf == '__terp__.py' or not bf.endswith('.py')): + if not RE_exclude.search(bf) and (src or bf == '__openerp__.py' or bf == '__terp__.py' or not bf.endswith('.py')): archive.write(os.path.join(path, f), os.path.join(base, f)) archname = StringIO() @@ -298,8 +298,10 @@ def get_modules_with_version(): modules = get_modules() res = {} for module in modules: - terp = get_module_resource(module, '__terp__.py') try: + terp = get_module_resource(module, '__openerp__.py') + if not os.path.isfile(terp): + terp = addons.get_module_resource(module, '__terp__.py') info = eval(tools.file_open(terp).read()) res[module] = "%s.%s" % (release.major_version, info['version']) except Exception, e: @@ -318,13 +320,17 @@ def upgrade_graph(graph, cr, module_list, force=None): len_graph = len(graph) for module in module_list: mod_path = get_module_path(module) - terp_file = get_module_resource(module, '__terp__.py') + terp_file = get_module_resource(module, '__openerp__.py') + if not os.path.isfile(terp_file): + terp_file = get_module_resource(module, '__terp__.py') + if not mod_path or not terp_file: global not_loaded not_loaded.append(module) logger.notifyChannel('init', netsvc.LOG_WARNING, 'module %s: not installable' % (module)) raise osv.osv.except_osv('Error!',"Module '%s' was not found" % (module,)) + if os.path.isfile(terp_file) or zipfile.is_zipfile(mod_path+'.zip'): try: info = eval(tools.file_open(terp_file).read()) @@ -337,7 +343,7 @@ def upgrade_graph(graph, cr, module_list, force=None): dependencies = dict([(p, deps) for p, deps, data in packages]) current, later = set([p for p, dep, data in packages]), set() - + while packages and current > later: package, deps, data = packages[0] @@ -378,7 +384,7 @@ def init_module_objects(cr, module_name, obj_list): try: result = obj._auto_init(cr, {'module': module_name}) except Exception, e: - raise + raise if result: todo += result if hasattr(obj, 'init'): @@ -588,7 +594,7 @@ def load_module_graph(cr, graph, status=None, perform_checks=True, **kwargs): modobj = None logger.notifyChannel('init', netsvc.LOG_DEBUG, 'loading %d packages..' % len(graph)) - + for package in graph: logger.notifyChannel('init', netsvc.LOG_INFO, 'module %s: loading objects' % package.name) migrations.migrate_module(package, 'pre') @@ -597,7 +603,7 @@ def load_module_graph(cr, graph, status=None, perform_checks=True, **kwargs): if hasattr(package, 'init') or hasattr(package, 'update') or package.state in ('to install', 'to upgrade'): init_module_objects(cr, package.name, modules) cr.commit() - + for package in graph: status['progress'] = (float(statusi)+0.1) / len(graph) m = package.name @@ -698,7 +704,7 @@ def load_modules(db, force_demo=False, status=None, update_module=False): cr = db.cursor() if cr: cr.execute("SELECT relname FROM pg_class WHERE relkind='r' AND relname='ir_module_module'") - if len(cr.fetchall())==0: + if len(cr.fetchall())==0: logger.notifyChannel("init", netsvc.LOG_INFO, "init db") tools.init_db(cr) # cr.execute("update res_users set password=%s where id=%s",('admin',1)) @@ -706,7 +712,7 @@ def load_modules(db, force_demo=False, status=None, update_module=False): tools.config["init"]["all"] = 1 tools.config['update']['all'] = 1 if not tools.config['without_demo']: - tools.config["demo"]['all'] = 1 + tools.config["demo"]['all'] = 1 force = [] if force_demo: force.append('demo') @@ -716,7 +722,6 @@ def load_modules(db, force_demo=False, status=None, update_module=False): # NOTE: Try to also load the modules that have been marked as uninstallable previously... STATES_TO_LOAD = ['installed', 'to upgrade', 'uninstallable'] graph = create_graph(cr, ['base'], force) - has_updates = load_module_graph(cr, graph, status, perform_checks=(not update_module), report=report) global not_loaded @@ -761,6 +766,7 @@ def load_modules(db, force_demo=False, status=None, update_module=False): if new_modules_in_graph == 0: # nothing to load break + logger.notifyChannel('init', netsvc.LOG_DEBUG, 'Updating graph with %d more modules' % (len(module_list))) r = load_module_graph(cr, graph, status, report=report) has_updates = has_updates or r diff --git a/bin/addons/base/module/module.py b/bin/addons/base/module/module.py index a474866f885..faec4ffa9be 100644 --- a/bin/addons/base/module/module.py +++ b/bin/addons/base/module/module.py @@ -65,7 +65,10 @@ class module(osv.osv): def get_module_info(self, name): try: - f = tools.file_open(os.path.join(name, '__terp__.py')) + terp_file = addons.get_module_resource(name, '__openerp__.py') + if not os.path.isfile(terp_file): + terp_file = addons.get_module_resource(name, '__terp__.py') + f = tools.file_open(terp_file) data = f.read() info = eval(data) if 'version' in info: diff --git a/bin/addons/module_graph.py b/bin/addons/module_graph.py index 74d4115a086..e321592ccc7 100755 --- a/bin/addons/module_graph.py +++ b/bin/addons/module_graph.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2009 Tiny SPRL (). # @@ -16,7 +16,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . +# along with this program. If not, see . # ############################################################################## @@ -32,7 +32,8 @@ if len(sys.argv) == 2 and (sys.argv[1] in ['-h', '--help']): modules = sys.argv[1:] if not len(modules): - modules = map(os.path.dirname, glob.glob(os.path.join('*', '__terp__.py'))) + modules = map(os.path.dirname, glob.glob(os.path.join('*', '__openerp__.py'))) + modules += map(os.path.dirname, glob.glob(os.path.join('*', '__terp__.py'))) done = [] @@ -40,7 +41,11 @@ print 'digraph G {' while len(modules): f = modules.pop(0) done.append(f) - if os.path.isfile(os.path.join(f,"__terp__.py")): + terp_file = os.path.join(f,"__openerp__.py") + if not os.path.isfile(terp_file): + terp_file = os.path.join(f,"__terp__.py") + + if os.path.isfile(terp_file): info=eval(file(os.path.join(f,"__terp__.py")).read()) if info.get('installable', True): for name in info['depends']: diff --git a/bin/tools/config.py b/bin/tools/config.py index bc4aa98b77e..57f0388a238 100644 --- a/bin/tools/config.py +++ b/bin/tools/config.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2009 Tiny SPRL (). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . +# along with this program. If not, see . # ############################################################################## @@ -83,7 +83,7 @@ class configmanager(object): 'list_db' : True, 'timezone' : False, # to override the default TZ } - + self.misc = {} hasSSL = check_ssl() @@ -234,7 +234,7 @@ class configmanager(object): keys = ['interface', 'port', 'db_name', 'db_user', 'db_password', 'db_host', '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', + 'netinterface', 'netport', 'db_maxconn', 'import_partial', 'addons_path', 'netrpc', 'xmlrpc', 'syslog', 'without_demo', 'timezone',] if hasSSL: @@ -278,7 +278,7 @@ class configmanager(object): self.options['translate_modules'].sort() if self.options['timezone']: - # If an explicit TZ was provided in the config, make sure it is known + # If an explicit TZ was provided in the config, make sure it is known try: import pytz tz = pytz.timezone(self.options['timezone']) @@ -356,13 +356,13 @@ class configmanager(object): for f in os.listdir(res): modpath = os.path.join(res, f) if os.path.isdir(modpath) and os.path.exists(os.path.join(modpath, '__init__.py')) and \ - os.path.exists(os.path.join(modpath, '__terp__.py')): + ('|', os.path.exists(os.path.join(modpath, '__openerp__.py')), os.path.exists(os.path.join(modpath, '__terp__.py'))): contains_addons = True break if not contains_addons: raise optparse.OptionValueError("option %s: The addons-path %r does not seem to a be a valid Addons Directory!" % (opt, value)) - + setattr(parser.values, option.dest, res) def load(self): @@ -403,7 +403,7 @@ 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]) diff --git a/bin/tools/misc.py b/bin/tools/misc.py index f105cd81256..b153467a2a9 100644 --- a/bin/tools/misc.py +++ b/bin/tools/misc.py @@ -50,13 +50,19 @@ def init_db(cr): cr.commit() for i in addons.get_modules(): - terp_file = addons.get_module_resource(i, '__terp__.py') + terp_file = addons.get_module_resource(i, '__openerp__.py') mod_path = addons.get_module_path(i) if not mod_path: continue info = False +# if os.path.isfile(terp_file) or os.path.isfile(mod_path+'.zip'): +# info = eval(file_open(terp_file).read()) + if not os.path.isfile(terp_file): + terp_file = addons.get_module_resource(i, '__terp__.py') + if os.path.isfile(terp_file) or os.path.isfile(mod_path+'.zip'): - info = eval(file_open(terp_file).read()) + info = eval(file_open(terp_file).read()) + if info: categs = info.get('category', 'Uncategorized').split('/') p_id = None diff --git a/setup.py b/setup.py index 9d7a735d2f6..bc2d8b64d3f 100755 --- a/setup.py +++ b/setup.py @@ -77,7 +77,7 @@ def check_modules(): def find_addons(): for root, _, names in os.walk(join('bin', 'addons')): - if '__terp__.py' in names: + if '__openerp__.py' or '__terp__.py' in names: yield basename(root), root #look for extra modules try: @@ -86,7 +86,11 @@ def find_addons(): mname = mname.strip() if not mname: continue - if os.path.exists(join(empath, mname, '__terp__.py')): + terp = join(empath, mname, '__openerp__.py') + if not os.path.exists(terp): + terp = join(empath, mname, '__terp__.py') + + if os.path.exists(terp): yield mname, join(empath, mname) else: print "Module %s specified, but no valid path." % mname From 23586fb33171451e8bc2220b57b12102e6dfe259 Mon Sep 17 00:00:00 2001 From: STW <> Date: Fri, 12 Mar 2010 11:45:00 +0530 Subject: [PATCH 2/2] Code improvement by stephane bzr revid: hda@tinyerp.com-20100312061500-540cpy0cbcwxmfbq --- bin/addons/__init__.py | 36 ++++++----- bin/addons/base/module/module.py | 11 +--- bin/addons/module_graph.py | 21 +++--- bin/tools/config.py | 8 ++- bin/tools/misc.py | 108 +++++++++++++++---------------- setup.py | 3 +- 6 files changed, 91 insertions(+), 96 deletions(-) diff --git a/bin/addons/__init__.py b/bin/addons/__init__.py index 4e939bf01dc..c5e73e7c709 100644 --- a/bin/addons/__init__.py +++ b/bin/addons/__init__.py @@ -221,7 +221,7 @@ def get_module_as_zip_from_module_directory(module_directory, b64enc=True, src=T base = os.path.basename(path) for f in tools.osutil.listdir(path, True): bf = os.path.basename(f) - if not RE_exclude.search(bf) and (src or bf == '__openerp__.py' or bf == '__terp__.py' or not bf.endswith('.py')): + if not RE_exclude.search(bf) and (src or bf in ('__openerp__.py', '__terp__.py') or not bf.endswith('.py')): archive.write(os.path.join(path, f), os.path.join(base, f)) archname = StringIO() @@ -294,15 +294,23 @@ def get_modules(): plist.extend(listdir(ad)) return list(set(plist)) +def load_information_from_description_file(module): + """ + :param module: The name of the module (sale, purchase, ...) + """ + for filename in ['__openerp__.py', '__terp__.py']: + description_file = addons.get_module_resource(module, filename) + if os.path.isfile(description_file): + return eval(tools.file_open(description_file).read()) + + raise Exception('The module %s does not contain a description file: __openerp__.py or __terp__.py (deprecated)') + def get_modules_with_version(): modules = get_modules() res = {} for module in modules: try: - terp = get_module_resource(module, '__openerp__.py') - if not os.path.isfile(terp): - terp = addons.get_module_resource(module, '__terp__.py') - info = eval(tools.file_open(terp).read()) + info = load_information_from_description_file(module) res[module] = "%s.%s" % (release.major_version, info['version']) except Exception, e: continue @@ -703,16 +711,14 @@ def load_modules(db, force_demo=False, status=None, update_module=False): status = {} cr = db.cursor() if cr: - cr.execute("SELECT relname FROM pg_class WHERE relkind='r' AND relname='ir_module_module'") - if len(cr.fetchall())==0: - logger.notifyChannel("init", netsvc.LOG_INFO, "init db") - tools.init_db(cr) -# cr.execute("update res_users set password=%s where id=%s",('admin',1)) - # in that case, force --init=all - tools.config["init"]["all"] = 1 - tools.config['update']['all'] = 1 - if not tools.config['without_demo']: - tools.config["demo"]['all'] = 1 + cr.execute("SELECT relname FROM pg_class WHERE relkind='r' AND relname='ir_module_module'") + if len(cr.fetchall())==0: + logger.notifyChannel("init", netsvc.LOG_INFO, "init db") + tools.init_db(cr) + tools.config["init"]["all"] = 1 + tools.config['update']['all'] = 1 + if not tools.config['without_demo']: + tools.config["demo"]['all'] = 1 force = [] if force_demo: force.append('demo') diff --git a/bin/addons/base/module/module.py b/bin/addons/base/module/module.py index faec4ffa9be..e11b4964471 100644 --- a/bin/addons/base/module/module.py +++ b/bin/addons/base/module/module.py @@ -64,18 +64,13 @@ class module(osv.osv): _description = "Module" def get_module_info(self, name): + info = {} try: - terp_file = addons.get_module_resource(name, '__openerp__.py') - if not os.path.isfile(terp_file): - terp_file = addons.get_module_resource(name, '__terp__.py') - f = tools.file_open(terp_file) - data = f.read() - info = eval(data) + info = addons.load_information_from_description_file(name) if 'version' in info: info['version'] = release.major_version + '.' + info['version'] - f.close() except: - return {} + pass return info def _get_latest_version(self, cr, uid, ids, field_name=None, arg=None, context={}): diff --git a/bin/addons/module_graph.py b/bin/addons/module_graph.py index e321592ccc7..edd7f6f947e 100755 --- a/bin/addons/module_graph.py +++ b/bin/addons/module_graph.py @@ -41,19 +41,14 @@ print 'digraph G {' while len(modules): f = modules.pop(0) done.append(f) - terp_file = os.path.join(f,"__openerp__.py") - if not os.path.isfile(terp_file): - terp_file = os.path.join(f,"__terp__.py") - - if os.path.isfile(terp_file): - info=eval(file(os.path.join(f,"__terp__.py")).read()) - if info.get('installable', True): - for name in info['depends']: - if name not in done+modules: - modules.append(name) - if not os.path.exists(name): - print '\t%s [color=red]' % (name,) - print '\t%s -> %s;' % (f, name) + info = addons.load_information_from_description_file(f) + if info.get('installable', True): + for name in info['depends']: + if name not in done+modules: + modules.append(name) + if not os.path.exists(name): + print '\t%s [color=red]' % (name,) + print '\t%s -> %s;' % (f, name) print '}' # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/bin/tools/config.py b/bin/tools/config.py index 57f0388a238..f814c3db6eb 100644 --- a/bin/tools/config.py +++ b/bin/tools/config.py @@ -352,11 +352,15 @@ class configmanager(object): res = os.path.abspath(os.path.expanduser(value)) if not os.path.exists(res): raise optparse.OptionValueError("option %s: no such directory: %r" % (opt, value)) + contains_addons = False for f in os.listdir(res): modpath = os.path.join(res, f) - if os.path.isdir(modpath) and os.path.exists(os.path.join(modpath, '__init__.py')) and \ - ('|', os.path.exists(os.path.join(modpath, '__openerp__.py')), os.path.exists(os.path.join(modpath, '__terp__.py'))): + if os.path.isdir(modpath) and \ + os.path.exists(os.path.join(modpath, '__init__.py')) and \ + (os.path.exists(os.path.join(modpath, '__openerp__.py')) or \ + os.path.exists(os.path.join(modpath, '__terp__.py'))): + contains_addons = True break diff --git a/bin/tools/misc.py b/bin/tools/misc.py index b153467a2a9..284324873de 100644 --- a/bin/tools/misc.py +++ b/bin/tools/misc.py @@ -50,69 +50,63 @@ def init_db(cr): cr.commit() for i in addons.get_modules(): - terp_file = addons.get_module_resource(i, '__openerp__.py') mod_path = addons.get_module_path(i) if not mod_path: continue - info = False -# if os.path.isfile(terp_file) or os.path.isfile(mod_path+'.zip'): -# info = eval(file_open(terp_file).read()) - if not os.path.isfile(terp_file): - terp_file = addons.get_module_resource(i, '__terp__.py') - if os.path.isfile(terp_file) or os.path.isfile(mod_path+'.zip'): - info = eval(file_open(terp_file).read()) + info = addons.load_information_from_description_file(i) - if info: - categs = info.get('category', 'Uncategorized').split('/') - p_id = None - while categs: - if p_id is not None: - cr.execute('select id \ - from ir_module_category \ - where name=%s and parent_id=%s', (categs[0], p_id)) - else: - cr.execute('select id \ - from ir_module_category \ - where name=%s and parent_id is NULL', (categs[0],)) - c_id = cr.fetchone() - if not c_id: - cr.execute('select nextval(\'ir_module_category_id_seq\')') - c_id = cr.fetchone()[0] - cr.execute('insert into ir_module_category \ - (id, name, parent_id) \ - values (%s, %s, %s)', (c_id, categs[0], p_id)) - else: - c_id = c_id[0] - p_id = c_id - categs = categs[1:] - - active = info.get('active', False) - installable = info.get('installable', True) - if installable: - if active: - state = 'to install' - else: - state = 'uninstalled' + if not info: + continue + categs = info.get('category', 'Uncategorized').split('/') + p_id = None + while categs: + if p_id is not None: + cr.execute('select id \ + from ir_module_category \ + where name=%s and parent_id=%s', (categs[0], p_id)) else: - state = 'uninstallable' - cr.execute('select nextval(\'ir_module_module_id_seq\')') - id = cr.fetchone()[0] - cr.execute('insert into ir_module_module \ - (id, author, website, name, shortdesc, description, \ - category_id, state, certificate) \ - values (%s, %s, %s, %s, %s, %s, %s, %s, %s)', ( - id, info.get('author', ''), - info.get('website', ''), i, info.get('name', False), - info.get('description', ''), p_id, state, info.get('certificate'))) - cr.execute('insert into ir_model_data \ - (name,model,module, res_id, noupdate) values (%s,%s,%s,%s,%s)', ( - 'module_meta_information', 'ir.module.module', i, id, True)) - dependencies = info.get('depends', []) - for d in dependencies: - cr.execute('insert into ir_module_module_dependency \ - (module_id,name) values (%s, %s)', (id, d)) - cr.commit() + cr.execute('select id \ + from ir_module_category \ + where name=%s and parent_id is NULL', (categs[0],)) + c_id = cr.fetchone() + if not c_id: + cr.execute('select nextval(\'ir_module_category_id_seq\')') + c_id = cr.fetchone()[0] + cr.execute('insert into ir_module_category \ + (id, name, parent_id) \ + values (%s, %s, %s)', (c_id, categs[0], p_id)) + else: + c_id = c_id[0] + p_id = c_id + categs = categs[1:] + + active = info.get('active', False) + installable = info.get('installable', True) + if installable: + if active: + state = 'to install' + else: + state = 'uninstalled' + else: + state = 'uninstallable' + cr.execute('select nextval(\'ir_module_module_id_seq\')') + id = cr.fetchone()[0] + cr.execute('insert into ir_module_module \ + (id, author, website, name, shortdesc, description, \ + category_id, state, certificate) \ + values (%s, %s, %s, %s, %s, %s, %s, %s, %s)', ( + id, info.get('author', ''), + info.get('website', ''), i, info.get('name', False), + info.get('description', ''), p_id, state, info.get('certificate'))) + cr.execute('insert into ir_model_data \ + (name,model,module, res_id, noupdate) values (%s,%s,%s,%s,%s)', ( + 'module_meta_information', 'ir.module.module', i, id, True)) + dependencies = info.get('depends', []) + for d in dependencies: + cr.execute('insert into ir_module_module_dependency \ + (module_id,name) values (%s, %s)', (id, d)) + cr.commit() def find_in_path(name): if os.name == "nt": diff --git a/setup.py b/setup.py index bc2d8b64d3f..2e004e713df 100755 --- a/setup.py +++ b/setup.py @@ -77,7 +77,7 @@ def check_modules(): def find_addons(): for root, _, names in os.walk(join('bin', 'addons')): - if '__openerp__.py' or '__terp__.py' in names: + if '__openerp__.py' in names or '__terp__.py' in names: yield basename(root), root #look for extra modules try: @@ -86,6 +86,7 @@ def find_addons(): mname = mname.strip() if not mname: continue + terp = join(empath, mname, '__openerp__.py') if not os.path.exists(terp): terp = join(empath, mname, '__terp__.py')