web_services: use pg_dump in batch mode.
[odoo/odoo.git] / bin / service / web_services.py
index 3536cf6..3c21202 100644 (file)
@@ -20,7 +20,6 @@
 ##############################################################################
 
 import base64
-import logging
 import os
 import security
 import thread
@@ -37,10 +36,9 @@ import release
 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)
@@ -188,7 +186,7 @@ class db(netsvc.ExportService):
 
         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']:
@@ -224,7 +222,7 @@ class db(netsvc.ExportService):
 
         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']:
@@ -305,7 +303,7 @@ class db(netsvc.ExportService):
                 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()
@@ -385,9 +383,10 @@ class common(_ObjectService):
             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)
@@ -438,11 +437,7 @@ GNU Public Licence.
         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
@@ -496,7 +491,7 @@ GNU Public Licence.
                 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
 
@@ -505,13 +500,13 @@ GNU Public Licence.
                     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):
@@ -567,8 +562,21 @@ GNU Public Licence.
         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()
 
@@ -580,8 +588,10 @@ class objects_proxy(netsvc.ExportService):
     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)
@@ -724,7 +734,10 @@ class report_spool(netsvc.ExportService):
                 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()
@@ -735,8 +748,9 @@ class report_spool(netsvc.ExportService):
 
     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']:
@@ -756,7 +770,6 @@ class report_spool(netsvc.ExportService):
         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)