merge
bzr revid: christophe@tinyerp.com-20080722075357-z9pfuk3qrwph8pbw
This commit is contained in:
commit
c5c7c2ef07
|
@ -45,8 +45,8 @@ logger = netsvc.Logger()
|
||||||
|
|
||||||
opj = os.path.join
|
opj = os.path.join
|
||||||
|
|
||||||
_ad = opj(tools.config['root_path'], 'addons') # default addons path (base)
|
_ad = os.path.abspath(opj(tools.config['root_path'], 'addons')) # default addons path (base)
|
||||||
ad = tools.config['addons_path'] # alternate addons path
|
ad = os.path.abspath(tools.config['addons_path']) # alternate addons path
|
||||||
|
|
||||||
sys.path.insert(1, _ad)
|
sys.path.insert(1, _ad)
|
||||||
if ad != _ad:
|
if ad != _ad:
|
||||||
|
@ -131,10 +131,37 @@ class Node(Singleton):
|
||||||
s += '%s`-> %s' % (' ' * depth, c._pprint(depth+1))
|
s += '%s`-> %s' % (' ' * depth, c._pprint(depth+1))
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def _get_module_path(module):
|
def get_module_path(module):
|
||||||
if os.path.exists(opj(ad, module)):
|
"""Return the path of the given module.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if os.path.exists(opj(ad, module)) or os.path.exists(opj(ad, '%s.zip' % module)):
|
||||||
return opj(ad, module)
|
return opj(ad, module)
|
||||||
return opj(_ad, module)
|
|
||||||
|
if os.path.exists(opj(_ad, module)) or os.path.exists(opj(_ad, '%s.zip' % module)):
|
||||||
|
return opj(_ad, module)
|
||||||
|
|
||||||
|
raise IOError, 'Module not found : %s' % module
|
||||||
|
|
||||||
|
def get_module_resource(module, *args):
|
||||||
|
"""Return the full path of a resource of the given module.
|
||||||
|
|
||||||
|
@param module: the module
|
||||||
|
@param args: the resource path components
|
||||||
|
|
||||||
|
@return: absolute path to the resource
|
||||||
|
"""
|
||||||
|
return opj(get_module_path(module), *args)
|
||||||
|
|
||||||
|
def get_modules():
|
||||||
|
"""Returns the list of module names
|
||||||
|
"""
|
||||||
|
|
||||||
|
module_list = os.listdir(ad)
|
||||||
|
module_names = [os.path.basename(m) for m in module_list]
|
||||||
|
module_list += [m for m in os.listdir(_ad) if m not in module_names]
|
||||||
|
|
||||||
|
return module_list
|
||||||
|
|
||||||
def create_graph(module_list, force=None):
|
def create_graph(module_list, force=None):
|
||||||
if not force:
|
if not force:
|
||||||
|
@ -145,9 +172,9 @@ def create_graph(module_list, force=None):
|
||||||
for module in module_list:
|
for module in module_list:
|
||||||
if module[-4:]=='.zip':
|
if module[-4:]=='.zip':
|
||||||
module = module[:-4]
|
module = module[:-4]
|
||||||
mod_path = _get_module_path(module)
|
mod_path = get_module_path(module)
|
||||||
terp_file = opj(mod_path, '__terp__.py')
|
terp_file = get_module_resource(module, '__terp__.py')
|
||||||
if os.path.isfile(terp_file) or zipfile.is_zipfile(mod_path+'.zip'):
|
if os.path.isfile(terp_file) or zipfile.is_zipfile(mod_path):
|
||||||
try:
|
try:
|
||||||
info = eval(tools.file_open(terp_file).read())
|
info = eval(tools.file_open(terp_file).read())
|
||||||
except:
|
except:
|
||||||
|
@ -254,24 +281,20 @@ def load_module_graph(cr, graph, status=None, **kwargs):
|
||||||
cr.commit()
|
cr.commit()
|
||||||
|
|
||||||
def register_classes():
|
def register_classes():
|
||||||
module_list = os.listdir(ad)
|
module_list = get_modules()
|
||||||
module_names = [os.path.basename(m) for m in module_list]
|
|
||||||
module_list += [m for m in os.listdir(_ad) if m not in module_names]
|
|
||||||
|
|
||||||
for package in create_graph(module_list):
|
for package in create_graph(module_list):
|
||||||
m = package.name
|
m = package.name
|
||||||
logger.notifyChannel('init', netsvc.LOG_INFO, 'addon:%s:registering classes' % m)
|
logger.notifyChannel('init', netsvc.LOG_INFO, 'addon:%s:registering classes' % m)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
mod_path = _get_module_path(m)
|
mod_path = get_module_path(m)
|
||||||
if not os.path.isfile(mod_path + '.zip'):
|
if not os.path.isfile(mod_path+'.zip'):
|
||||||
# XXX must restrict to only addons paths
|
# XXX must restrict to only addons paths
|
||||||
imp.load_module(m, *imp.find_module(m))
|
imp.load_module(m, *imp.find_module(m))
|
||||||
else:
|
else:
|
||||||
import zipimport
|
import zipimport
|
||||||
mod_path = mod_path + '.zip'
|
|
||||||
try:
|
try:
|
||||||
zimp = zipimport.zipimporter(mod_path)
|
zimp = zipimport.zipimporter(mod_path+'.zip')
|
||||||
zimp.load_module(m)
|
zimp.load_module(m)
|
||||||
except zipimport.ZipImportError:
|
except zipimport.ZipImportError:
|
||||||
logger.notifyChannel('init', netsvc.LOG_ERROR, 'Couldn\'t find module %s' % m)
|
logger.notifyChannel('init', netsvc.LOG_ERROR, 'Couldn\'t find module %s' % m)
|
||||||
|
|
|
@ -2,13 +2,6 @@
|
||||||
-- Pure SQL
|
-- Pure SQL
|
||||||
-------------------------------------------------------------------------
|
-------------------------------------------------------------------------
|
||||||
|
|
||||||
CREATE TABLE inherit (
|
|
||||||
obj_type varchar(128) not null,
|
|
||||||
obj_id int not null,
|
|
||||||
inst_type varchar(128) not null,
|
|
||||||
inst_id int not null
|
|
||||||
);
|
|
||||||
|
|
||||||
-------------------------------------------------------------------------
|
-------------------------------------------------------------------------
|
||||||
-- IR dictionary
|
-- IR dictionary
|
||||||
-------------------------------------------------------------------------
|
-------------------------------------------------------------------------
|
||||||
|
@ -336,3 +329,4 @@ CREATE TABLE ir_model_data (
|
||||||
res_id integer, primary key(id)
|
res_id integer, primary key(id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -38,9 +38,7 @@ import release
|
||||||
import zipimport
|
import zipimport
|
||||||
|
|
||||||
import wizard
|
import wizard
|
||||||
|
import addons
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ver_regexp = re.compile("^(\\d+)((\\.\\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)\\d*)*)(-r(\\d+))?$")
|
ver_regexp = re.compile("^(\\d+)((\\.\\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)\\d*)*)(-r(\\d+))?$")
|
||||||
suffix_regexp = re.compile("^(alpha|beta|rc|pre|p)(\\d*)$")
|
suffix_regexp = re.compile("^(alpha|beta|rc|pre|p)(\\d*)$")
|
||||||
|
@ -199,7 +197,7 @@ class module(osv.osv):
|
||||||
|
|
||||||
def get_module_info(self, name):
|
def get_module_info(self, name):
|
||||||
try:
|
try:
|
||||||
f = tools.file_open(os.path.join(tools.config['addons_path'], name, '__terp__.py'))
|
f = tools.file_open(os.path.join(name, '__terp__.py'))
|
||||||
data = f.read()
|
data = f.read()
|
||||||
info = eval(data)
|
info = eval(data)
|
||||||
if 'version' in info:
|
if 'version' in info:
|
||||||
|
@ -343,18 +341,17 @@ class module(osv.osv):
|
||||||
filepath = files[lang]
|
filepath = files[lang]
|
||||||
# if filepath does not contain :// we prepend the path of the module
|
# if filepath does not contain :// we prepend the path of the module
|
||||||
if filepath.find('://') == -1:
|
if filepath.find('://') == -1:
|
||||||
filepath = os.path.join(tools.config['addons_path'], module['name'], filepath)
|
filepath = addons.get_module_resource(module['name'], filepath)
|
||||||
tools.trans_load(filepath, lang)
|
tools.trans_load(filepath, lang)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# update the list of available packages
|
# update the list of available packages
|
||||||
def update_list(self, cr, uid, context={}):
|
def update_list(self, cr, uid, context={}):
|
||||||
robj = self.pool.get('ir.module.repository')
|
robj = self.pool.get('ir.module.repository')
|
||||||
adp = tools.config['addons_path']
|
|
||||||
res = [0, 0] # [update, add]
|
res = [0, 0] # [update, add]
|
||||||
|
|
||||||
# iterate through installed modules and mark them as being so
|
# iterate through installed modules and mark them as being so
|
||||||
for name in os.listdir(adp):
|
for name in addons.get_modules():
|
||||||
mod_name = name
|
mod_name = name
|
||||||
if name[-4:]=='.zip':
|
if name[-4:]=='.zip':
|
||||||
mod_name=name[:-4]
|
mod_name=name[:-4]
|
||||||
|
@ -384,20 +381,19 @@ class module(osv.osv):
|
||||||
self._update_category(cr, uid, ids[0], terp.get('category',
|
self._update_category(cr, uid, ids[0], terp.get('category',
|
||||||
'Uncategorized'))
|
'Uncategorized'))
|
||||||
continue
|
continue
|
||||||
terp_file = os.path.join(adp, name, '__terp__.py')
|
terp_file = addons.get_module_resource(name, '__terp__.py')
|
||||||
mod_path = os.path.join(adp, name)
|
mod_path = addons.get_module_path(name)
|
||||||
if os.path.isdir(mod_path) or os.path.islink(mod_path) or zipfile.is_zipfile(mod_path):
|
if os.path.isdir(mod_path) or os.path.islink(mod_path) or zipfile.is_zipfile(mod_path):
|
||||||
terp = self.get_module_info(mod_name)
|
terp = self.get_module_info(mod_name)
|
||||||
if not terp or not terp.get('installable', True):
|
if not terp or not terp.get('installable', True):
|
||||||
continue
|
continue
|
||||||
if not os.path.isfile(os.path.join(adp, mod_name+'.zip')):
|
if not os.path.isfile(mod_path+'.zip'):
|
||||||
import imp
|
import imp
|
||||||
# XXX must restrict to only addons paths
|
# XXX must restrict to only addons paths
|
||||||
imp.load_module(name, *imp.find_module(mod_name))
|
imp.load_module(name, *imp.find_module(mod_name))
|
||||||
else:
|
else:
|
||||||
import zipimport
|
import zipimport
|
||||||
mod_path = os.path.join(adp, mod_name+'.zip')
|
zimp = zipimport.zipimporter(mod_path+'.zip')
|
||||||
zimp = zipimport.zipimporter(mod_path)
|
|
||||||
zimp.load_module(mod_name)
|
zimp.load_module(mod_name)
|
||||||
id = self.create(cr, uid, {
|
id = self.create(cr, uid, {
|
||||||
'name': mod_name,
|
'name': mod_name,
|
||||||
|
@ -472,7 +468,6 @@ class module(osv.osv):
|
||||||
|
|
||||||
def download(self, cr, uid, ids, download=True, context=None):
|
def download(self, cr, uid, ids, download=True, context=None):
|
||||||
res = []
|
res = []
|
||||||
adp = tools.config['addons_path']
|
|
||||||
for mod in self.browse(cr, uid, ids, context=context):
|
for mod in self.browse(cr, uid, ids, context=context):
|
||||||
if not mod.url:
|
if not mod.url:
|
||||||
continue
|
continue
|
||||||
|
@ -486,7 +481,7 @@ class module(osv.osv):
|
||||||
if not download:
|
if not download:
|
||||||
continue
|
continue
|
||||||
zipfile = urllib.urlopen(mod.url).read()
|
zipfile = urllib.urlopen(mod.url).read()
|
||||||
fname = os.path.join(adp, mod.name+'.zip')
|
fname = addons.get_module_path(mod.name+'.zip')
|
||||||
try:
|
try:
|
||||||
fp = file(fname, 'wb')
|
fp = file(fname, 'wb')
|
||||||
fp.write(zipfile)
|
fp.write(zipfile)
|
||||||
|
|
|
@ -333,7 +333,6 @@ class one2many(_column):
|
||||||
for r in obj.pool.get(self._obj).read(cr, user, ids2, [self._fields_id], context=context, load='_classic_write'):
|
for r in obj.pool.get(self._obj).read(cr, user, ids2, [self._fields_id], context=context, load='_classic_write'):
|
||||||
if r[self._fields_id] in res:
|
if r[self._fields_id] in res:
|
||||||
res[r[self._fields_id]].append( r['id'] )
|
res[r[self._fields_id]].append( r['id'] )
|
||||||
print 'Ok', res
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def set_memory(self, cr, obj, id, field, values, user=None, context=None):
|
def set_memory(self, cr, obj, id, field, values, user=None, context=None):
|
||||||
|
|
|
@ -1842,10 +1842,6 @@ class orm(orm_template):
|
||||||
_('You try to bypass an access rule (Document type: %s).') % \
|
_('You try to bypass an access rule (Document type: %s).') % \
|
||||||
self._description)
|
self._description)
|
||||||
|
|
||||||
cr.execute('delete from inherit ' \
|
|
||||||
'where (obj_type=%s and obj_id in ('+str_d+')) ' \
|
|
||||||
'or (inst_type=%s and inst_id in ('+str_d+'))',
|
|
||||||
(self._name,)+tuple(sub_ids)+(self._name,)+tuple(sub_ids))
|
|
||||||
if d1:
|
if d1:
|
||||||
cr.execute('delete from "'+self._table+'" ' \
|
cr.execute('delete from "'+self._table+'" ' \
|
||||||
'where id in ('+str_d+')'+d1, sub_ids+d2)
|
'where id in ('+str_d+')'+d1, sub_ids+d2)
|
||||||
|
@ -2089,7 +2085,6 @@ class orm(orm_template):
|
||||||
upd0 += ','+self._inherits[table]
|
upd0 += ','+self._inherits[table]
|
||||||
upd1 += ',%d'
|
upd1 += ',%d'
|
||||||
upd2.append(id)
|
upd2.append(id)
|
||||||
cr.execute('insert into inherit (obj_type,obj_id,inst_type,inst_id) values (%s,%d,%s,%d)', (table,id,self._name,id_new))
|
|
||||||
|
|
||||||
for field in vals:
|
for field in vals:
|
||||||
if self._columns[field]._classic_write:
|
if self._columns[field]._classic_write:
|
||||||
|
|
|
@ -68,33 +68,12 @@ class osv_pool(netsvc.Service):
|
||||||
self.exportMethod(self.execute_cr)
|
self.exportMethod(self.execute_cr)
|
||||||
|
|
||||||
def execute_cr(self, cr, uid, obj, method, *args, **kw):
|
def execute_cr(self, cr, uid, obj, method, *args, **kw):
|
||||||
#
|
|
||||||
# TODO: check security level
|
|
||||||
#
|
|
||||||
try:
|
try:
|
||||||
object = pooler.get_pool(cr.dbname).get(obj)
|
object = pooler.get_pool(cr.dbname).get(obj)
|
||||||
if not object:
|
if not object:
|
||||||
self.abortResponse(1, 'Object Error', 'warning',
|
self.abortResponse(1, 'Object Error', 'warning',
|
||||||
'Object %s doesn\'t exist' % str(obj))
|
'Object %s doesn\'t exist' % str(obj))
|
||||||
if (not method in getattr(object,'_protected')) and len(args) \
|
return getattr(object,method)(cr, uid, *args, **kw)
|
||||||
and args[0] and len(object._inherits):
|
|
||||||
types = {obj: args[0]}
|
|
||||||
cr.execute('select inst_type,inst_id,obj_id \
|
|
||||||
from inherit \
|
|
||||||
where obj_type=%s \
|
|
||||||
and obj_id in ('+','.join(map(str,args[0]))+')', (obj,))
|
|
||||||
for ty,id,id2 in cr.fetchall():
|
|
||||||
if not ty in types:
|
|
||||||
types[ty]=[]
|
|
||||||
types[ty].append(id)
|
|
||||||
types[obj].remove(id2)
|
|
||||||
for t,ids in types.items():
|
|
||||||
if len(ids):
|
|
||||||
object_t = pooler.get_pool(cr.dbname).get(t)
|
|
||||||
res = getattr(object_t,method)(cr, uid, ids, *args[1:], **kw)
|
|
||||||
else:
|
|
||||||
res = getattr(object,method)(cr, uid, *args, **kw)
|
|
||||||
return res
|
|
||||||
except orm.except_orm, inst:
|
except orm.except_orm, inst:
|
||||||
self.abortResponse(1, inst.name, 'warning', inst.value)
|
self.abortResponse(1, inst.name, 'warning', inst.value)
|
||||||
except except_osv, inst:
|
except except_osv, inst:
|
||||||
|
|
|
@ -37,6 +37,7 @@ import netsvc
|
||||||
import pooler
|
import pooler
|
||||||
|
|
||||||
import tools
|
import tools
|
||||||
|
import addons
|
||||||
import print_xml
|
import print_xml
|
||||||
import render
|
import render
|
||||||
import urllib
|
import urllib
|
||||||
|
@ -121,7 +122,7 @@ class report_rml(report_int):
|
||||||
pos_xml = i.end()
|
pos_xml = i.end()
|
||||||
|
|
||||||
doc = print_xml.document(cr, uid, {}, {})
|
doc = print_xml.document(cr, uid, {}, {})
|
||||||
tmpl_path = os.path.join(tools.config['root_path'], 'addons/custom/corporate_defaults.xml')
|
tmpl_path = addons.get_module_resource('custom', 'corporate_defaults.xml')
|
||||||
doc.parse(tmpl_path, [uid], 'res.users', context)
|
doc.parse(tmpl_path, [uid], 'res.users', context)
|
||||||
corporate_header = doc.xml_get()
|
corporate_header = doc.xml_get()
|
||||||
doc.close()
|
doc.close()
|
||||||
|
@ -146,16 +147,14 @@ class report_rml(report_int):
|
||||||
return xml
|
return xml
|
||||||
|
|
||||||
# load XSL (parse it to the XML level)
|
# load XSL (parse it to the XML level)
|
||||||
styledoc = libxml2.parseDoc(tools.file_open(
|
styledoc = libxml2.parseDoc(tools.file_open(self.xsl).read())
|
||||||
os.path.join(tools.config['root_path'], self.xsl)).read())
|
xsl_path, tail = os.path.split(self.xsl)
|
||||||
xsl_path, tail = os.path.split(os.path.join(tools.config['root_path'],
|
|
||||||
self.xsl))
|
|
||||||
for child in styledoc.children:
|
for child in styledoc.children:
|
||||||
if child.name == 'import':
|
if child.name == 'import':
|
||||||
if child.hasProp('href'):
|
if child.hasProp('href'):
|
||||||
file = child.prop('href')
|
imp_file = child.prop('href')
|
||||||
child.setProp('href', urllib.quote(str(
|
_x, imp_file = tools.file_open(imp_file, subdir=xsl_path, pathinfo=True)
|
||||||
os.path.normpath(os.path.join(xsl_path, file)))))
|
child.setProp('href', urllib.quote(str(imp_file)))
|
||||||
|
|
||||||
#TODO: get all the translation in one query. That means we have to:
|
#TODO: get all the translation in one query. That means we have to:
|
||||||
# * build a list of items to translate,
|
# * build a list of items to translate,
|
||||||
|
|
|
@ -353,9 +353,7 @@ class document(object):
|
||||||
if not context:
|
if not context:
|
||||||
context={}
|
context={}
|
||||||
# parses the xml template to memory
|
# parses the xml template to memory
|
||||||
self.dom = minidom.parseString(tools.file_open(
|
self.dom = minidom.parseString(tools.file_open(filename).read())
|
||||||
os.path.join(tools.config['root_path'],
|
|
||||||
filename)).read())
|
|
||||||
|
|
||||||
# create the xml data from the xml template
|
# create the xml data from the xml template
|
||||||
self.parse_tree(ids, model, context)
|
self.parse_tree(ids, model, context)
|
||||||
|
|
|
@ -290,11 +290,14 @@ class graph(object):
|
||||||
return self.result
|
return self.result
|
||||||
|
|
||||||
if __name__=='__main__':
|
if __name__=='__main__':
|
||||||
starting_node = ['mrp'] # put here nodes with flow_start=True
|
starting_node = ['profile'] # put here nodes with flow_start=True
|
||||||
nodes = ['project','account','hr','base','product','mrp','test']
|
nodes = ['project','account','hr','base','product','mrp','test','profile']
|
||||||
transitions = [
|
transitions = [
|
||||||
|
('profile','mrp'),
|
||||||
('mrp','project'),
|
('mrp','project'),
|
||||||
('project','product'),
|
('project','product'),
|
||||||
|
('mrp','hr'),
|
||||||
|
('mrp','test'),
|
||||||
('project','account'),
|
('project','account'),
|
||||||
('project','hr'),
|
('project','hr'),
|
||||||
('product','base'),
|
('product','base'),
|
||||||
|
|
|
@ -50,25 +50,23 @@ else:
|
||||||
|
|
||||||
# initialize a database with base/base.sql
|
# initialize a database with base/base.sql
|
||||||
def init_db(cr):
|
def init_db(cr):
|
||||||
f = os.path.join(config['addons_path'], 'base/base.sql')
|
import addons
|
||||||
|
f = addons.get_module_resource('base', 'base.sql')
|
||||||
for line in file(f).read().split(';'):
|
for line in file(f).read().split(';'):
|
||||||
if (len(line)>0) and (not line.isspace()):
|
if (len(line)>0) and (not line.isspace()):
|
||||||
cr.execute(line)
|
cr.execute(line)
|
||||||
cr.commit()
|
cr.commit()
|
||||||
|
|
||||||
opj = os.path.join
|
for i in addons.get_modules():
|
||||||
ad = config['addons_path']
|
terp_file = addons.get_module_resource(i, '__terp__.py')
|
||||||
|
mod_path = addons.get_module_path(i)
|
||||||
for i in os.listdir(ad):
|
|
||||||
terp_file = opj(ad, i, '__terp__.py')
|
|
||||||
mod_path = opj(ad, i)
|
|
||||||
info = False
|
info = False
|
||||||
if os.path.isfile(terp_file) and not os.path.isfile(opj(ad, i+'.zip')):
|
if os.path.isfile(terp_file) and not os.path.isfile(mod_path+'.zip'):
|
||||||
info = eval(file(terp_file).read())
|
info = eval(file(terp_file).read())
|
||||||
elif zipfile.is_zipfile(mod_path):
|
elif zipfile.is_zipfile(mod_path+'.zip'):
|
||||||
zfile = zipfile.ZipFile(mod_path)
|
zfile = zipfile.ZipFile(mod_path+'.zip')
|
||||||
i = os.path.splitext(i)[0]
|
i = os.path.splitext(i)[0]
|
||||||
info = eval(zfile.read(opj(i, '__terp__.py')))
|
info = eval(zfile.read(os.path.join(i, '__terp__.py')))
|
||||||
if info:
|
if info:
|
||||||
categs = info.get('category', 'Uncategorized').split('/')
|
categs = info.get('category', 'Uncategorized').split('/')
|
||||||
p_id = None
|
p_id = None
|
||||||
|
@ -170,12 +168,55 @@ def exec_command_pipe(name, *args):
|
||||||
#file_path_root = os.getcwd()
|
#file_path_root = os.getcwd()
|
||||||
#file_path_addons = os.path.join(file_path_root, 'addons')
|
#file_path_addons = os.path.join(file_path_root, 'addons')
|
||||||
|
|
||||||
def file_open(name, mode="r", subdir='addons'):
|
def file_open(name, mode="r", subdir='addons', pathinfo=False):
|
||||||
"""Open a file from the Tiny ERP root, using a subdir folder."""
|
"""Open a file from the Tiny ERP root, using a subdir folder.
|
||||||
|
|
||||||
|
>>> file_open('hr/report/timesheer.xsl')
|
||||||
|
>>> file_open('addons/hr/report/timesheet.xsl')
|
||||||
|
>>> file_open('../../base/report/rml_template.xsl', subdir='addons/hr/report', pathinfo=True)
|
||||||
|
|
||||||
|
@param name: name of the file
|
||||||
|
@param mode: file open mode
|
||||||
|
@param subdir: subdirectory
|
||||||
|
@param pathinfo: if True returns tupple (fileobject, filepath)
|
||||||
|
|
||||||
|
@return: fileobject if pathinfo is False else (fileobject, filepath)
|
||||||
|
"""
|
||||||
|
|
||||||
|
adp = os.path.normcase(os.path.abspath(config['addons_path']))
|
||||||
|
rtp = os.path.normcase(os.path.abspath(config['root_path']))
|
||||||
|
|
||||||
|
if name.replace(os.path.sep, '/').startswith('addons/'):
|
||||||
|
subdir = 'addons'
|
||||||
|
name = name[7:]
|
||||||
|
|
||||||
|
# First try to locate in addons_path
|
||||||
if subdir:
|
if subdir:
|
||||||
name = os.path.join(config['root_path'], subdir, name)
|
subdir2 = subdir
|
||||||
|
if subdir2.replace(os.path.sep, '/').startswith('addons/'):
|
||||||
|
subdir2 = subdir2[7:]
|
||||||
|
|
||||||
|
subdir2 = (subdir2 != 'addons' or None) and subdir2
|
||||||
|
|
||||||
|
try:
|
||||||
|
if subdir2:
|
||||||
|
fn = os.path.join(adp, subdir2, name)
|
||||||
|
else:
|
||||||
|
fn = os.path.join(adp, name)
|
||||||
|
fn = os.path.normpath(fn)
|
||||||
|
fo = file_open(fn, mode=mode, subdir=None, pathinfo=pathinfo)
|
||||||
|
if pathinfo:
|
||||||
|
return fo, fn
|
||||||
|
return fo
|
||||||
|
except IOError, e:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if subdir:
|
||||||
|
name = os.path.join(rtp, subdir, name)
|
||||||
else:
|
else:
|
||||||
name = os.path.join(config['root_path'], name)
|
name = os.path.join(rtp, name)
|
||||||
|
|
||||||
|
name = os.path.normpath(name)
|
||||||
|
|
||||||
# Check for a zipfile in the path
|
# Check for a zipfile in the path
|
||||||
head = name
|
head = name
|
||||||
|
@ -193,15 +234,22 @@ def file_open(name, mode="r", subdir='addons'):
|
||||||
import StringIO
|
import StringIO
|
||||||
zfile = zipfile.ZipFile(head+'.zip')
|
zfile = zipfile.ZipFile(head+'.zip')
|
||||||
try:
|
try:
|
||||||
return StringIO.StringIO(zfile.read(os.path.join(
|
fo = StringIO.StringIO(zfile.read(os.path.join(
|
||||||
os.path.basename(head), zipname).replace(
|
os.path.basename(head), zipname).replace(
|
||||||
os.sep, '/')))
|
os.sep, '/')))
|
||||||
|
|
||||||
|
if pathinfo:
|
||||||
|
return fo, name
|
||||||
|
return fo
|
||||||
except:
|
except:
|
||||||
name2 = os.path.normpath(os.path.join(head + '.zip', zipname))
|
name2 = os.path.normpath(os.path.join(head + '.zip', zipname))
|
||||||
pass
|
pass
|
||||||
for i in (name2, name):
|
for i in (name2, name):
|
||||||
if i and os.path.isfile(i):
|
if i and os.path.isfile(i):
|
||||||
return file(i, mode)
|
fo = file(i, mode)
|
||||||
|
if pathinfo:
|
||||||
|
return fo, i
|
||||||
|
return fo
|
||||||
|
|
||||||
raise IOError, 'File not found : '+str(name)
|
raise IOError, 'File not found : '+str(name)
|
||||||
|
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -1,3 +1,4 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
|
@ -26,7 +27,6 @@
|
||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# setup from TinERP
|
# setup from TinERP
|
||||||
# taken from straw http://www.nongnu.org/straw/index.html
|
# taken from straw http://www.nongnu.org/straw/index.html
|
||||||
# taken from gnomolicious http://www.nongnu.org/gnomolicious/
|
# taken from gnomolicious http://www.nongnu.org/gnomolicious/
|
||||||
|
|
Loading…
Reference in New Issue