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): |