[devtools] improve error message when postgresql tools are missing
authorAlain Leufroy <alain.leufroy@logilab.fr>
Tue, 03 Jun 2014 12:37:54 +0200
changeset 9886 1b26289217a3
parent 9885 9f546848ba48
child 9887 152c09c2f0ed
[devtools] improve error message when postgresql tools are missing By default in at least Debian, some pg tools are not present in the PATH. Or they may not be installed. But the tests tools expects them to be in the PATH, and give an unhelpful 'No such file or directory' backtrace if they're not found. To help devs using the pg tests we improve the error message.
devtools/__init__.py
--- a/devtools/__init__.py	Fri Jul 11 17:13:32 2014 +0200
+++ b/devtools/__init__.py	Tue Jun 03 12:37:54 2014 +0200
@@ -21,6 +21,7 @@
 
 import os
 import sys
+import errno
 import logging
 import shutil
 import pickle
@@ -545,14 +546,29 @@
         super(PostgresTestDataBaseHandler, self).__init__(*args, **kwargs)
         datadir = join(self.config.apphome, 'pgdb')
         if not exists(datadir):
-            subprocess.check_call(['initdb', '-D', datadir, '-E', 'utf-8', '--locale=C'])
+            try:
+                subprocess.check_call(['initdb', '-D', datadir, '-E', 'utf-8', '--locale=C'])
+
+            except OSError, err:
+                if err.errno == errno.ENOENT:
+                    raise OSError('"initdb" could not be found. '
+                                  'You should add the postgresql bin folder to your PATH '
+                                  '(/usr/lib/postgresql/9.1/bin for example).')
+                raise
         port = self.system_source['db-port']
         directory = self.system_source['db-host']
         env = os.environ.copy()
         env['PGPORT'] = str(port)
         env['PGHOST'] = str(directory)
-        subprocess.check_call(['pg_ctl', 'start', '-w', '-D', datadir, '-o', '-h "" -k %s -p %s' % (directory, port)],
-                              env=env)
+        try:
+            subprocess.check_call(['pg_ctl', 'start', '-w', '-D', datadir, '-o', '-h "" -k %s -p %s' % (directory, port)],
+                                  env=env)
+        except OSError, err:
+            if err.errno == errno.ENOENT:
+                raise OSError('"pg_ctl" could not be found. '
+                              'You should add the postgresql bin folder to your PATH '
+                              '(/usr/lib/postgresql/9.1/bin for example).')
+            raise
         self.__CTL.add(datadir)
 
     @property