Custom addons path now overrides default addons path.

- `root_path`/addons is default
	- `addons_path` overrides default path (will get precedence over default path)
	- added `--addons-path` command line option

bzr revid: ame@tinyerp.com-20080715081040-fqmfvx7jxl6d5hn3
This commit is contained in:
Amit Mendapara 2008-07-15 13:40:40 +05:30
parent 8d7e8075b1
commit f469837563
2 changed files with 24 additions and 10 deletions

View File

@ -44,8 +44,13 @@ import zipfile
logger = netsvc.Logger()
opj = os.path.join
ad = tools.config['addons_path']
sys.path.insert(1,ad)
_ad = opj(tools.config['root_path'], 'addons') # default addons path (base)
ad = tools.config['addons_path'] # alternate addons path
sys.path.insert(1, _ad)
if ad != _ad:
sys.path.insert(1, ad)
class Graph(dict):
@ -126,6 +131,11 @@ class Node(Singleton):
s += '%s`-> %s' % (' ' * depth, c._pprint(depth+1))
return s
def _get_module_path(module):
if os.path.exists(opj(ad, module)):
return opj(ad, module)
return opj(_ad, module)
def create_graph(module_list, force=None):
if not force:
force=[]
@ -135,8 +145,8 @@ def create_graph(module_list, force=None):
for module in module_list:
if module[-4:]=='.zip':
module = module[:-4]
terp_file = opj(ad, module, '__terp__.py')
mod_path = opj(ad, module)
mod_path = _get_module_path(module)
terp_file = opj(mod_path, '__terp__.py')
if os.path.isfile(terp_file) or zipfile.is_zipfile(mod_path+'.zip'):
try:
info = eval(tools.file_open(terp_file).read())
@ -245,17 +255,20 @@ def load_module_graph(cr, graph, status=None, **kwargs):
def register_classes():
module_list = os.listdir(ad)
module_list += [m for m in os.listdir(_ad) if m not in module_list]
for package in create_graph(module_list):
m = package.name
logger.notifyChannel('init', netsvc.LOG_INFO, 'addon:%s:registering classes' % m)
sys.stdout.flush()
if not os.path.isfile(opj(ad, m+'.zip')):
mod_path = _get_module_path(m)
if not os.path.isfile(mod_path + '.zip'):
# XXX must restrict to only addons paths
imp.load_module(m, *imp.find_module(m))
else:
import zipimport
mod_path = opj(ad, m+'.zip')
mod_path = mod_path + '.zip'
try:
zimp = zipimport.zipimporter(mod_path)
zimp.load_module(m)

View File

@ -121,6 +121,7 @@ class configmanager(object):
group.add_option("--i18n-export", dest="translate_out", help="export all sentences to be translated to a CSV file and exit")
group.add_option("--i18n-import", dest="translate_in", help="import a CSV file with translations and exit")
group.add_option("--modules", dest="translate_modules", help="specify modules to export. Use in combination with --i18n-export")
group.add_option("--addons-path", dest="addons_path", help="specify an alternative addons path.")
parser.add_option_group(group)
(opt, args) = parser.parse_args()
@ -142,13 +143,13 @@ class configmanager(object):
# Verify that we want to log or not, if not the output will go to stdout
if self.options['logfile'] in ('None', 'False'):
self.options['logfile'] = False
self.options['logfile'] = False
# the same for the pidfile
if self.options['pidfile'] in ('None', 'False'):
self.options['pidfile'] = False
if self.options['pidfile'] in ('None', 'False'):
self.options['pidfile'] = False
for arg in ('interface', 'port', 'db_name', 'db_user', 'db_password', 'db_host',
'db_port', 'logfile', 'pidfile', 'secure', 'smtp_server', 'smtp_user', 'smtp_password', 'price_accuracy', 'netinterface', 'netport', 'db_maxconn', 'commit_mode'):
'db_port', 'logfile', 'pidfile', 'secure', 'smtp_server', 'smtp_user', 'smtp_password', 'price_accuracy', 'netinterface', 'netport', 'db_maxconn', 'commit_mode', 'addons_path'):
if getattr(opt, arg):
self.options[arg] = getattr(opt, arg)