Merge branch 'master' of /home/panos/tmp/tinyerp/openobject-server/ into mdv-gpl3-py26
Conflicts: bin/tools/translate.py bzr revid: p_christ@hol.gr-20090114075916-feh0125soh9euu1h
This commit is contained in:
commit
b8d5eac277
|
@ -41,7 +41,8 @@ import release
|
|||
import re
|
||||
import base64
|
||||
from zipfile import PyZipFile, ZIP_DEFLATED
|
||||
import StringIO
|
||||
from cStringIO import StringIO
|
||||
|
||||
|
||||
logger = netsvc.Logger()
|
||||
|
||||
|
@ -198,7 +199,7 @@ def get_module_as_zip(modulename, b64enc=True, src=True):
|
|||
if os.path.isfile(ap + '.zip'):
|
||||
val = file(ap + '.zip', 'rb').read()
|
||||
else:
|
||||
archname = StringIO.StringIO('wb')
|
||||
archname = StringIO()
|
||||
archive = PyZipFile(archname, "w", ZIP_DEFLATED)
|
||||
archive.writepy(ap)
|
||||
_zippy(archive, ap, src=src)
|
||||
|
@ -206,11 +207,6 @@ def get_module_as_zip(modulename, b64enc=True, src=True):
|
|||
val = archname.getvalue()
|
||||
archname.close()
|
||||
|
||||
### debug
|
||||
f = file('/tmp/mod.zip', 'wb')
|
||||
f.write(val)
|
||||
f.close()
|
||||
|
||||
if b64enc:
|
||||
val = base64.encodestring(val)
|
||||
return val
|
||||
|
@ -317,11 +313,17 @@ def register_class(m):
|
|||
"""
|
||||
Register module named m, if not already registered
|
||||
"""
|
||||
|
||||
def log(e):
|
||||
mt = isinstance(e, zipimport.ZipImportError) and 'zip ' or ''
|
||||
msg = "Couldn't load%s module %s" % (mt, m)
|
||||
logger.notifyChannel('init', netsvc.LOG_CRITICAL, msg)
|
||||
logger.notifyChannel('init', netsvc.LOG_CRITICAL, e)
|
||||
|
||||
global loaded
|
||||
if m in loaded:
|
||||
return
|
||||
logger.notifyChannel('init', netsvc.LOG_INFO, 'module %s: registering objects' % m)
|
||||
loaded.append(m)
|
||||
mod_path = get_module_path(m)
|
||||
try:
|
||||
zip_mod_path = mod_path + '.zip'
|
||||
|
@ -335,15 +337,11 @@ def register_class(m):
|
|||
else:
|
||||
zimp = zipimport.zipimporter(zip_mod_path)
|
||||
zimp.load_module(m)
|
||||
except zipimport.ZipImportError:
|
||||
logger.notifyChannel('init', netsvc.LOG_CRITICAL, 'Couldn\'t find zip module %s' % m)
|
||||
raise
|
||||
except ImportError:
|
||||
logger.notifyChannel('init', netsvc.LOG_CRITICAL, 'Couldn\'t find module %s' % m)
|
||||
raise
|
||||
except Exception:
|
||||
logger.notifyChannel('init', netsvc.LOG_CRITICAL, 'Couldn\'t find module %s' % (m))
|
||||
except Exception, e:
|
||||
log(e)
|
||||
raise
|
||||
else:
|
||||
loaded.append(m)
|
||||
|
||||
|
||||
class MigrationManager(object):
|
||||
|
@ -463,24 +461,36 @@ class MigrationManager(object):
|
|||
name, ext = os.path.splitext(os.path.basename(pyfile))
|
||||
if ext.lower() != '.py':
|
||||
continue
|
||||
fp = tools.file_open(opj(modulename, pyfile))
|
||||
mod = None
|
||||
mod = fp = fp2 = None
|
||||
try:
|
||||
mod = imp.load_source(name, pyfile, fp)
|
||||
logger.notifyChannel('migration', netsvc.LOG_INFO, 'module %(addon)s: Running migration %(version)s %(name)s"' % mergedict({'name': mod.__name__},strfmt))
|
||||
mod.migrate(self.cr, pkg.installed_version)
|
||||
except ImportError:
|
||||
logger.notifyChannel('migration', netsvc.LOG_ERROR, 'module %(addon)s: Unable to load %(stage)-migration file %(file)s' % mergedict({'file': opj(modulename,pyfile)}, strfmt))
|
||||
raise
|
||||
except AttributeError:
|
||||
logger.notifyChannel('migration', netsvc.LOG_ERROR, 'module %(addon)s: Each %(stage)-migration file must have a "migrate(cr, installed_version)" function' % strfmt)
|
||||
except:
|
||||
raise
|
||||
fp.close()
|
||||
del mod
|
||||
fp = tools.file_open(opj(modulename, pyfile))
|
||||
|
||||
# imp.load_source need a real file object, so we create
|
||||
# on from the file-like object we get from file_open
|
||||
fp2 = os.tmpfile()
|
||||
fp2.write(fp.read())
|
||||
fp2.seek(0)
|
||||
try:
|
||||
mod = imp.load_source(name, pyfile, fp2)
|
||||
logger.notifyChannel('migration', netsvc.LOG_INFO, 'module %(addon)s: Running migration %(version)s %(name)s"' % mergedict({'name': mod.__name__},strfmt))
|
||||
mod.migrate(self.cr, pkg.installed_version)
|
||||
except ImportError:
|
||||
logger.notifyChannel('migration', netsvc.LOG_ERROR, 'module %(addon)s: Unable to load %(stage)s-migration file %(file)s' % mergedict({'file': opj(modulename,pyfile)}, strfmt))
|
||||
raise
|
||||
except AttributeError:
|
||||
logger.notifyChannel('migration', netsvc.LOG_ERROR, 'module %(addon)s: Each %(stage)s-migration file must have a "migrate(cr, installed_version)" function' % strfmt)
|
||||
except:
|
||||
raise
|
||||
finally:
|
||||
if fp:
|
||||
fp.close()
|
||||
if fp2:
|
||||
fp2.close()
|
||||
if mod:
|
||||
del mod
|
||||
|
||||
|
||||
def load_module_graph(cr, graph, status=None, check_access_rules=True, **kwargs):
|
||||
def load_module_graph(cr, graph, status=None, perform_checks=True, **kwargs):
|
||||
# **kwargs is passed directly to convert_xml_import
|
||||
if not status:
|
||||
status={}
|
||||
|
@ -511,6 +521,8 @@ def load_module_graph(cr, graph, status=None, check_access_rules=True, **kwargs)
|
|||
migrations = MigrationManager(cr, graph)
|
||||
|
||||
check_rules = False
|
||||
modobj = None
|
||||
|
||||
for package in graph:
|
||||
status['progress'] = (float(statusi)+0.1)/len(graph)
|
||||
m = package.name
|
||||
|
@ -522,6 +534,12 @@ def load_module_graph(cr, graph, status=None, check_access_rules=True, **kwargs)
|
|||
logger.notifyChannel('init', netsvc.LOG_INFO, 'module %s loading objects' % m)
|
||||
modules = pool.instanciate(m, cr)
|
||||
|
||||
if modobj is None:
|
||||
modobj = pool.get('ir.module.module')
|
||||
|
||||
if modobj and perform_checks:
|
||||
modobj.check(cr, 1, [mid])
|
||||
|
||||
idref = {}
|
||||
status['progress'] = (float(statusi)+0.4)/len(graph)
|
||||
if hasattr(package, 'init') or hasattr(package, 'update') or package.state in ('to install', 'to upgrade'):
|
||||
|
@ -564,7 +582,6 @@ def load_module_graph(cr, graph, status=None, check_access_rules=True, **kwargs)
|
|||
#cr.execute("update ir_module_module set state='installed', latest_version=%s where id=%s", (ver, mid,))
|
||||
|
||||
# Set new modules and dependencies
|
||||
modobj = pool.get('ir.module.module')
|
||||
modobj.write(cr, 1, [mid], {'state':'installed', 'latest_version':ver})
|
||||
cr.commit()
|
||||
|
||||
|
@ -576,13 +593,12 @@ def load_module_graph(cr, graph, status=None, check_access_rules=True, **kwargs)
|
|||
|
||||
statusi+=1
|
||||
|
||||
if check_access_rules and check_rules:
|
||||
if perform_checks and check_rules:
|
||||
cr.execute("""select model,name from ir_model where id not in (select model_id from ir_model_access)""")
|
||||
for (model,name) in cr.fetchall():
|
||||
logger.notifyChannel('init', netsvc.LOG_WARNING, 'object %s (%s) has no access rules!' % (model,name))
|
||||
|
||||
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
cr.execute('select model from ir_model where state=%s', ('manual',))
|
||||
for model in cr.dictfetchall():
|
||||
pool.get('ir.model').instanciate(cr, 1, model['model'], {})
|
||||
|
@ -603,7 +619,7 @@ def load_modules(db, force_demo=False, status=None, update_module=False):
|
|||
report = tools.assertion_report()
|
||||
if update_module:
|
||||
basegraph = create_graph(['base'], force)
|
||||
load_module_graph(cr, basegraph, status, check_access_rules=False, report=report)
|
||||
load_module_graph(cr, basegraph, status, perform_checks=False, report=report)
|
||||
|
||||
modobj = pool.get('ir.module.module')
|
||||
logger.notifyChannel('init', netsvc.LOG_INFO, 'updating modules list')
|
||||
|
|
|
@ -19,50 +19,50 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
|
||||
{
|
||||
"name" : "Base",
|
||||
"version" : "1.1",
|
||||
"author" : "Tiny",
|
||||
"website" : "http://www.openerp.com",
|
||||
"category" : "Generic Modules/Base",
|
||||
"description": "The kernel of OpenERP, needed for all installation.",
|
||||
"depends" : [],
|
||||
"init_xml" : [
|
||||
"base_data.xml",
|
||||
"base_menu.xml",
|
||||
"security/base_security.xml",
|
||||
"res/res_security.xml",
|
||||
"maintenance/maintenance_security.xml",
|
||||
'name': 'Base',
|
||||
'version': '1.1',
|
||||
'category': 'Generic Modules/Base',
|
||||
'description': """The kernel of OpenERP, needed for all installation.""",
|
||||
'author': 'Tiny',
|
||||
'website': 'http://www.openerp.com',
|
||||
'depends': [],
|
||||
'init_xml': [
|
||||
'base_data.xml',
|
||||
'base_menu.xml',
|
||||
'security/base_security.xml',
|
||||
'res/res_security.xml',
|
||||
'maintenance/maintenance_security.xml'
|
||||
],
|
||||
"demo_xml" : [
|
||||
"base_demo.xml",
|
||||
"res/partner/partner_demo.xml",
|
||||
"res/partner/crm_demo.xml",
|
||||
'update_xml': [
|
||||
'base_update.xml',
|
||||
'ir/wizard/wizard_menu_view.xml',
|
||||
'ir/ir.xml',
|
||||
'ir/workflow/workflow_view.xml',
|
||||
'module/module_wizard.xml',
|
||||
'module/module_view.xml',
|
||||
'module/module_data.xml',
|
||||
'module/module_report.xml',
|
||||
'res/res_request_view.xml',
|
||||
'res/res_lang_view.xml',
|
||||
'res/partner/partner_report.xml',
|
||||
'res/partner/partner_view.xml',
|
||||
'res/partner/partner_wizard.xml',
|
||||
'res/bank_view.xml',
|
||||
'res/country_view.xml',
|
||||
'res/res_currency_view.xml',
|
||||
'res/partner/crm_view.xml',
|
||||
'res/partner/partner_data.xml',
|
||||
'res/ir_property_view.xml',
|
||||
'security/base_security.xml',
|
||||
'maintenance/maintenance_view.xml',
|
||||
'security/ir.model.access.csv'
|
||||
],
|
||||
"update_xml" : [
|
||||
"base_update.xml",
|
||||
"ir/wizard/wizard_menu_view.xml",
|
||||
"ir/ir.xml",
|
||||
"ir/workflow/workflow_view.xml",
|
||||
"module/module_wizard.xml",
|
||||
"module/module_view.xml",
|
||||
"module/module_data.xml",
|
||||
"module/module_report.xml",
|
||||
"res/res_request_view.xml",
|
||||
"res/res_lang_view.xml",
|
||||
"res/partner/partner_report.xml",
|
||||
"res/partner/partner_view.xml",
|
||||
"res/partner/partner_wizard.xml",
|
||||
"res/bank_view.xml",
|
||||
"res/country_view.xml",
|
||||
"res/res_currency_view.xml",
|
||||
"res/partner/crm_view.xml",
|
||||
"res/partner/partner_data.xml",
|
||||
"res/ir_property_view.xml",
|
||||
"security/base_security.xml",
|
||||
"maintenance/maintenance_view.xml",
|
||||
"security/ir.model.access.csv",
|
||||
],
|
||||
"active": True,
|
||||
"installable": True,
|
||||
'demo_xml': ['base_demo.xml', 'res/partner/partner_demo.xml', 'res/partner/crm_demo.xml'],
|
||||
'installable': True,
|
||||
'active': True,
|
||||
'certificate': '76807797149',
|
||||
}
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -79,9 +79,9 @@ class ir_translation(osv.osv):
|
|||
cr.execute('CREATE INDEX ir_translation_lts ON ir_translation (lang, type, src)')
|
||||
cr.commit()
|
||||
|
||||
@tools.cache(skiparg=3)
|
||||
@tools.cache(skiparg=3, multi='ids')
|
||||
def _get_ids(self, cr, uid, name, tt, lang, ids):
|
||||
translations = {}
|
||||
translations = dict.fromkeys(ids, False)
|
||||
if ids:
|
||||
cr.execute('select res_id,value ' \
|
||||
'from ir_translation ' \
|
||||
|
@ -92,9 +92,6 @@ class ir_translation(osv.osv):
|
|||
(lang,tt,name))
|
||||
for res_id, value in cr.fetchall():
|
||||
translations[res_id] = value
|
||||
for res_id in ids:
|
||||
if res_id not in translations:
|
||||
translations[res_id] = False
|
||||
return translations
|
||||
|
||||
def _set_ids(self, cr, uid, name, tt, lang, ids, value):
|
||||
|
@ -104,6 +101,7 @@ class ir_translation(osv.osv):
|
|||
if tr[res_id]:
|
||||
self._get_source.clear_cache(cr.dbname, uid, name, tt, lang, tr[res_id])
|
||||
self._get_source.clear_cache(cr.dbname, uid, name, tt, lang)
|
||||
self._get_ids.clear_cache(cr.dbname, uid, name, tt, lang, ids)
|
||||
|
||||
cr.execute('delete from ir_translation ' \
|
||||
'where lang=%s ' \
|
||||
|
|
|
@ -30,7 +30,8 @@ def _check_xml(self, cr, uid, ids, context={}):
|
|||
for view in self.browse(cr, uid, ids, context):
|
||||
eview = etree.fromstring(view.arch.encode('utf8'))
|
||||
frng = tools.file_open(os.path.join('base','rng','view.rng'))
|
||||
relaxng = etree.RelaxNG(file=frng)
|
||||
relaxng_doc = etree.parse(frng)
|
||||
relaxng = etree.RelaxNG(relaxng_doc)
|
||||
if not relaxng.validate(eview):
|
||||
logger = netsvc.Logger()
|
||||
logger.notifyChannel('init', netsvc.LOG_ERROR, 'The view does not fit the required schema !')
|
||||
|
@ -64,7 +65,7 @@ class view(osv.osv):
|
|||
'field_parent': fields.char('Childs Field',size=64),
|
||||
}
|
||||
_defaults = {
|
||||
'arch': lambda *a: '<?xml version="1.0"?>\n<tree title="Unknwown">\n\t<field name="name"/>\n</tree>',
|
||||
'arch': lambda *a: '<?xml version="1.0"?>\n<tree string="Unknwown">\n\t<field name="name"/>\n</tree>',
|
||||
'priority': lambda *a: 16
|
||||
}
|
||||
_order = "priority"
|
||||
|
@ -73,7 +74,7 @@ class view(osv.osv):
|
|||
]
|
||||
|
||||
def create(self, cr, uid, vals, context={}):
|
||||
if 'inherit_id' in vals:
|
||||
if 'inherit_id' in vals and vals['inherit_id']:
|
||||
obj=self.browse(cr,uid,vals['inherit_id'])
|
||||
child=self.pool.get(vals['model'])
|
||||
error="Inherited view model [%s] and \
|
||||
|
|
|
@ -176,6 +176,7 @@ class module(osv.osv):
|
|||
'menus_by_module': fields.function(_get_views, method=True, string='Menus', type='text', multi="meta", store=True),
|
||||
'reports_by_module': fields.function(_get_views, method=True, string='Reports', type='text', multi="meta", store=True),
|
||||
'views_by_module': fields.function(_get_views, method=True, string='Views', type='text', multi="meta", store=True),
|
||||
'certificate' : fields.char('Quality Certificate', size=64, readonly=True),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
|
@ -186,7 +187,8 @@ class module(osv.osv):
|
|||
_order = 'name'
|
||||
|
||||
_sql_constraints = [
|
||||
('name_uniq', 'unique (name)', 'The name of the module must be unique !')
|
||||
('name_uniq', 'unique (name)', 'The name of the module must be unique !'),
|
||||
('certificate_uniq', 'unique (certificate)', 'The certificate ID of the module must be unique !')
|
||||
]
|
||||
|
||||
def unlink(self, cr, uid, ids, context=None):
|
||||
|
@ -309,6 +311,7 @@ class module(osv.osv):
|
|||
'author': terp.get('author', 'Unknown'),
|
||||
'website': terp.get('website', ''),
|
||||
'license': terp.get('license', 'GPL-2'),
|
||||
'certificate': terp.get('certificate') or None,
|
||||
})
|
||||
cr.execute('DELETE FROM ir_module_module_dependency WHERE module_id = %s', (id,))
|
||||
self._update_dependencies(cr, uid, ids[0], terp.get('depends', []))
|
||||
|
@ -328,6 +331,7 @@ class module(osv.osv):
|
|||
'author': terp.get('author', 'Unknown'),
|
||||
'website': terp.get('website', ''),
|
||||
'license': terp.get('license', 'GPL-2'),
|
||||
'certificate': terp.get('certificate') or None,
|
||||
})
|
||||
res[1] += 1
|
||||
self._update_dependencies(cr, uid, id, terp.get('depends', []))
|
||||
|
@ -408,6 +412,7 @@ class module(osv.osv):
|
|||
'author': terp.get('author', 'Unknown'),
|
||||
'website': terp.get('website', ''),
|
||||
'license': terp.get('license', 'GPL-2'),
|
||||
'certificate': terp.get('certificate') or None,
|
||||
})
|
||||
cr.execute('DELETE FROM ir_module_module_dependency ' \
|
||||
'WHERE module_id = %s', (mod.id,))
|
||||
|
@ -463,29 +468,21 @@ class module(osv.osv):
|
|||
if os.path.exists(f):
|
||||
logger.notifyChannel("init", netsvc.LOG_INFO, 'module %s: loading translation file for language %s' % (mod.name, lang))
|
||||
tools.trans_load(cr.dbname, f, lang, verbose=False)
|
||||
|
||||
|
||||
def write(self, cr, uid, ids, vals, context=None):
|
||||
# Override the write method because we want to show a warning when the description field is empty !
|
||||
if isinstance( ids, (long, int) ):
|
||||
ids = [ids]
|
||||
if 'description' in vals and not vals['description']:
|
||||
logger = netsvc.Logger()
|
||||
for mod in self.browse(cr, uid, ids):
|
||||
logger.notifyChannel("init", netsvc.LOG_WARNING, 'module %s: description is empty !' % (mod.name))
|
||||
|
||||
return super(module, self).write(cr, uid, ids, vals, context=context)
|
||||
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
# Override the create method because we want to show a warning when the description field is empty !
|
||||
module_id = super(module, self).create(cr, uid, vals, context=context)
|
||||
|
||||
if 'description' in vals and not vals['description']:
|
||||
logger = netsvc.Logger()
|
||||
for mod in self.browse(cr, uid, [module_id]):
|
||||
logger.notifyChannel("init", netsvc.LOG_WARNING, 'module %s: description is empty !' % (mod.name))
|
||||
|
||||
return module_id
|
||||
def check(self, cr, uid, ids, context=None):
|
||||
logger = netsvc.Logger()
|
||||
for mod in self.browse(cr, uid, ids, context=context):
|
||||
if not mod.description:
|
||||
logger.notifyChannel("init", netsvc.LOG_WARNING, 'module %s: description is empty !' % (mod.name,))
|
||||
|
||||
if not mod.certificate:
|
||||
logger.notifyChannel('init', netsvc.LOG_WARNING, 'module %s: no quality certificate' % (mod.name,))
|
||||
else:
|
||||
val = long(mod.certificate) % 97 == 29
|
||||
if not val:
|
||||
logger.notifyChannel('init', netsvc.LOG_CRITICAL, 'module %s: invalid quality certificate: %s' % (mod.name, mod.certificate))
|
||||
raise osv.except_osv(_('Error'), _('Module %s: Invalid Quality Certificate') % (mod.name,))
|
||||
|
||||
module()
|
||||
|
||||
|
|
|
@ -64,6 +64,7 @@
|
|||
<field name="arch" type="xml">
|
||||
<form string="Module">
|
||||
<field name="name" select="1"/>
|
||||
<field name="certificate" />
|
||||
<field colspan="4" name="shortdesc" select="2"/>
|
||||
<notebook colspan="4">
|
||||
<page string="Module">
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
import wizard
|
||||
import tools
|
||||
import base64
|
||||
import StringIO
|
||||
import cStringIO
|
||||
import csv
|
||||
import pooler
|
||||
from osv import fields,osv
|
||||
|
@ -49,7 +49,7 @@ class wizard_export_lang(osv.osv_memory):
|
|||
this = self.browse(cr, uid, ids)[0]
|
||||
mods = map(lambda m: m.name, this.modules) or ['all']
|
||||
mods.sort()
|
||||
buf=StringIO.StringIO()
|
||||
buf=cStringIO.StringIO()
|
||||
tools.trans_export(this.lang, mods, buf, this.format, dbname=cr.dbname)
|
||||
if this.format == 'csv':
|
||||
this.advice = _("Save this document to a .CSV file and open it with your favourite spreadsheet software. The file encoding is UTF-8. You have to translate the latest column before reimporting it.")
|
||||
|
|
|
@ -28,7 +28,7 @@ import os
|
|||
import tools
|
||||
|
||||
import zipfile
|
||||
import StringIO
|
||||
from StringIO import StringIO
|
||||
import base64
|
||||
|
||||
finish_form ='''<?xml version="1.0"?>
|
||||
|
@ -55,7 +55,8 @@ class move_module_wizard(wizard.interface):
|
|||
module_data = data['form']['module_file']
|
||||
|
||||
val =base64.decodestring(module_data)
|
||||
fp = StringIO.StringIO(val)
|
||||
fp = StringIO()
|
||||
fp.write(val)
|
||||
fdata = zipfile.ZipFile(fp, 'r')
|
||||
fname = fdata.namelist()[0]
|
||||
module_name = os.path.split(fname)[0]
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
from osv import osv, fields
|
||||
import tools
|
||||
import pooler
|
||||
import StringIO
|
||||
import cStringIO
|
||||
|
||||
class update_translations(osv.osv_memory):
|
||||
def _get_languages(self, cr, uid, context):
|
||||
|
@ -45,7 +45,7 @@ class update_translations(osv.osv_memory):
|
|||
def act_update(self, cr, uid, ids, context=None):
|
||||
this = self.browse(cr, uid, ids)[0]
|
||||
lang_name = self._get_lang_name(cr, uid, this.lang)
|
||||
buf=StringIO.StringIO()
|
||||
buf=cStringIO.StringIO()
|
||||
tools.trans_export(this.lang, ['all'], buf, 'csv', dbname=cr.dbname)
|
||||
tools.trans_load_data(cr.dbname, buf, 'csv', this.lang, lang_name=lang_name)
|
||||
buf.close()
|
||||
|
|
178
bin/netsvc.py
178
bin/netsvc.py
|
@ -38,81 +38,21 @@ import time
|
|||
import xmlrpclib
|
||||
import release
|
||||
|
||||
_service = {}
|
||||
_group = {}
|
||||
_res_id = 1
|
||||
_res = {}
|
||||
|
||||
class ServiceEndPointCall(object):
|
||||
def __init__(self, id, method):
|
||||
self._id = id
|
||||
self._meth = method
|
||||
|
||||
def __call__(self, *args):
|
||||
_res[self._id] = self._meth(*args)
|
||||
return self._id
|
||||
|
||||
|
||||
class ServiceEndPoint(object):
|
||||
def __init__(self, name, id):
|
||||
self._id = id
|
||||
self._meth = {}
|
||||
s = _service[name]
|
||||
for m in s._method:
|
||||
self._meth[m] = s._method[m]
|
||||
|
||||
def __getattr__(self, name):
|
||||
return ServiceEndPointCall(self._id, self._meth[name])
|
||||
|
||||
SERVICES = {}
|
||||
GROUPS = {}
|
||||
|
||||
class Service(object):
|
||||
_serviceEndPointID = 0
|
||||
|
||||
def __init__(self, name, audience=''):
|
||||
_service[name] = self
|
||||
SERVICES[name] = self
|
||||
self.__name = name
|
||||
self._method = {}
|
||||
self.exportedMethods = None
|
||||
self._response_process = None
|
||||
self._response_process_id = None
|
||||
self._response = None
|
||||
self._methods = {}
|
||||
|
||||
def joinGroup(self, name):
|
||||
if not name in _group:
|
||||
_group[name] = {}
|
||||
_group[name][self.__name] = self
|
||||
GROUPS.setdefault(name, {})[self.__name] = self
|
||||
|
||||
def exportMethod(self, m):
|
||||
if callable(m):
|
||||
self._method[m.__name__] = m
|
||||
|
||||
def serviceEndPoint(self, s):
|
||||
if Service._serviceEndPointID >= 2**16:
|
||||
Service._serviceEndPointID = 0
|
||||
Service._serviceEndPointID += 1
|
||||
return ServiceEndPoint(s, self._serviceEndPointID)
|
||||
|
||||
def conversationId(self):
|
||||
return 1
|
||||
|
||||
def processResponse(self, s, id):
|
||||
self._response_process, self._response_process_id = s, id
|
||||
|
||||
def processFailure(self, s, id):
|
||||
pass
|
||||
|
||||
def resumeResponse(self, s):
|
||||
pass
|
||||
|
||||
def cancelResponse(self, s):
|
||||
pass
|
||||
|
||||
def suspendResponse(self, s):
|
||||
if self._response_process:
|
||||
self._response_process(self._response_process_id,
|
||||
_res[self._response_process_id])
|
||||
self._response_process = None
|
||||
self._response = s(self._response_process_id)
|
||||
def exportMethod(self, method):
|
||||
if callable(method):
|
||||
self._methods[method.__name__] = method
|
||||
|
||||
def abortResponse(self, error, description, origin, details):
|
||||
if not tools.config['debug_mode']:
|
||||
|
@ -120,24 +60,21 @@ class Service(object):
|
|||
else:
|
||||
raise
|
||||
|
||||
def currentFailure(self, s):
|
||||
pass
|
||||
|
||||
|
||||
class LocalService(Service):
|
||||
def __init__(self, name):
|
||||
self.__name = name
|
||||
try:
|
||||
s = _service[name]
|
||||
self._service = s
|
||||
for m in s._method:
|
||||
setattr(self, m, s._method[m])
|
||||
self._service = SERVICES[name]
|
||||
for method_name, method_definition in self._service._methods.items():
|
||||
setattr(self, method_name, method_definition)
|
||||
except KeyError, keyError:
|
||||
Logger().notifyChannel('module', LOG_ERROR, 'This service does not exists: %s' % (str(keyError),) )
|
||||
raise
|
||||
def __call__(self, method, *params):
|
||||
return getattr(self, method)(*params)
|
||||
|
||||
def service_exist(name):
|
||||
return _service.get(name, False)
|
||||
return SERVICES.get(name, False)
|
||||
|
||||
LOG_NOTSET = 'notset'
|
||||
LOG_DEBUG_RPC = 'debug_rpc'
|
||||
|
@ -223,6 +160,9 @@ class Logger(object):
|
|||
|
||||
level_method = getattr(log, level)
|
||||
|
||||
if isinstance(msg, Exception):
|
||||
msg = tools.exception_to_unicode(msg)
|
||||
|
||||
result = tools.ustr(msg).strip().split('\n')
|
||||
if len(result)>1:
|
||||
for idx, s in enumerate(result):
|
||||
|
@ -268,34 +208,40 @@ class xmlrpc(object):
|
|||
def __init__(self, name):
|
||||
self.name = name
|
||||
|
||||
class GenericXMLRPCRequestHandler:
|
||||
class OpenERPDispatcherException(Exception):
|
||||
def __init__(self, exception, traceback):
|
||||
self.exception = exception
|
||||
self.traceback = traceback
|
||||
|
||||
class OpenERPDispatcher:
|
||||
def log(self, title, msg):
|
||||
from pprint import pformat
|
||||
Logger().notifyChannel('XMLRPC-%s' % title, LOG_DEBUG_RPC, pformat(msg))
|
||||
Logger().notifyChannel('%s' % title, LOG_DEBUG_RPC, pformat(msg))
|
||||
|
||||
def _dispatch(self, method, params):
|
||||
def dispatch(self, service_name, method, params):
|
||||
try:
|
||||
self.log('service', service_name)
|
||||
self.log('method', method)
|
||||
self.log('params', params)
|
||||
n = self.path.split("/")[-1]
|
||||
s = LocalService(n)
|
||||
m = getattr(s, method)
|
||||
s._service._response = None
|
||||
r = m(*params)
|
||||
self.log('result', r)
|
||||
res = s._service._response
|
||||
if res is not None:
|
||||
r = res
|
||||
self.log('res',r)
|
||||
return r
|
||||
result = LocalService(service_name)(method, *params)
|
||||
self.log('result', result)
|
||||
return result
|
||||
except Exception, e:
|
||||
self.log('exception', e)
|
||||
self.log('exception', tools.exception_to_unicode(e))
|
||||
tb = sys.exc_info()
|
||||
tb_s = "".join(traceback.format_exception(*tb))
|
||||
if tools.config['debug_mode']:
|
||||
import pdb
|
||||
pdb.post_mortem(tb[2])
|
||||
raise xmlrpclib.Fault(str(e), tb_s)
|
||||
raise OpenERPDispatcherException(e, tb_s)
|
||||
|
||||
class GenericXMLRPCRequestHandler(OpenERPDispatcher):
|
||||
def _dispatch(self, method, params):
|
||||
try:
|
||||
service_name = self.path.split("/")[-1]
|
||||
return self.dispatch(service_name, method, params)
|
||||
except OpenERPDispatcherException, e:
|
||||
raise xmlrpclib.Fault(tools.exception_to_unicode(e.exception), e.traceback)
|
||||
|
||||
class SSLSocket(object):
|
||||
def __init__(self, socket):
|
||||
|
@ -331,7 +277,7 @@ class doesitgohere():
|
|||
|
||||
|
||||
class SimpleXMLRPCRequestHandler(GenericXMLRPCRequestHandler, SimpleXMLRPCServer.SimpleXMLRPCRequestHandler):
|
||||
rpc_paths = map(lambda s: '/xmlrpc/%s' % s, _service)
|
||||
rpc_paths = map(lambda s: '/xmlrpc/%s' % s, SERVICES.keys())
|
||||
|
||||
class SecureXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
||||
def setup(self):
|
||||
|
@ -382,11 +328,10 @@ class HttpDaemon(threading.Thread):
|
|||
from OpenSSL.SSL import Error as SSLError
|
||||
else:
|
||||
class SSLError(Exception): pass
|
||||
|
||||
try:
|
||||
try:
|
||||
self.server = server_class((interface, port), handler_class, 0)
|
||||
except SSLError, e:
|
||||
Logger().notifyChannel('xml-rpc-ssl', LOG_CRITICAL, "Can't load the certificate and/or the private key files")
|
||||
Logger().notifyChannel('xml-rpc-ssl', LOG_CRITICAL, "Can not load the certificate and/or the private key files")
|
||||
sys.exit(1)
|
||||
except Exception, e:
|
||||
Logger().notifyChannel('xml-rpc', LOG_CRITICAL, "Error occur when strarting the server daemon: %s" % (e,))
|
||||
|
@ -419,19 +364,13 @@ class HttpDaemon(threading.Thread):
|
|||
#signal.alarm(0) # Disable the alarm
|
||||
|
||||
import tiny_socket
|
||||
class TinySocketClientThread(threading.Thread):
|
||||
class TinySocketClientThread(threading.Thread, OpenERPDispatcher):
|
||||
def __init__(self, sock, threads):
|
||||
threading.Thread.__init__(self)
|
||||
self.sock = sock
|
||||
self.threads = threads
|
||||
self._logger = Logger()
|
||||
|
||||
def log(self, msg):
|
||||
from pprint import pformat
|
||||
self._logger.notifyChannel('NETRPC', LOG_DEBUG_RPC, pformat(msg))
|
||||
|
||||
def run(self):
|
||||
import time
|
||||
import select
|
||||
self.running = True
|
||||
try:
|
||||
|
@ -448,27 +387,12 @@ class TinySocketClientThread(threading.Thread):
|
|||
self.threads.remove(self)
|
||||
return False
|
||||
try:
|
||||
self.log(msg)
|
||||
service = LocalService(msg[0])
|
||||
method = getattr(service, msg[1])
|
||||
service._service._response = None
|
||||
result_from_method = method(*msg[2:])
|
||||
res = service._service._response
|
||||
if res != None:
|
||||
result_from_method = res
|
||||
self.log(result_from_method)
|
||||
ts.mysend(result_from_method)
|
||||
except Exception, e:
|
||||
self.log(e)
|
||||
tb = sys.exc_info()
|
||||
tb_s = "".join(traceback.format_exception(*tb))
|
||||
if tools.config['debug_mode']:
|
||||
import pdb
|
||||
pdb.post_mortem(tb[2])
|
||||
e = Exception(tools.ustr(e)) # avoid problems of pickeling
|
||||
ts.mysend(e, exception=True, traceback=tb_s)
|
||||
except:
|
||||
pass
|
||||
result = self.dispatch(msg[0], msg[1], msg[2:])
|
||||
ts.mysend(result)
|
||||
except OpenERPDispatcherException, e:
|
||||
new_e = Exception(tools.exception_to_unicode(e.exception)) # avoid problems of pickeling
|
||||
ts.mysend(new_e, exception=True, traceback=e.traceback)
|
||||
|
||||
self.sock.close()
|
||||
self.threads.remove(self)
|
||||
return True
|
||||
|
@ -515,8 +439,4 @@ class TinySocketServerThread(threading.Thread):
|
|||
except:
|
||||
return False
|
||||
|
||||
|
||||
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
|
|
@ -823,7 +823,7 @@ class orm_template(object):
|
|||
elif node.nodeType==node.ELEMENT_NODE and node.localName in ('form', 'tree'):
|
||||
result = self.view_header_get(cr, user, False, node.localName, context)
|
||||
if result:
|
||||
node.setAttribute('string', result.decode('utf-8'))
|
||||
node.setAttribute('string', result)
|
||||
|
||||
elif node.nodeType==node.ELEMENT_NODE and node.localName == 'calendar':
|
||||
for additional_field in ('date_start', 'date_delay', 'date_stop', 'color'):
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# -*- encoding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
|
||||
# $Id$
|
||||
#
|
||||
|
@ -87,7 +87,6 @@ class osv_pool(netsvc.Service):
|
|||
self._init_parent = {}
|
||||
netsvc.Service.__init__(self, 'object_proxy', audience='')
|
||||
self.joinGroup('web-services')
|
||||
self.exportMethod(self.exportedMethods)
|
||||
self.exportMethod(self.obj_list)
|
||||
self.exportMethod(self.exec_workflow)
|
||||
self.exportMethod(self.execute)
|
||||
|
@ -262,3 +261,5 @@ class osv(orm.orm):
|
|||
self.pool = pool
|
||||
orm.orm.__init__(self, cr)
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
|
|
@ -35,7 +35,13 @@ def get_db_and_pool(db_name, force_demo=False, status=None, update_module=False)
|
|||
import osv.osv
|
||||
pool = osv.osv.osv_pool()
|
||||
pool_dic[db_name] = pool
|
||||
addons.load_modules(db, force_demo, status, update_module)
|
||||
|
||||
try:
|
||||
addons.load_modules(db, force_demo, status, update_module)
|
||||
except Exception, e:
|
||||
del pool_dic[db_name]
|
||||
raise
|
||||
|
||||
cr = db.cursor()
|
||||
try:
|
||||
pool.init_set(cr, False)
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
#
|
||||
##############################################################################
|
||||
|
||||
import os, time
|
||||
import os
|
||||
import time
|
||||
import netsvc
|
||||
|
||||
import tools
|
||||
|
@ -37,7 +38,7 @@ import libxml2
|
|||
import libxslt
|
||||
from pychart import *
|
||||
import misc
|
||||
import StringIO
|
||||
import cStringIO
|
||||
|
||||
class external_pdf(render.render):
|
||||
def __init__(self, pdf):
|
||||
|
@ -157,8 +158,13 @@ class report_custom(report_int):
|
|||
row = []
|
||||
cond = []
|
||||
for i in range(4):
|
||||
if f['field_child'+str(i)]:
|
||||
row.append(f['field_child'+str(i)][1])
|
||||
field_child = f['field_child'+str(i)]
|
||||
if field_child:
|
||||
row.append(
|
||||
service.execute(cr.dbname, uid,
|
||||
'ir.model.fields', 'read', [field_child[0]],
|
||||
['name'], context=context)[0]['name']
|
||||
)
|
||||
if f['fc'+str(i)+'_operande']:
|
||||
fct_name = 'id'
|
||||
cond_op = f['fc'+str(i)+'_op']
|
||||
|
@ -358,7 +364,7 @@ class report_custom(report_int):
|
|||
|
||||
def _create_lines(self, cr, uid, ids, report, fields, results, context):
|
||||
service = netsvc.LocalService("object_proxy")
|
||||
pdf_string = StringIO.StringIO()
|
||||
pdf_string = cStringIO.StringIO()
|
||||
can = canvas.init(fname=pdf_string, format='pdf')
|
||||
|
||||
can.show(80,380,'/16/H'+report['title'])
|
||||
|
@ -461,7 +467,7 @@ class report_custom(report_int):
|
|||
|
||||
def _create_bars(self, cr, uid, ids, report, fields, results, context):
|
||||
service = netsvc.LocalService("object_proxy")
|
||||
pdf_string = StringIO.StringIO()
|
||||
pdf_string = cStringIO.StringIO()
|
||||
can = canvas.init(fname=pdf_string, format='pdf')
|
||||
|
||||
can.show(80,380,'/16/H'+report['title'])
|
||||
|
@ -558,7 +564,7 @@ class report_custom(report_int):
|
|||
return True
|
||||
|
||||
def _create_pie(self, cr, uid, ids, report, fields, results, context):
|
||||
pdf_string = StringIO.StringIO()
|
||||
pdf_string = cStringIO.StringIO()
|
||||
can = canvas.init(fname=pdf_string, format='pdf')
|
||||
ar = area.T(size=(350,350), legend=legend.T(),
|
||||
x_grid_style = None, y_grid_style = None)
|
||||
|
|
|
@ -162,9 +162,11 @@ class document(object):
|
|||
fname = str(datas['datas_fname'])
|
||||
ext = fname.split('.')[-1].lower()
|
||||
if ext in ('jpg','jpeg', 'png'):
|
||||
import base64, StringIO
|
||||
import base64
|
||||
from StringIO import StringIO
|
||||
dt = base64.decodestring(datas['datas'])
|
||||
fp = StringIO.StringIO(dt)
|
||||
fp = StringIO()
|
||||
fp.write(dt)
|
||||
i = str(len(self.bin_datas))
|
||||
self.bin_datas[i] = fp
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
import sys
|
||||
import StringIO
|
||||
import cStringIO
|
||||
import xml.dom.minidom
|
||||
import copy
|
||||
|
||||
|
@ -365,7 +365,7 @@ def parseString(data, fout=None):
|
|||
fp.close()
|
||||
return fout
|
||||
else:
|
||||
fp = StringIO.StringIO()
|
||||
fp = cStringIO.StringIO()
|
||||
r.render(fp)
|
||||
return fp.getvalue()
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
import sys
|
||||
import StringIO
|
||||
from StringIO import StringIO
|
||||
import xml.dom.minidom
|
||||
import copy
|
||||
|
||||
|
@ -351,26 +351,26 @@ class _rml_canvas(object):
|
|||
import urllib
|
||||
from reportlab.lib.utils import ImageReader
|
||||
|
||||
s = StringIO()
|
||||
if not node.hasAttribute('file'):
|
||||
|
||||
if node.hasAttribute('name'):
|
||||
image_data = self.images[node.getAttribute('name')]
|
||||
s = StringIO.StringIO(image_data)
|
||||
s.write(image_data)
|
||||
else:
|
||||
import base64
|
||||
image_data = base64.decodestring(node.firstChild.nodeValue)
|
||||
if not image_data: return False
|
||||
s = StringIO.StringIO(image_data)
|
||||
s.write(image_data)
|
||||
else:
|
||||
if node.getAttribute('file') in self.images:
|
||||
s = StringIO.StringIO(self.images[node.getAttribute('file')])
|
||||
s.write(self.images[node.getAttribute('file')])
|
||||
else:
|
||||
try:
|
||||
u = urllib.urlopen(str(node.getAttribute('file')))
|
||||
s = StringIO.StringIO(u.read())
|
||||
except:
|
||||
u = file(os.path.join(self.path,str(node.getAttribute('file'))), 'rb')
|
||||
s = StringIO.StringIO(u.read())
|
||||
s.write(u.read())
|
||||
img = ImageReader(s)
|
||||
(sx,sy) = img.getSize()
|
||||
|
||||
|
@ -639,7 +639,8 @@ class _rml_flowable(object):
|
|||
else:
|
||||
import base64
|
||||
image_data = base64.decodestring(node.firstChild.nodeValue)
|
||||
image = StringIO.StringIO(image_data)
|
||||
image = StringIO()
|
||||
image.write(image_data)
|
||||
return platypus.Image(image, mask=(250,255,250,255,250,255), **(utils.attr_get(node, ['width','height'])))
|
||||
else:
|
||||
return platypus.Image(node.getAttribute('file'), mask=(250,255,250,255,250,255), **(utils.attr_get(node, ['width','height'])))
|
||||
|
@ -794,7 +795,7 @@ def parseString(data, fout=None, images={}, path='.',title=None):
|
|||
fp.close()
|
||||
return fout
|
||||
else:
|
||||
fp = StringIO.StringIO()
|
||||
fp = StringIO()
|
||||
r.render(fp)
|
||||
return fp.getvalue()
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
import render
|
||||
|
||||
from StringIO import StringIO
|
||||
from cStringIO import StringIO
|
||||
import xml.dom.minidom
|
||||
|
||||
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Table
|
||||
|
|
|
@ -28,6 +28,7 @@ import string
|
|||
import thread
|
||||
import threading
|
||||
import time
|
||||
import sys
|
||||
|
||||
from tools.translate import _
|
||||
import addons
|
||||
|
@ -67,12 +68,14 @@ class db(netsvc.Service):
|
|||
|
||||
self.actions[id] = {'clean': False}
|
||||
|
||||
db = sql_db.db_connect('template1', serialize=1)
|
||||
db = sql_db.db_connect('template1')
|
||||
cr = db.cursor()
|
||||
cr.autocommit(True)
|
||||
time.sleep(0.2)
|
||||
cr.execute('CREATE DATABASE ' + db_name + ' ENCODING \'unicode\'')
|
||||
cr.close()
|
||||
try:
|
||||
cr.autocommit(True)
|
||||
cr.execute('CREATE DATABASE ' + db_name + ' ENCODING \'unicode\'')
|
||||
finally:
|
||||
cr.close()
|
||||
sql_db.close_db('template1')
|
||||
class DBInitialize(object):
|
||||
def __call__(self, serv, id, db_name, demo, lang, user_password='admin'):
|
||||
try:
|
||||
|
@ -105,7 +108,7 @@ class db(netsvc.Service):
|
|||
except Exception, e:
|
||||
serv.actions[id]['clean'] = False
|
||||
serv.actions[id]['exception'] = e
|
||||
from StringIO import StringIO
|
||||
from cStringIO import StringIO
|
||||
import traceback
|
||||
e_str = StringIO()
|
||||
traceback.print_exc(file=e_str)
|
||||
|
@ -145,7 +148,7 @@ class db(netsvc.Service):
|
|||
sql_db.close_db(db_name)
|
||||
logger = netsvc.Logger()
|
||||
|
||||
db = sql_db.db_connect('template1', serialize=1)
|
||||
db = sql_db.db_connect('template1')
|
||||
cr = db.cursor()
|
||||
cr.autocommit(True)
|
||||
try:
|
||||
|
@ -160,6 +163,7 @@ class db(netsvc.Service):
|
|||
'DROP DB: %s' % (db_name))
|
||||
finally:
|
||||
cr.close()
|
||||
sql_db.close_db('template1')
|
||||
return True
|
||||
|
||||
def dump(self, password, db_name):
|
||||
|
@ -196,11 +200,14 @@ class db(netsvc.Service):
|
|||
'RESTORE DB: %s already exists' % (db_name,))
|
||||
raise Exception, "Database already exists"
|
||||
|
||||
db = sql_db.db_connect('template1', serialize=1)
|
||||
db = sql_db.db_connect('template1')
|
||||
cr = db.cursor()
|
||||
cr.autocommit(True)
|
||||
cr.execute('CREATE DATABASE ' + db_name + ' ENCODING \'unicode\'')
|
||||
cr.close()
|
||||
try:
|
||||
cr.execute('CREATE DATABASE ' + db_name + ' ENCODING \'unicode\'')
|
||||
finally:
|
||||
cr.close()
|
||||
sql_db.close_db('template1')
|
||||
|
||||
cmd = ['pg_restore']
|
||||
if tools.config['db_user']:
|
||||
|
@ -239,24 +246,28 @@ class db(netsvc.Service):
|
|||
|
||||
def list(self):
|
||||
db = sql_db.db_connect('template1')
|
||||
cr = db.cursor()
|
||||
try:
|
||||
cr = db.cursor()
|
||||
db_user = tools.config["db_user"]
|
||||
if not db_user and os.name == 'posix':
|
||||
import pwd
|
||||
db_user = pwd.getpwuid(os.getuid())[0]
|
||||
if not db_user:
|
||||
cr.execute("select decode(usename, 'escape') from pg_user where usesysid=(select datdba from pg_database where datname=%s)", (tools.config["db_name"],))
|
||||
res = cr.fetchone()
|
||||
db_user = res and str(res[0])
|
||||
if db_user:
|
||||
cr.execute("select decode(datname, 'escape') from pg_database where datdba=(select usesysid from pg_user where usename=%s) and datname not in ('template0', 'template1', 'postgres')", (db_user,))
|
||||
else:
|
||||
cr.execute("select decode(datname, 'escape') from pg_database where datname not in('template0', 'template1','postgres')")
|
||||
res = [str(name) for (name,) in cr.fetchall()]
|
||||
try:
|
||||
cr = db.cursor()
|
||||
db_user = tools.config["db_user"]
|
||||
if not db_user and os.name == 'posix':
|
||||
import pwd
|
||||
db_user = pwd.getpwuid(os.getuid())[0]
|
||||
if not db_user:
|
||||
cr.execute("select decode(usename, 'escape') from pg_user where usesysid=(select datdba from pg_database where datname=%s)", (tools.config["db_name"],))
|
||||
res = cr.fetchone()
|
||||
db_user = res and str(res[0])
|
||||
if db_user:
|
||||
cr.execute("select decode(datname, 'escape') from pg_database where datdba=(select usesysid from pg_user where usename=%s) and datname not in ('template0', 'template1', 'postgres')", (db_user,))
|
||||
else:
|
||||
cr.execute("select decode(datname, 'escape') from pg_database where datname not in('template0', 'template1','postgres')")
|
||||
res = [str(name) for (name,) in cr.fetchall()]
|
||||
except:
|
||||
res = []
|
||||
finally:
|
||||
cr.close()
|
||||
except:
|
||||
res = []
|
||||
sql_db.close_db('template1')
|
||||
res.sort()
|
||||
return res
|
||||
|
||||
|
@ -276,6 +287,10 @@ class db(netsvc.Service):
|
|||
return release.version
|
||||
|
||||
def migrate_databases(self, password, databases):
|
||||
|
||||
from osv.orm import except_orm
|
||||
from osv.osv import except_osv
|
||||
|
||||
security.check_super(password)
|
||||
l = netsvc.Logger()
|
||||
for db in databases:
|
||||
|
@ -283,14 +298,18 @@ class db(netsvc.Service):
|
|||
l.notifyChannel('migration', netsvc.LOG_INFO, 'migrate database %s' % (db,))
|
||||
tools.config['update']['base'] = True
|
||||
pooler.restart_pool(db, force_demo=False, update_module=True)
|
||||
except except_orm, inst:
|
||||
self.abortResponse(1, inst.name, 'warning', inst.value)
|
||||
except except_osv, inst:
|
||||
self.abortResponse(1, inst.name, inst.exc_type, inst.value)
|
||||
except Exception, e:
|
||||
tools.debug(e)
|
||||
import traceback
|
||||
tb_s = reduce(lambda x, y: x+y, traceback.format_exception( sys.exc_type, sys.exc_value, sys.exc_traceback))
|
||||
l.notifyChannel('web-services', netsvc.LOG_ERROR, tb_s)
|
||||
raise
|
||||
return True
|
||||
db()
|
||||
|
||||
class MigrationException(Exception): pass
|
||||
|
||||
class common(netsvc.Service):
|
||||
def __init__(self,name="common"):
|
||||
netsvc.Service.__init__(self,name)
|
||||
|
@ -372,12 +391,12 @@ GNU Public Licence.
|
|||
security.check_super(password)
|
||||
l = netsvc.Logger()
|
||||
try:
|
||||
from tools.maintenance import remote_contract
|
||||
rc = remote_contract(contract_id, contract_password)
|
||||
import tools.maintenance as tm
|
||||
rc = tm.remote_contract(contract_id, contract_password)
|
||||
if not rc.id:
|
||||
raise MigrationException('This contract does not exist or is not active')
|
||||
raise tm.RemoteContractException('This contract does not exist or is not active')
|
||||
if rc.status != 'full':
|
||||
raise MigrationException('Can not get updates for a partial contract')
|
||||
raise tm.RemoteContractException('Can not get updates for a partial contract')
|
||||
|
||||
l.notifyChannel('migration', netsvc.LOG_INFO, 'starting migration with contract %s' % (rc.name,))
|
||||
|
||||
|
@ -389,7 +408,10 @@ GNU Public Licence.
|
|||
mp = addons.get_module_path(module)
|
||||
if mp:
|
||||
if os.path.isdir(mp):
|
||||
rmtree(os.path.realpath(mp))
|
||||
if os.path.islink(mp):
|
||||
os.unlink(mp)
|
||||
else:
|
||||
rmtree(mp)
|
||||
else:
|
||||
os.unlink(mp + '.zip')
|
||||
|
||||
|
@ -400,7 +422,7 @@ GNU Public Licence.
|
|||
zip.close()
|
||||
|
||||
return True
|
||||
except MigrationException, e:
|
||||
except tm.RemoteContractException, e:
|
||||
self.abortResponse(1, 'Migration Error', 'warning', str(e))
|
||||
except Exception, e:
|
||||
import traceback
|
||||
|
|
|
@ -231,7 +231,7 @@ class PoolManager(object):
|
|||
cls._pools[db_name].closeall()
|
||||
del cls._pools[db_name]
|
||||
|
||||
def db_connect(db_name, serialize=0):
|
||||
def db_connect(db_name):
|
||||
return PoolManager.get(db_name)
|
||||
|
||||
def close_db(db_name):
|
||||
|
|
|
@ -20,8 +20,11 @@
|
|||
#
|
||||
##############################################################################
|
||||
import re
|
||||
import StringIO,xml.dom.minidom
|
||||
import osv,ir,pooler
|
||||
import cStringIO
|
||||
import xml.dom.minidom
|
||||
import osv
|
||||
import ir
|
||||
import pooler
|
||||
|
||||
import csv
|
||||
import os.path
|
||||
|
@ -811,7 +814,7 @@ def convert_csv_import(cr, module, fname, csvcontent, idref=None, mode='init',
|
|||
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
|
||||
input = StringIO.StringIO(csvcontent)
|
||||
input = cStringIO.StringIO(csvcontent)
|
||||
reader = csv.reader(input, quotechar='"', delimiter=',')
|
||||
fields = reader.next()
|
||||
fname_partial = ""
|
||||
|
|
|
@ -22,15 +22,20 @@
|
|||
|
||||
import xmlrpclib
|
||||
|
||||
class RemoteContractException(Exception): pass
|
||||
|
||||
class remote_contract(object):
|
||||
def __init__(self, contract_id, contract_password, modules=None):
|
||||
self.__server = 'http://localhost:8069/xmlrpc/'
|
||||
self.__db = "trunk"
|
||||
self.__server = 'http://192.168.0.127:8072/xmlrpc/'
|
||||
self.__db = "maintenance"
|
||||
self.__password = "admin"
|
||||
self.__login = "admin"
|
||||
|
||||
rpc = xmlrpclib.ServerProxy(self.__server + 'common')
|
||||
self.__userid = rpc.login(self.__db, self.__login, self.__password)
|
||||
try:
|
||||
self.__userid = rpc.login(self.__db, self.__login, self.__password)
|
||||
except:
|
||||
raise RemoteContractException("Unable to contact the migration server")
|
||||
|
||||
self.__rpc = xmlrpclib.ServerProxy(self.__server + 'object')
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ from itertools import izip
|
|||
def init_db(cr):
|
||||
import addons
|
||||
f = addons.get_module_resource('base', 'base.sql')
|
||||
for line in file(f).read().split(';'):
|
||||
for line in file_open(f).read().split(';'):
|
||||
if (len(line)>0) and (not line.isspace()):
|
||||
cr.execute(line)
|
||||
cr.commit()
|
||||
|
@ -55,12 +55,8 @@ def init_db(cr):
|
|||
if not mod_path:
|
||||
continue
|
||||
info = False
|
||||
if os.path.isfile(terp_file) and not os.path.isfile(mod_path+'.zip'):
|
||||
info = eval(file(terp_file).read())
|
||||
elif zipfile.is_zipfile(mod_path+'.zip'):
|
||||
zfile = zipfile.ZipFile(mod_path+'.zip')
|
||||
i = os.path.splitext(i)[0]
|
||||
info = eval(zfile.read(os.path.join(i, '__terp__.py')))
|
||||
if os.path.isfile(terp_file) or os.path.isfile(mod_path+'.zip'):
|
||||
info = eval(file_open(terp_file).read())
|
||||
if info:
|
||||
categs = info.get('category', 'Uncategorized').split('/')
|
||||
p_id = None
|
||||
|
@ -224,13 +220,14 @@ def file_open(name, mode="r", subdir='addons', pathinfo=False):
|
|||
else:
|
||||
zipname = tail
|
||||
if zipfile.is_zipfile(head+'.zip'):
|
||||
import StringIO
|
||||
from cStringIO import StringIO
|
||||
zfile = zipfile.ZipFile(head+'.zip')
|
||||
try:
|
||||
fo = StringIO.StringIO(zfile.read(os.path.join(
|
||||
fo = StringIO()
|
||||
fo.write(zfile.read(os.path.join(
|
||||
os.path.basename(head), zipname).replace(
|
||||
os.sep, '/')))
|
||||
|
||||
fo.seek(0)
|
||||
if pathinfo:
|
||||
return fo, name
|
||||
return fo
|
||||
|
@ -560,7 +557,7 @@ class cache(object):
|
|||
|
||||
def to_tuple(d):
|
||||
i = d.items()
|
||||
i.sort()
|
||||
i.sort(key=lambda (x,y): x)
|
||||
return tuple(i)
|
||||
|
||||
if not self.multi:
|
||||
|
@ -569,7 +566,7 @@ class cache(object):
|
|||
else:
|
||||
multis = kwargs2[self.multi][:]
|
||||
for id in multis:
|
||||
kwargs2[self.multi] = [id]
|
||||
kwargs2[self.multi] = (id,)
|
||||
key = (('dbname', dbname),) + to_tuple(kwargs2)
|
||||
yield key, id
|
||||
|
||||
|
@ -614,7 +611,6 @@ class cache(object):
|
|||
self.fun_default_values = {}
|
||||
if argspec[3]:
|
||||
self.fun_default_values = dict(zip(self.fun_arg_names[-len(argspec[3]):], argspec[3]))
|
||||
debug(self.fun_default_values)
|
||||
|
||||
def cached_result(self2, cr, *args, **kwargs):
|
||||
if time.time()-self.timeout > self.lasttime:
|
||||
|
@ -680,6 +676,17 @@ def ustr(value):
|
|||
|
||||
return unicode(value, 'utf-8')
|
||||
|
||||
def exception_to_unicode(e):
|
||||
if hasattr(e, 'message'):
|
||||
return ustr(e.message)
|
||||
if hasattr(e, 'args'):
|
||||
return "\n".join((ustr(a) for a in e.args))
|
||||
try:
|
||||
return ustr(e)
|
||||
except:
|
||||
return u"Unknow message"
|
||||
|
||||
|
||||
# to be compatible with python 2.4
|
||||
import __builtin__
|
||||
if not hasattr(__builtin__, 'all'):
|
||||
|
@ -711,19 +718,22 @@ def get_languages():
|
|||
'bs_BS': u'Bosnian / bosanski jezik',
|
||||
'ca_ES': u'Catalan / Català',
|
||||
'cs_CZ': u'Czech / Čeština',
|
||||
'da_DK': u'Danish / Dansk',
|
||||
'de_DE': u'German / Deutsch',
|
||||
'el_EL': u'Greek / Ελληνικά',
|
||||
'en_CA': u'English (CA)',
|
||||
'en_EN': u'English (default)',
|
||||
'en_GB': u'English (UK)',
|
||||
'en_US': u'English (US)',
|
||||
'es_AR': u'Spanish (AR) / Español (AR)',
|
||||
'es_ES': u'Spanish / Español',
|
||||
'et_ET': u'Estonian / Eesti keel',
|
||||
'et_EE': u'Estonian / Eesti keel',
|
||||
'fr_BE': u'French (BE) / Français (BE)',
|
||||
'fr_CH': u'French (CH) / Français (CH)',
|
||||
'fr_FR': u'French / Français',
|
||||
'hr_HR': u'Croatian / hrvatski jezik',
|
||||
'hu_HU': u'Hungarian / Magyar',
|
||||
'id_ID': u'Indonesian / Bahasa Indonesia',
|
||||
'it_IT': u'Italian / Italiano',
|
||||
'lt_LT': u'Lithuanian / Lietuvių kalba',
|
||||
'nl_NL': u'Dutch / Nederlands',
|
||||
|
|
|
@ -351,7 +351,7 @@ def trans_generate(lang, modules, dbname=None):
|
|||
|
||||
_to_translate = []
|
||||
def push_translation(module, type, name, id, source):
|
||||
tuple = (module, type, name, id, source)
|
||||
tuple = (module, source, name, id, type)
|
||||
if source and tuple not in _to_translate:
|
||||
_to_translate.append(tuple)
|
||||
|
||||
|
@ -376,7 +376,7 @@ def trans_generate(lang, modules, dbname=None):
|
|||
elif model=='ir.actions.wizard':
|
||||
service_name = 'wizard.'+encode(obj.wiz_name)
|
||||
try:
|
||||
obj2 = netsvc._service[service_name]
|
||||
obj2 = netsvc.SERVICES[service_name]
|
||||
except KeyError, exc:
|
||||
logger.notifyChannel("db", netsvc.LOG_ERROR, "key error in %s: %s" % (xml_name,str(exc)))
|
||||
continue
|
||||
|
@ -516,8 +516,9 @@ def trans_generate(lang, modules, dbname=None):
|
|||
|
||||
|
||||
out = [["module","type","name","res_id","src","value"]] # header
|
||||
_to_translate.sort()
|
||||
# translate strings marked as to be translated
|
||||
for module, type, name, id, source in _to_translate:
|
||||
for module, source, name, id, type in _to_translate:
|
||||
trans = trans_obj._get_source(cr, uid, name, type, lang, source)
|
||||
out.append([module, type, name, id, source, encode(trans) or ''])
|
||||
|
||||
|
|
Loading…
Reference in New Issue