##############################################################################
import base64
-import logging
import os
import security
import thread
import sql_db
import tools
import locale
+import logging
from cStringIO import StringIO
-logging.basicConfig()
-
class db(netsvc.ExportService):
def __init__(self, name="db"):
netsvc.ExportService.__init__(self, name)
self._set_pg_psw_env_var()
- cmd = ['pg_dump', '--format=c', '--no-owner']
+ cmd = ['pg_dump', '--format=c', '--no-owner' , '-w']
if tools.config['db_user']:
cmd.append('--username=' + tools.config['db_user'])
if tools.config['db_host']:
self._create_empty_database(db_name)
- cmd = ['pg_restore', '--no-owner']
+ cmd = ['pg_restore', '--no-owner', '-w']
if tools.config['db_user']:
cmd.append('--username=' + tools.config['db_user'])
if tools.config['db_host']:
else:
cr.execute("select decode(datname, 'escape') from pg_database where datname not in('template0', 'template1','postgres') order by datname")
res = [str(name) for (name,) in cr.fetchall()]
- except:
+ except Exception:
res = []
finally:
cr.close()
logger.notifyChannel("web-service", netsvc.LOG_INFO,'Logout %s from database %s'%(login,db))
return True
elif method in ['about', 'timezone_get', 'get_server_environment',
- 'login_message','get_stats', 'check_connectivity']:
+ 'login_message','get_stats', 'check_connectivity',
+ 'list_http_services']:
pass
- elif method in ['get_available_updates', 'get_migration_scripts', 'set_loglevel']:
+ elif method in ['get_available_updates', 'get_migration_scripts', 'set_loglevel', 'get_os_time', 'get_sqlcount']:
passwd = params[0]
params = params[1:]
security.check_super(passwd)
return info
def exp_timezone_get(self, db, login, password):
- #timezone detection is safe in multithread, so lazy init is ok here
- if (not tools.config['timezone']):
- tools.config['timezone'] = tools.misc.detect_server_timezone()
- return tools.config['timezone']
-
+ return tools.misc.get_server_timezone()
def exp_get_available_updates(self, contract_id, contract_password):
import tools.maintenance as tm
try:
try:
base64_decoded = base64.decodestring(zips[module])
- except:
+ except Exception:
l.notifyChannel('migration', netsvc.LOG_ERROR, 'unable to read the module %s' % (module,))
raise
try:
try:
tools.extract_zip_file(zip_contents, tools.config['addons_path'] )
- except:
+ except Exception:
l.notifyChannel('migration', netsvc.LOG_ERROR, 'unable to extract the module %s' % (module, ))
rmtree(module)
raise
finally:
zip_contents.close()
- except:
+ except Exception:
l.notifyChannel('migration', netsvc.LOG_ERROR, 'restore the previous version of the module %s' % (module, ))
nmp = os.path.join(backup_directory, module)
if os.path.isdir(nmp):
res += netsvc.Server.allStats()
return res
+ def exp_list_http_services(self):
+ from service import http_server
+ return http_server.list_http_services()
+
def exp_check_connectivity(self):
return bool(sql_db.db_connect('template1'))
+
+ def exp_get_os_time(self):
+ return os.times()
+
+ def exp_get_sqlcount(self):
+ logger = logging.getLogger('db.cursor')
+ if not logger.isEnabledFor(logging.DEBUG_SQL):
+ logger.warning("Counters of SQL will not be reliable unless DEBUG_SQL is set at the server's config.")
+ return sql_db.sql_counter
common()
def dispatch(self, method, auth, params):
(db, uid, passwd ) = params[0:3]
params = params[3:]
- if method not in ['execute','exec_workflow','obj_list']:
- raise KeyError("Method not supported %s" % method)
+ if method == 'obj_list':
+ raise NameError("obj_list has been discontinued via RPC as of 6.0, please query ir.model directly!")
+ if method not in ['execute','exec_workflow']:
+ raise NameError("Method not available %s" % method)
security.check(db,uid,passwd)
ls = netsvc.LocalService('object_proxy')
fn = getattr(ls, method)
logger = netsvc.Logger()
logger.notifyChannel('web-services', netsvc.LOG_ERROR,
'Exception: %s\n%s' % (str(exception), tb_s))
- self._reports[id]['exception'] = ExceptionWithTraceback(tools.exception_to_unicode(exception), tb)
+ if hasattr(exception, 'name') and hasattr(exception, 'value'):
+ self._reports[id]['exception'] = ExceptionWithTraceback(tools.ustr(exception.name), tools.ustr(exception.value))
+ else:
+ self._reports[id]['exception'] = ExceptionWithTraceback(tools.exception_to_unicode(exception), tb)
self._reports[id]['state'] = True
cr.commit()
cr.close()
def _check_report(self, report_id):
result = self._reports[report_id]
- if result['exception']:
- raise result['exception']
+ exc = result['exception']
+ if exc:
+ self.abortResponse(exc, exc.message, 'warning', exc.traceback)
res = {'state': result['state']}
if res['state']:
if tools.config['reportgz']:
return res
def exp_report_get(self, db, uid, report_id):
-
if report_id in self._reports:
if self._reports[report_id]['uid'] == uid:
return self._check_report(report_id)