Change addons into modules

This commit is contained in:
Cédric Krier
2008-01-27 23:55:22 +01:00
parent 358fd67ad3
commit a5fe147aba
8 changed files with 34 additions and 34 deletions
+9 -9
View File
@@ -6,7 +6,7 @@ import urllib
import zipimport
from trytond.osv import fields, OSV
import trytond.tools as tools
from trytond.module import ADDONS_PATH
from trytond.module import MODULES_PATH
from trytond.osv.orm import ExceptORM
from trytond.wizard import Wizard, WizardOSV
from trytond.pooler import get_db, restart_pool
@@ -131,7 +131,7 @@ class Module(OSV):
def get_module_info(name):
"Return the content of the __tryton__.py"
try:
file_p = tools.file_open(os.path.join(ADDONS_PATH, name,
file_p = tools.file_open(os.path.join(MODULES_PATH, name,
'__tryton__.py'))
data = file_p.read()
info = eval(data)
@@ -301,7 +301,7 @@ class Module(OSV):
files = Module.get_module_info(module.name).get('translations', {})
for lang in langs:
if files.has_key(lang.code):
filepath = os.path.join(ADDONS_PATH, module.name,
filepath = os.path.join(MODULES_PATH, module.name,
files[lang.code])
tools.trans_load(filepath, lang.code)
return True
@@ -312,7 +312,7 @@ class Module(OSV):
res = [0, 0] # [update, add]
# iterate through installed modules and mark them as being so
for name in os.listdir(ADDONS_PATH):
for name in os.listdir(MODULES_PATH):
mod_name = name
if name[-4:] == '.zip':
mod_name = name[:-4]
@@ -345,7 +345,7 @@ class Module(OSV):
self._update_category(cursor, user, module_id,
tryton.get('category', 'None'))
continue
mod_path = os.path.join(ADDONS_PATH, name)
mod_path = os.path.join(MODULES_PATH, name)
if os.path.isdir(mod_path) \
or os.path.islink(mod_path) \
or zipfile.is_zipfile(mod_path):
@@ -353,13 +353,13 @@ class Module(OSV):
if not tryton or not tryton.get('installable', True):
continue
if not os.path.isfile(
os.path.join(ADDONS_PATH, mod_name+'.zip')):
os.path.join(MODULES_PATH, mod_name+'.zip')):
import imp
# XXX must restrict to only addons paths
# XXX must restrict to only modules paths
imp.load_module(name, *imp.find_module(mod_name))
else:
import zipimport
mod_path = os.path.join(ADDONS_PATH, mod_name+'.zip')
mod_path = os.path.join(MODULES_PATH, mod_name+'.zip')
zimp = zipimport.zipimporter(mod_path)
zimp.load_module(mod_name)
new_id = self.create(cursor, user, {
@@ -442,7 +442,7 @@ class Module(OSV):
if not download:
continue
zip_file = urllib.urlopen(mod.url).read()
fname = os.path.join(ADDONS_PATH, mod.name+'.zip')
fname = os.path.join(MODULES_PATH, mod.name+'.zip')
try:
file_p = file(fname, 'wb')
file_p.write(zip_file)
+1 -1
View File
@@ -105,7 +105,7 @@
<field name="arch" type="xml">
<![CDATA[
<form string="Update Module List">
<label string="This function will check for new modules in the 'addons' path and on module repositories:"
<label string="This function will check for new modules in the 'modules' path and on module repositories:"
colspan="4" align="0.0"/>
<field name="repositories" colspan="4" nolabel="1"/>
</form>
+14 -14
View File
@@ -8,8 +8,8 @@ from netsvc import Logger, LOG_ERROR, LOG_INFO
import zipfile
OPJ = os.path.join
ADDONS_PATH = OPJ(os.path.dirname(__file__), 'addons')
sys.path.insert(1, ADDONS_PATH)
MODULES_PATH = OPJ(os.path.dirname(__file__), 'modules')
sys.path.insert(1, MODULES_PATH)
class Graph(dict):
@@ -106,8 +106,8 @@ def create_graph(module_list, force=None):
for module in module_list:
if module[-4:] == '.zip':
module = module[:-4]
tryton_file = OPJ(ADDONS_PATH, module, '__tryton__.py')
mod_path = OPJ(ADDONS_PATH, module)
tryton_file = OPJ(MODULES_PATH, module, '__tryton__.py')
mod_path = OPJ(MODULES_PATH, module)
if module in ('ir', 'workflow', 'res'):
root_path = os.path.dirname(__file__)
tryton_file = OPJ(root_path, module, '__tryton__.py')
@@ -117,7 +117,7 @@ def create_graph(module_list, force=None):
info = eval(tools.file_open(tryton_file).read())
except:
Logger().notify_channel('init', LOG_ERROR,
'addon:%s:eval file %s' % (module, tryton_file))
'module:%s:eval file %s' % (module, tryton_file))
raise
if info.get('installable', True):
packages.append((module, info.get('depends', []), info))
@@ -149,12 +149,12 @@ def create_graph(module_list, force=None):
for package in later:
Logger().notify_channel('init', LOG_ERROR,
'addon:%s:Unmet dependency' % package)
'module:%s:Unmet dependency' % package)
return graph
def init_module_objects(cursor, module_name, obj_list):
Logger().notify_channel('init', LOG_INFO,
'addon:%s:creating or updating database tables' % module_name)
'module:%s:creating or updating database tables' % module_name)
for obj in obj_list:
obj.auto_init(cursor)
@@ -164,7 +164,7 @@ def load_module_graph(cursor, graph):
statusi = 0
for package in graph:
module = package.name
Logger().notify_channel('init', LOG_INFO, 'addon:%s' % module)
Logger().notify_channel('init', LOG_INFO, 'module:%s' % module)
sys.stdout.flush()
pool = pooler.get_pool(cursor.dbname)
modules = pool.instanciate(module)
@@ -188,7 +188,7 @@ def load_module_graph(cursor, graph):
if hasattr(package, 'init') or package_state=='to install':
mode = 'init'
Logger().notify_channel('init', LOG_INFO,
'addon:%s:loading %s' % (module, filename))
'module:%s:loading %s' % (module, filename))
ext = os.path.splitext(filename)[1]
if ext == '.csv':
tools.convert_csv_import(cursor, module,
@@ -222,7 +222,7 @@ def load_module_graph(cursor, graph):
cursor.commit()
def register_classes():
module_list = os.listdir(ADDONS_PATH)
module_list = os.listdir(MODULES_PATH)
module_list.append('ir')
module_list.append('workflow')
module_list.append('res')
@@ -232,18 +232,18 @@ def register_classes():
for package in create_graph(module_list):
module = package.name
Logger().notify_channel('init', LOG_INFO,
'addon:%s:registering classes' % module)
'module:%s:registering classes' % module)
sys.stdout.flush()
if module in ('ir', 'workflow', 'res'):
continue
if not os.path.isfile(OPJ(ADDONS_PATH, module+'.zip')):
# XXX must restrict to only addons paths
if not os.path.isfile(OPJ(MODULES_PATH, module+'.zip')):
# XXX must restrict to only modules paths
imp.load_module(module, *imp.find_module(module))
else:
import zipimport
mod_path = OPJ(ADDONS_PATH, module+'.zip')
mod_path = OPJ(MODULES_PATH, module+'.zip')
try:
zimp = zipimport.zipimporter(mod_path)
zimp.load_module(module)
+1 -1
View File
@@ -155,7 +155,7 @@ class OSV(ORM):
def __new__(cls):
for module in cls.__module__.split('.'):
if module != 'trytond' and module != 'addons':
if module != 'trytond' and module != 'modules':
break
if not hasattr(cls, '_module'):
cls._module = module
+1 -1
View File
@@ -166,7 +166,7 @@ class Report(object):
def __new__(cls):
for module in cls.__module__.split('.'):
if module != 'trytond' and module != 'addons':
if module != 'trytond' and module != 'modules':
break
if not hasattr(cls, '_module'):
cls._module = module
+5 -5
View File
@@ -113,18 +113,18 @@ def init_db(cursor):
cursor.execute(line)
opj = os.path.join
addons_path = os.path.join(os.path.dirname(__file__), 'addons')
modules_path = os.path.join(os.path.dirname(__file__), 'modules')
for i in (os.listdir(addons_path) + ['ir', 'workflow', 'res']):
tryton_file = opj(addons_path, i, '__tryton__.py')
mod_path = opj(addons_path, i)
for i in (os.listdir(modules_path) + ['ir', 'workflow', 'res']):
tryton_file = opj(modules_path, i, '__tryton__.py')
mod_path = opj(modules_path, i)
if i in ('ir', 'workflow', 'res'):
root_path = os.path.dirname(__file__)
tryton_file = opj(root_path, i, '__tryton__.py')
mod_path = opj(root_path, i)
info = {}
if os.path.isfile(tryton_file) \
and not os.path.isfile(opj(addons_path, i + '.zip')):
and not os.path.isfile(opj(modules_path, i + '.zip')):
info = eval(file(tryton_file).read())
elif zipfile.is_zipfile(mod_path):
zfile = zipfile.ZipFile(mod_path)
+2 -2
View File
@@ -59,11 +59,11 @@ def exec_command_pipe(name, *args):
cmd = prog+' '+' '.join(args)
return os.popen2(cmd, 'b')
def file_open(name, mode="r", subdir='addons'):
def file_open(name, mode="r", subdir='modules'):
"""Open a file from the root dir, using a subdir folder."""
root_path = os.path.dirname(os.path.dirname(__file__))
if subdir:
if subdir == 'addons'\
if subdir == 'modules'\
and (name.startswith('ir' + os.sep) \
or name.startswith('workflow' + os.sep) \
or name.startswith('res' + os.sep)):
+1 -1
View File
@@ -99,7 +99,7 @@ class Wizard(object):
def __new__(cls):
for module in cls.__module__.split('.'):
if module != 'trytond' and module != 'addons':
if module != 'trytond' and module != 'modules':
break
if not hasattr(cls, '_module'):
cls._module = module