preliminary addons loading support
bzr revid: al@openerp.com-20110307092632-e0a6rho0bvuk04ei
This commit is contained in:
parent
acef7835aa
commit
fc679ac8a5
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"name" : "OpenERP Web base",
|
||||||
|
"version" : "2.0",
|
||||||
|
"depends" : [],
|
||||||
|
'active': True,
|
||||||
|
}
|
|
@ -1,6 +1,8 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import json, os, sys, traceback
|
import glob,json,os,sys,traceback
|
||||||
|
|
||||||
|
#import simplejson as json
|
||||||
|
|
||||||
import openerpweb
|
import openerpweb
|
||||||
|
|
||||||
|
@ -64,12 +66,9 @@ class Hello(openerpweb.Controller):
|
||||||
|
|
||||||
class Connection(openerpweb.Controller):
|
class Connection(openerpweb.Controller):
|
||||||
_cp_path = "/base/connection"
|
_cp_path = "/base/connection"
|
||||||
|
def filesofmodulemap(self, ):
|
||||||
def filesofmodulemap(self, module_file_map):
|
|
||||||
# TODO root should be a global config
|
# TODO root should be a global config
|
||||||
root = os.path.join(os.path.dirname(__file__),'..','..')
|
|
||||||
files=[]
|
files=[]
|
||||||
for i in mods.split(','):
|
|
||||||
for j in cssfiles.get(i,[]):
|
for j in cssfiles.get(i,[]):
|
||||||
files.append(j)
|
files.append(j)
|
||||||
|
|
||||||
|
@ -79,6 +78,7 @@ class Connection(openerpweb.Controller):
|
||||||
concat: concatenation of file content
|
concat: concatenation of file content
|
||||||
timestamp: max(os.path.getmtime of file_list)
|
timestamp: max(os.path.getmtime of file_list)
|
||||||
"""
|
"""
|
||||||
|
root = openerpweb.path_root
|
||||||
files_content = []
|
files_content = []
|
||||||
files_timestamp = 0
|
files_timestamp = 0
|
||||||
for i in file_list:
|
for i in file_list:
|
||||||
|
@ -92,7 +92,15 @@ class Connection(openerpweb.Controller):
|
||||||
|
|
||||||
def css(self, req):
|
def css(self, req):
|
||||||
# TODO http get argument mods is a comma seprated value of modules
|
# TODO http get argument mods is a comma seprated value of modules
|
||||||
mods = 'base,base_calendar'
|
mods = 'base,base_hello'
|
||||||
|
files = []
|
||||||
|
for i in mods.split(','):
|
||||||
|
globlist = openerpweb.addons_manifest.get(i,{})
|
||||||
|
for j in globlist:
|
||||||
|
tmp = glob.glob(os.path.join(path_addons,i,j))
|
||||||
|
print tmp
|
||||||
|
files.append(tmp)
|
||||||
|
|
||||||
# TODO modules should list their css and js in __openerp__
|
# TODO modules should list their css and js in __openerp__
|
||||||
# TODO cssfiles should be a global registry of files
|
# TODO cssfiles should be a global registry of files
|
||||||
cssfiles = {
|
cssfiles = {
|
||||||
|
@ -130,6 +138,12 @@ class Session(openerpweb.Controller):
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def modules(self, req):
|
||||||
|
# TODO return the list of all modules
|
||||||
|
res={}
|
||||||
|
res["modules"] = ["base","base_hello"]
|
||||||
|
return res
|
||||||
|
|
||||||
class Menu(openerpweb.Controller):
|
class Menu(openerpweb.Controller):
|
||||||
_cp_path = "/base/menu"
|
_cp_path = "/base/menu"
|
||||||
|
|
||||||
|
|
|
@ -135,7 +135,7 @@ def jsonrequest(f):
|
||||||
l.exposed=1
|
l.exposed=1
|
||||||
return l
|
return l
|
||||||
|
|
||||||
class BasicRequest(object):
|
class HttpRequest(object):
|
||||||
""" Regular GET/POST request
|
""" Regular GET/POST request
|
||||||
"""
|
"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -148,10 +148,10 @@ class BasicRequest(object):
|
||||||
r=f(controller, self, request)
|
r=f(controller, self, request)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def basicrequest(f):
|
def httprequest(f):
|
||||||
# check cleaner wrapping:
|
# check cleaner wrapping:
|
||||||
# functools.wraps(f)(lambda x: JsonRequest().dispatch(x, f))
|
# functools.wraps(f)(lambda x: JsonRequest().dispatch(x, f))
|
||||||
l=lambda self, request: BasicRequest().dispatch(self, f, request)
|
l=lambda self, request: HttpRequest().dispatch(self, f, request)
|
||||||
l.exposed=1
|
l.exposed=1
|
||||||
return l
|
return l
|
||||||
|
|
||||||
|
@ -162,17 +162,20 @@ def basicrequest(f):
|
||||||
path_root = os.path.dirname(os.path.dirname(os.path.normpath(__file__)))
|
path_root = os.path.dirname(os.path.dirname(os.path.normpath(__file__)))
|
||||||
path_addons = os.path.join(path_root,'addons')
|
path_addons = os.path.join(path_root,'addons')
|
||||||
cherrypy_root = None
|
cherrypy_root = None
|
||||||
openerp_addons = {}
|
|
||||||
openerp_controllers_class = {}
|
# globals might move into a pool if needed
|
||||||
openerp_controllers_object = {}
|
addons_module = {}
|
||||||
openerp_controllers_path = {}
|
addons_manifest = {}
|
||||||
|
controllers_class = {}
|
||||||
|
controllers_object = {}
|
||||||
|
controllers_path = {}
|
||||||
|
|
||||||
class ControllerType(type):
|
class ControllerType(type):
|
||||||
def __init__(cls, name, bases, attrs):
|
def __init__(cls, name, bases, attrs):
|
||||||
super(ControllerType, cls).__init__(name, bases, attrs)
|
super(ControllerType, cls).__init__(name, bases, attrs)
|
||||||
# TODO forgive me this hack and find me a clean way to get the absolute name of a class
|
# TODO forgive me this hack and find me a clean way to get the absolute name of a class
|
||||||
cls.fullname = re.search("'(.+)'",repr(cls)).group(1)
|
cls.fullname = re.search("'(.+)'",repr(cls)).group(1)
|
||||||
openerp_controllers_class[cls.fullname] = cls
|
controllers_class[cls.fullname] = cls
|
||||||
|
|
||||||
class Controller(object):
|
class Controller(object):
|
||||||
__metaclass__ = ControllerType
|
__metaclass__ = ControllerType
|
||||||
|
@ -186,15 +189,19 @@ class Root(object):
|
||||||
sys.path.insert(0,path_addons)
|
sys.path.insert(0,path_addons)
|
||||||
for i in os.listdir(path_addons):
|
for i in os.listdir(path_addons):
|
||||||
if i not in sys.modules:
|
if i not in sys.modules:
|
||||||
print "Loading",i
|
manifest_path = os.path.join(path_addons,i,'__openerp__.py')
|
||||||
m = __import__(i)
|
if os.path.isfile(manifest_path):
|
||||||
openerp_addons[i] = m
|
manifest = eval(open(manifest_path).read())
|
||||||
for k,v in openerp_controllers_class.items():
|
print "Loading",i
|
||||||
if k not in openerp_controllers_object:
|
m = __import__(i)
|
||||||
|
addons_module[i] = m
|
||||||
|
addons_manifest[i] = manifest
|
||||||
|
for k,v in controllers_class.items():
|
||||||
|
if k not in controllers_object:
|
||||||
o = v()
|
o = v()
|
||||||
openerp_controllers_object[k] = o
|
controllers_object[k] = o
|
||||||
if hasattr(o,'_cp_path'):
|
if hasattr(o,'_cp_path'):
|
||||||
openerp_controllers_path[o._cp_path] = o
|
controllers_path[o._cp_path] = o
|
||||||
|
|
||||||
def default(self, *l, **kw):
|
def default(self, *l, **kw):
|
||||||
#print "default",l,kw
|
#print "default",l,kw
|
||||||
|
@ -206,13 +213,14 @@ class Root(object):
|
||||||
elif len(l) > 1:
|
elif len(l) > 1:
|
||||||
for i in range(1,len(l)+1):
|
for i in range(1,len(l)+1):
|
||||||
ps = "/" + "/".join(l[0:i])
|
ps = "/" + "/".join(l[0:i])
|
||||||
if ps in openerp_controllers_path:
|
if ps in controllers_path:
|
||||||
c = openerp_controllers_path[ps]
|
c = controllers_path[ps]
|
||||||
rest = l[i:] or ['index']
|
rest = l[i:] or ['index']
|
||||||
meth = rest[0]
|
meth = rest[0]
|
||||||
m = getattr(c,meth)
|
m = getattr(c,meth)
|
||||||
print "Calling",ps,c,meth,m
|
if getattr(m,'exposed',0):
|
||||||
return m(**kw)
|
print "Calling",ps,c,meth,m
|
||||||
|
return m(**kw)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return '<a href="/base/static/openerp/base.html">/base/static/openerp/base.html</a>'
|
return '<a href="/base/static/openerp/base.html">/base/static/openerp/base.html</a>'
|
||||||
|
|
Loading…
Reference in New Issue