Code improvement by stephane
bzr revid: hda@tinyerp.com-20100312061500-540cpy0cbcwxmfbq
This commit is contained in:
parent
587828161d
commit
23586fb331
|
@ -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')
|
||||
|
|
|
@ -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={}):
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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":
|
||||
|
|
3
setup.py
3
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')
|
||||
|
|
Loading…
Reference in New Issue