devtools/__init__.py
changeset 9886 1b26289217a3
parent 9864 f60a80592224
child 10038 f2f065d406dc
equal deleted inserted replaced
9885:9f546848ba48 9886:1b26289217a3
    19 
    19 
    20 __docformat__ = "restructuredtext en"
    20 __docformat__ = "restructuredtext en"
    21 
    21 
    22 import os
    22 import os
    23 import sys
    23 import sys
       
    24 import errno
    24 import logging
    25 import logging
    25 import shutil
    26 import shutil
    26 import pickle
    27 import pickle
    27 import glob
    28 import glob
    28 import random
    29 import random
   543 
   544 
   544     def __init__(self, *args, **kwargs):
   545     def __init__(self, *args, **kwargs):
   545         super(PostgresTestDataBaseHandler, self).__init__(*args, **kwargs)
   546         super(PostgresTestDataBaseHandler, self).__init__(*args, **kwargs)
   546         datadir = join(self.config.apphome, 'pgdb')
   547         datadir = join(self.config.apphome, 'pgdb')
   547         if not exists(datadir):
   548         if not exists(datadir):
   548             subprocess.check_call(['initdb', '-D', datadir, '-E', 'utf-8', '--locale=C'])
   549             try:
       
   550                 subprocess.check_call(['initdb', '-D', datadir, '-E', 'utf-8', '--locale=C'])
       
   551 
       
   552             except OSError, err:
       
   553                 if err.errno == errno.ENOENT:
       
   554                     raise OSError('"initdb" could not be found. '
       
   555                                   'You should add the postgresql bin folder to your PATH '
       
   556                                   '(/usr/lib/postgresql/9.1/bin for example).')
       
   557                 raise
   549         port = self.system_source['db-port']
   558         port = self.system_source['db-port']
   550         directory = self.system_source['db-host']
   559         directory = self.system_source['db-host']
   551         env = os.environ.copy()
   560         env = os.environ.copy()
   552         env['PGPORT'] = str(port)
   561         env['PGPORT'] = str(port)
   553         env['PGHOST'] = str(directory)
   562         env['PGHOST'] = str(directory)
   554         subprocess.check_call(['pg_ctl', 'start', '-w', '-D', datadir, '-o', '-h "" -k %s -p %s' % (directory, port)],
   563         try:
   555                               env=env)
   564             subprocess.check_call(['pg_ctl', 'start', '-w', '-D', datadir, '-o', '-h "" -k %s -p %s' % (directory, port)],
       
   565                                   env=env)
       
   566         except OSError, err:
       
   567             if err.errno == errno.ENOENT:
       
   568                 raise OSError('"pg_ctl" could not be found. '
       
   569                               'You should add the postgresql bin folder to your PATH '
       
   570                               '(/usr/lib/postgresql/9.1/bin for example).')
       
   571             raise
   556         self.__CTL.add(datadir)
   572         self.__CTL.add(datadir)
   557 
   573 
   558     @property
   574     @property
   559     @cached
   575     @cached
   560     def helper(self):
   576     def helper(self):