Skip to content

Commit

Permalink
Merge branch 'official-trunk' into deb-scripts
Browse files Browse the repository at this point in the history
bzr revid: p_christ@hol.gr-20110117094021-rbjm55dip17tnuy4
  • Loading branch information
xrg committed Jan 17, 2011
2 parents 4f4164b + acc5c03 commit 3aed57e
Show file tree
Hide file tree
Showing 205 changed files with 265,286 additions and 124,156 deletions.
3 changes: 3 additions & 0 deletions .bzrignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ bin/python2.6
build/
bin/yolk
bin/pil*.py
.project
.pydevproject
.settings
8 changes: 8 additions & 0 deletions bin/agpl.txt → LICENSE
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
OpenERP v6.0 is published under the GNU AFFERO GENERAL PUBLIC LICENSE,
Version 3 (AGPLv3), as included below. Some external libraries and
contributions bundled with OpenERP may be published under other
AGPLv3-compatible licenses. For these, please refer to the relevant
source files and/or license files, in the source code tree.

**************************************************************************

GNU AFFERO GENERAL PUBLIC LICENSE
Version 3, 19 November 2007

Expand Down
175 changes: 108 additions & 67 deletions bin/addons/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
# Copyright (C) 2010 OpenERP s.a. (<http://openerp.com>).
# Copyright (C) 2010-2011 OpenERP s.a. (<http://openerp.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
Expand All @@ -30,7 +30,7 @@
import tools.osutil
from tools.safe_eval import safe_eval as eval
import pooler

from tools.translate import _

import netsvc

Expand All @@ -47,8 +47,8 @@

logger = netsvc.Logger()

_ad = os.path.abspath(opj(tools.config['root_path'], 'addons')) # default addons path (base)
ad_paths= map(lambda m: os.path.abspath(m.strip()),tools.config['addons_path'].split(','))
_ad = os.path.abspath(opj(tools.ustr(tools.config['root_path']), u'addons')) # default addons path (base)
ad_paths= map(lambda m: os.path.abspath(tools.ustr(m.strip())), tools.config['addons_path'].split(','))

sys.path.insert(1, _ad)

Expand Down Expand Up @@ -225,6 +225,10 @@ def _zippy(archive, path, src=True):

archname = StringIO()
archive = PyZipFile(archname, "w", ZIP_DEFLATED)

# for Python 2.5, ZipFile.write() still expects 8-bit strings (2.6 converts to utf-8)
directory = tools.ustr(directory).encode('utf-8')

