bzr revid: stephane@openerp.com-20100312105803-zytgew4zwwo3kzr6
This commit is contained in:
Stephane Wirtel
2010-03-12 11:58:03 +01:00
6 changed files with 121 additions and 102 deletions
+34 -22
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 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,13 +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:
terp = get_module_resource(module, '__terp__.py')
try:
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
@@ -318,13 +328,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 +351,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 +392,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 +602,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 +611,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
@@ -697,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')
@@ -716,7 +728,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 +772,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
+3 -5
View File
@@ -64,15 +64,13 @@ class module(osv.osv):
_description = "Module"
def get_module_info(self, name):
info = {}
try:
f = tools.file_open(os.path.join(name, '__terp__.py'))
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={}):
+12 -12
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,15 +41,14 @@ print 'digraph G {'
while len(modules):
f = modules.pop(0)
done.append(f)
if os.path.isfile(os.path.join(f,"__terp__.py")):
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:
+13 -9
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'])
@@ -352,17 +352,21 @@ 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, '__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
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 +407,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])
+52 -52
View File
@@ -50,63 +50,63 @@ def init_db(cr):
cr.commit()
for i in addons.get_modules():
terp_file = addons.get_module_resource(i, '__terp__.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 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'
info = addons.load_information_from_description_file(i)
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":
+7 -2
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' in names or '__terp__.py' in names:
yield basename(root), root
#look for extra modules
try:
@@ -86,7 +86,12 @@ 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