[ADD]:suppot for __openerp__.py or __terp__.py

bzr revid: rvo@tinyerp.co.in-20100311084941-1l92enpyz1a98hrr
This commit is contained in:
Rvo (Open ERP) 2010-03-11 14:19:41 +05:30
parent 0dfa91ac8a
commit 587828161d
6 changed files with 54 additions and 30 deletions

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
##############################################################################
#
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
@ -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 <http://www.gnu.org/licenses/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
@ -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

View File

@ -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:

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
##############################################################################
#
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
@ -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 <http://www.gnu.org/licenses/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
@ -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']:

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
##############################################################################
#
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
@ -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 <http://www.gnu.org/licenses/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
@ -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])

View File

@ -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

View File

@ -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