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)
|
base = os.path.basename(path)
|
||||||
for f in tools.osutil.listdir(path, True):
|
for f in tools.osutil.listdir(path, True):
|
||||||
bf = os.path.basename(f)
|
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))
|
archive.write(os.path.join(path, f), os.path.join(base, f))
|
||||||
|
|
||||||
archname = StringIO()
|
archname = StringIO()
|
||||||
|
@ -294,15 +294,23 @@ def get_modules():
|
||||||
plist.extend(listdir(ad))
|
plist.extend(listdir(ad))
|
||||||
return list(set(plist))
|
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():
|
def get_modules_with_version():
|
||||||
modules = get_modules()
|
modules = get_modules()
|
||||||
res = {}
|
res = {}
|
||||||
for module in modules:
|
for module in modules:
|
||||||
try:
|
try:
|
||||||
terp = get_module_resource(module, '__openerp__.py')
|
info = load_information_from_description_file(module)
|
||||||
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'])
|
res[module] = "%s.%s" % (release.major_version, info['version'])
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
continue
|
continue
|
||||||
|
@ -703,16 +711,14 @@ def load_modules(db, force_demo=False, status=None, update_module=False):
|
||||||
status = {}
|
status = {}
|
||||||
cr = db.cursor()
|
cr = db.cursor()
|
||||||
if cr:
|
if cr:
|
||||||
cr.execute("SELECT relname FROM pg_class WHERE relkind='r' AND relname='ir_module_module'")
|
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")
|
logger.notifyChannel("init", netsvc.LOG_INFO, "init db")
|
||||||
tools.init_db(cr)
|
tools.init_db(cr)
|
||||||
# cr.execute("update res_users set password=%s where id=%s",('admin',1))
|
tools.config["init"]["all"] = 1
|
||||||
# in that case, force --init=all
|
tools.config['update']['all'] = 1
|
||||||
tools.config["init"]["all"] = 1
|
if not tools.config['without_demo']:
|
||||||
tools.config['update']['all'] = 1
|
tools.config["demo"]['all'] = 1
|
||||||
if not tools.config['without_demo']:
|
|
||||||
tools.config["demo"]['all'] = 1
|
|
||||||
force = []
|
force = []
|
||||||
if force_demo:
|
if force_demo:
|
||||||
force.append('demo')
|
force.append('demo')
|
||||||
|
|
|
@ -64,18 +64,13 @@ class module(osv.osv):
|
||||||
_description = "Module"
|
_description = "Module"
|
||||||
|
|
||||||
def get_module_info(self, name):
|
def get_module_info(self, name):
|
||||||
|
info = {}
|
||||||
try:
|
try:
|
||||||
terp_file = addons.get_module_resource(name, '__openerp__.py')
|
info = addons.load_information_from_description_file(name)
|
||||||
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:
|
if 'version' in info:
|
||||||
info['version'] = release.major_version + '.' + info['version']
|
info['version'] = release.major_version + '.' + info['version']
|
||||||
f.close()
|
|
||||||
except:
|
except:
|
||||||
return {}
|
pass
|
||||||
return info
|
return info
|
||||||
|
|
||||||
def _get_latest_version(self, cr, uid, ids, field_name=None, arg=None, context={}):
|
def _get_latest_version(self, cr, uid, ids, field_name=None, arg=None, context={}):
|
||||||
|
|
|
@ -41,19 +41,14 @@ print 'digraph G {'
|
||||||
while len(modules):
|
while len(modules):
|
||||||
f = modules.pop(0)
|
f = modules.pop(0)
|
||||||
done.append(f)
|
done.append(f)
|
||||||
terp_file = os.path.join(f,"__openerp__.py")
|
info = addons.load_information_from_description_file(f)
|
||||||
if not os.path.isfile(terp_file):
|
if info.get('installable', True):
|
||||||
terp_file = os.path.join(f,"__terp__.py")
|
for name in info['depends']:
|
||||||
|
if name not in done+modules:
|
||||||
if os.path.isfile(terp_file):
|
modules.append(name)
|
||||||
info=eval(file(os.path.join(f,"__terp__.py")).read())
|
if not os.path.exists(name):
|
||||||
if info.get('installable', True):
|
print '\t%s [color=red]' % (name,)
|
||||||
for name in info['depends']:
|
print '\t%s -> %s;' % (f, name)
|
||||||
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 '}'
|
print '}'
|
||||||
|
|
||||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||||
|
|
|
@ -352,11 +352,15 @@ class configmanager(object):
|
||||||
res = os.path.abspath(os.path.expanduser(value))
|
res = os.path.abspath(os.path.expanduser(value))
|
||||||
if not os.path.exists(res):
|
if not os.path.exists(res):
|
||||||
raise optparse.OptionValueError("option %s: no such directory: %r" % (opt, value))
|
raise optparse.OptionValueError("option %s: no such directory: %r" % (opt, value))
|
||||||
|
|
||||||
contains_addons = False
|
contains_addons = False
|
||||||
for f in os.listdir(res):
|
for f in os.listdir(res):
|
||||||
modpath = os.path.join(res, f)
|
modpath = os.path.join(res, f)
|
||||||
if os.path.isdir(modpath) and os.path.exists(os.path.join(modpath, '__init__.py')) and \
|
if os.path.isdir(modpath) and \
|
||||||
('|', os.path.exists(os.path.join(modpath, '__openerp__.py')), os.path.exists(os.path.join(modpath, '__terp__.py'))):
|
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
|
contains_addons = True
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
|
@ -50,69 +50,63 @@ def init_db(cr):
|
||||||
cr.commit()
|
cr.commit()
|
||||||
|
|
||||||
for i in addons.get_modules():
|
for i in addons.get_modules():
|
||||||
terp_file = addons.get_module_resource(i, '__openerp__.py')
|
|
||||||
mod_path = addons.get_module_path(i)
|
mod_path = addons.get_module_path(i)
|
||||||
if not mod_path:
|
if not mod_path:
|
||||||
continue
|
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 = addons.load_information_from_description_file(i)
|
||||||
info = eval(file_open(terp_file).read())
|
|
||||||
|
|
||||||
if info:
|
if not info:
|
||||||
categs = info.get('category', 'Uncategorized').split('/')
|
continue
|
||||||
p_id = None
|
categs = info.get('category', 'Uncategorized').split('/')
|
||||||
while categs:
|
p_id = None
|
||||||
if p_id is not None:
|
while categs:
|
||||||
cr.execute('select id \
|
if p_id is not None:
|
||||||
from ir_module_category \
|
cr.execute('select id \
|
||||||
where name=%s and parent_id=%s', (categs[0], p_id))
|
from ir_module_category \
|
||||||
else:
|
where name=%s and parent_id=%s', (categs[0], p_id))
|
||||||
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:
|
else:
|
||||||
state = 'uninstallable'
|
cr.execute('select id \
|
||||||
cr.execute('select nextval(\'ir_module_module_id_seq\')')
|
from ir_module_category \
|
||||||
id = cr.fetchone()[0]
|
where name=%s and parent_id is NULL', (categs[0],))
|
||||||
cr.execute('insert into ir_module_module \
|
c_id = cr.fetchone()
|
||||||
(id, author, website, name, shortdesc, description, \
|
if not c_id:
|
||||||
category_id, state, certificate) \
|
cr.execute('select nextval(\'ir_module_category_id_seq\')')
|
||||||
values (%s, %s, %s, %s, %s, %s, %s, %s, %s)', (
|
c_id = cr.fetchone()[0]
|
||||||
id, info.get('author', ''),
|
cr.execute('insert into ir_module_category \
|
||||||
info.get('website', ''), i, info.get('name', False),
|
(id, name, parent_id) \
|
||||||
info.get('description', ''), p_id, state, info.get('certificate')))
|
values (%s, %s, %s)', (c_id, categs[0], p_id))
|
||||||
cr.execute('insert into ir_model_data \
|
else:
|
||||||
(name,model,module, res_id, noupdate) values (%s,%s,%s,%s,%s)', (
|
c_id = c_id[0]
|
||||||
'module_meta_information', 'ir.module.module', i, id, True))
|
p_id = c_id
|
||||||
dependencies = info.get('depends', [])
|
categs = categs[1:]
|
||||||
for d in dependencies:
|
|
||||||
cr.execute('insert into ir_module_module_dependency \
|
active = info.get('active', False)
|
||||||
(module_id,name) values (%s, %s)', (id, d))
|
installable = info.get('installable', True)
|
||||||
cr.commit()
|
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):
|
def find_in_path(name):
|
||||||
if os.name == "nt":
|
if os.name == "nt":
|
||||||
|
|
3
setup.py
3
setup.py
|
@ -77,7 +77,7 @@ def check_modules():
|
||||||
|
|
||||||
def find_addons():
|
def find_addons():
|
||||||
for root, _, names in os.walk(join('bin', '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
|
yield basename(root), root
|
||||||
#look for extra modules
|
#look for extra modules
|
||||||
try:
|
try:
|
||||||
|
@ -86,6 +86,7 @@ def find_addons():
|
||||||
mname = mname.strip()
|
mname = mname.strip()
|
||||||
if not mname:
|
if not mname:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
terp = join(empath, mname, '__openerp__.py')
|
terp = join(empath, mname, '__openerp__.py')
|
||||||
if not os.path.exists(terp):
|
if not os.path.exists(terp):
|
||||||
terp = join(empath, mname, '__terp__.py')
|
terp = join(empath, mname, '__terp__.py')
|
||||||
|
|
Loading…
Reference in New Issue