archive.writepy(directory)
_zippy(archive, directory, src=src)
archive.close()
Expand Down Expand Up @@ -270,19 +274,18 @@ def get_module_resource(module, *args):
@return: absolute path to the resource
"""
a = get_module_path(module)
res = a and opj(a, *args) or False
if not a: return False
resource_path = opj(a, *args)
if zipfile.is_zipfile( a +'.zip') :
zip = zipfile.ZipFile( a + ".zip")
files = ['/'.join(f.split('/')[1:]) for f in zip.namelist()]
res = '/'.join(args)
if res in files:
return opj(a, res)
elif os.path.isfile(res):
return res
resource_path = '/'.join(args)
if resource_path in files:
return opj(a, resource_path)
elif os.path.exists(resource_path):
return resource_path
return False



def get_modules():
"""Returns the list of module names
"""
Expand Down Expand Up @@ -311,7 +314,11 @@ def load_information_from_description_file(module):
for filename in ['__openerp__.py', '__terp__.py']:
description_file = get_module_resource(module, filename)
if description_file :
return eval(tools.file_open(description_file).read())
desc_f = tools.file_open(description_file)
try:
return eval(desc_f.read())
finally:
desc_f.close()

#TODO: refactor the logger in this file to follow the logging guidelines
# for 6.0
Expand Down Expand Up @@ -350,11 +357,14 @@ def upgrade_graph(graph, cr, module_list, force=None):
continue

if os.path.isfile(terp_file) or zipfile.is_zipfile(mod_path+'.zip'):
terp_f = tools.file_open(terp_file)
try:
info = eval(tools.file_open(terp_file).read())
except:
info = eval(terp_f.read())
except Exception:
logger.notifyChannel('init', netsvc.LOG_ERROR, 'module %s: eval file %s' % (module, terp_file))
raise
finally:
terp_f.close()
if info.get('installable', True):
packages.append((module, info.get('depends', []), info))
else:
Expand Down Expand Up @@ -598,8 +608,15 @@ def mergedict(a, b):

log = logging.getLogger('init')

def load_module_graph(cr, graph, status=None, perform_checks=True, **kwargs):

def load_module_graph(cr, graph, status=None, perform_checks=True, skip_modules=None, **kwargs):
"""Migrates+Updates or Installs all module nodes from ``graph``
:param graph: graph of module nodes to load
:param status: status dictionary for keeping track of progress
:param perform_checks: whether module descriptors should be checked for validity (prints warnings
for same cases, and even raise osv_except if certificate is invalid)
:param skip_modules: optional list of module names (packages) which have previously been loaded and can be skipped
:return: list of modules that were installed or updated
"""
def process_sql_file(cr, fp):
queries = fp.read().split(';')
for query in queries:
Expand All @@ -612,29 +629,33 @@ def load_init_update_xml(cr, m, idref, mode, kind):
logger.notifyChannel('init', netsvc.LOG_INFO, 'module %s: loading %s' % (m, filename))
_, ext = os.path.splitext(filename)
fp = tools.file_open(opj(m, filename))
if ext == '.csv':
noupdate = (kind == 'init')
tools.convert_csv_import(cr, m, os.path.basename(filename), fp.read(), idref, mode=mode, noupdate=noupdate)
elif ext == '.sql':
process_sql_file(cr, fp)
elif ext == '.yml':
tools.convert_yaml_import(cr, m, fp, idref, mode=mode, **kwargs)
else:
tools.convert_xml_import(cr, m, fp, idref, mode=mode, **kwargs)
fp.close()
try:
if ext == '.csv':
noupdate = (kind == 'init')
tools.convert_csv_import(cr, m, os.path.basename(filename), fp.read(), idref, mode=mode, noupdate=noupdate)
elif ext == '.sql':
process_sql_file(cr, fp)
elif ext == '.yml':
tools.convert_yaml_import(cr, m, fp, idref, mode=mode, **kwargs)
else:
tools.convert_xml_import(cr, m, fp, idref, mode=mode, **kwargs)
finally:
fp.close()

def load_demo_xml(cr, m, idref, mode):
for xml in package.data.get('demo_xml', []):
name, ext = os.path.splitext(xml)
logger.notifyChannel('init', netsvc.LOG_INFO, 'module %s: loading %s' % (m, xml))
fp = tools.file_open(opj(m, xml))
if ext == '.csv':
tools.convert_csv_import(cr, m, os.path.basename(xml), fp.read(), idref, mode=mode, noupdate=True)
elif ext == '.yml':
tools.convert_yaml_import(cr, m, fp, idref, mode=mode, noupdate=True, **kwargs)
else:
tools.convert_xml_import(cr, m, fp, idref, mode=mode, noupdate=True, **kwargs)
fp.close()
try:
if ext == '.csv':
tools.convert_csv_import(cr, m, os.path.basename(xml), fp.read(), idref, mode=mode, noupdate=True)
elif ext == '.yml':
tools.convert_yaml_import(cr, m, fp, idref, mode=mode, noupdate=True, **kwargs)
else:
tools.convert_xml_import(cr, m, fp, idref, mode=mode, noupdate=True, **kwargs)
finally:
fp.close()

def load_data(cr, module_name, id_map, mode):
_load_data(cr, module_name, id_map, mode, 'data')
Expand All @@ -648,50 +669,48 @@ def load_test(cr, module_name, id_map, mode):
try:
_load_data(cr, module_name, id_map, mode, 'test')
except Exception, e:
logger.notifyChannel('ERROR', netsvc.LOG_TEST, e)
pass
logging.getLogger('test').exception('Tests failed to execute in module %s', module_name)
finally:
if tools.config.options['test_commit']:
cr.commit()
else:
cr.rollback()

def _load_data(cr, module_name, id_map, mode, kind):
noupdate = (kind == 'demo')
for filename in package.data.get(kind, []):
noupdate = (kind == 'demo')
_, ext = os.path.splitext(filename)
log.info("module %s: loading %s", module_name, filename)
pathname = os.path.join(module_name, filename)
file = tools.file_open(pathname)
# TODO manage .csv file with noupdate == (kind == 'init')
if ext == '.sql':
process_sql_file(cr, file)
elif ext == '.csv':
noupdate = (kind == 'init')
tools.convert_csv_import(cr, module_name, pathname, file.read(), id_map, mode, noupdate)
elif ext == '.yml':
tools.convert_yaml_import(cr, module_name, file, id_map, mode, noupdate)
else:
tools.convert_xml_import(cr, module_name, file, id_map, mode, noupdate)
file.close()
try:
if ext == '.sql':
process_sql_file(cr, file)
elif ext == '.csv':
noupdate = (kind == 'init')
tools.convert_csv_import(cr, module_name, pathname, file.read(), id_map, mode, noupdate)
elif ext == '.yml':
tools.convert_yaml_import(cr, module_name, file, id_map, mode, noupdate)
else:
tools.convert_xml_import(cr, module_name, file, id_map, mode, noupdate)
finally:
file.close()

# **kwargs is passed directly to convert_xml_import
if not status:
status = {}

status = status.copy()
package_todo = []
processed_modules = []
statusi = 0
pool = pooler.get_pool(cr.dbname)

migrations = MigrationManager(cr, graph)

has_updates = False
modobj = None

logger.notifyChannel('init', netsvc.LOG_DEBUG, 'loading %d packages..' % len(graph))

for package in graph:
if skip_modules and package.name in skip_modules:
continue
logger.notifyChannel('init', netsvc.LOG_INFO, 'module %s: loading objects' % package.name)
migrations.migrate_module(package, 'pre')
register_class(package.name)
Expand All @@ -705,6 +724,9 @@ def _load_data(cr, module_name, id_map, mode, kind):
m = package.name
mid = package.id

if skip_modules and m in skip_modules:
continue

if modobj is None:
modobj = pool.get('ir.module.module')

Expand All @@ -719,7 +741,6 @@ def _load_data(cr, module_name, id_map, mode, kind):
mode = 'init'

if hasattr(package, 'init') or hasattr(package, 'update') or package.state in ('to install', 'to upgrade'):
has_updates = True
for kind in ('init', 'update'):
if package.state=='to upgrade':
# upgrading the module information
Expand All @@ -738,7 +759,7 @@ def _load_data(cr, module_name, id_map, mode, kind):
# as there is no rollback.
load_test(cr, m, idref, mode)

package_todo.append(package.name)
processed_modules.append(package.name)

migrations.migrate_module(package, 'post')

Expand All @@ -758,14 +779,9 @@ def _load_data(cr, module_name, id_map, mode, kind):

statusi += 1

cr.execute('select model from ir_model where state=%s', ('manual',))
for model in cr.dictfetchall():
pool.get('ir.model').instanciate(cr, 1, model['model'], {})

pool.get('ir.model.data')._process_end(cr, 1, package_todo)
cr.commit()

return has_updates
return processed_modules

def _check_module_names(cr, module_names):
mod_names = set(module_names)
Expand Down Expand Up @@ -797,17 +813,30 @@ def load_modules(db, force_demo=False, status=None, update_module=False):
force = []
if force_demo:
force.append('demo')

# This is a brand new pool, just created in pooler.get_db_and_pool()
pool = pooler.get_pool(cr.dbname)

try:
processed_modules = []
report = tools.assertion_report()
# NOTE: Try to also load the modules that have been marked as uninstallable previously...
STATES_TO_LOAD = ['installed', 'to upgrade', 'uninstallable']
if 'base' in tools.config['update'] or 'all' in tools.config['update']:
cr.execute("update ir_module_module set state=%s where name=%s and state=%s", ('to upgrade', 'base', 'installed'))

# STEP 1: LOAD BASE (must be done before module dependencies can be computed for later steps)
graph = create_graph(cr, ['base'], force)
if not graph:
logger.notifyChannel('init', netsvc.LOG_CRITICAL, 'module base cannot be loaded! (hint: verify addons-path)')
raise osv.osv.except_osv('Could not load base module', 'module base cannot be loaded! (hint: verify addons-path)')
has_updates = load_module_graph(cr, graph, status, perform_checks=(not update_module), report=report)
raise osv.osv.except_osv(_('Could not load base module'), _('module base cannot be loaded! (hint: verify addons-path)'))
processed_modules.extend(load_module_graph(cr, graph, status, perform_checks=(not update_module), report=report))

if tools.config['load_language']:
for lang in tools.config['load_language'].split(','):
tools.load_language(cr, lang)

# STEP 2: Mark other modules to be loaded/updated
if update_module:
modobj = pool.get('ir.module.module')
logger.notifyChannel('init', netsvc.LOG_INFO, 'updating modules list')
Expand All @@ -832,6 +861,8 @@ def load_modules(db, force_demo=False, status=None, update_module=False):

STATES_TO_LOAD += ['to install']


# STEP 3: Load marked modules (skipping base which was done in STEP 1)
loop_guardrail = 0
while True:
loop_guardrail += 1
Expand All @@ -849,14 +880,19 @@ def load_modules(db, force_demo=False, status=None, update_module=False):
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
processed_modules.extend(load_module_graph(cr, graph, status, report=report, skip_modules=processed_modules))

# STEP 4: Finish and cleanup
if processed_modules:
# load custom models
cr.execute('select model from ir_model where state=%s', ('manual',))
for model in cr.dictfetchall():
pool.get('ir.model').instanciate(cr, 1, model['model'], {})

if has_updates:
cr.execute("""select model,name from ir_model where id NOT IN (select distinct model_id from ir_model_access)""")
for (model, name) in cr.fetchall():
model_obj = pool.get(model)
if not isinstance(model_obj, osv.osv.osv_memory):
if model_obj and not isinstance(model_obj, osv.osv.osv_memory):
logger.notifyChannel('init', netsvc.LOG_WARNING, 'object %s (%s) has no access rules!' % (model, name))

# Temporary warning while we remove access rights on osv_memory objects, as they have
Expand All @@ -872,6 +908,11 @@ def load_modules(db, force_demo=False, status=None, update_module=False):
obj = pool.get(model)
if obj:
obj._check_removed_columns(cr, log=True)
else:
logger.notifyChannel('init', netsvc.LOG_WARNING, "Model %s is referenced but not present in the orm pool!" % model)

# Cleanup orphan records
pool.get('ir.model.data')._process_end(cr, 1, processed_modules)

if report.get_report():
logger.notifyChannel('init', netsvc.LOG_INFO, report)
Expand Down
2 changes: 1 addition & 1 deletion bin/addons/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import ir
import module
import res
import maintenance
import publisher_warranty

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

Loading

0 comments on commit 3aed57e

Please sign in to comment.