devtools/__init__.py
changeset 10440 eecb7bbb6795
parent 10439 45e18b4a7466
child 10472 7dd84b69c7d4
equal deleted inserted replaced
10439:45e18b4a7466 10440:eecb7bbb6795
    24 import errno
    24 import errno
    25 import logging
    25 import logging
    26 import shutil
    26 import shutil
    27 import pickle
    27 import pickle
    28 import glob
    28 import glob
    29 import random
       
    30 import subprocess
    29 import subprocess
    31 import warnings
    30 import warnings
    32 import tempfile
    31 import tempfile
    33 import getpass
    32 import getpass
    34 from hashlib import sha1 # pylint: disable=E0611
    33 from hashlib import sha1 # pylint: disable=E0611
   526 
   525 
   527 
   526 
   528 ### postgres test database handling ############################################
   527 ### postgres test database handling ############################################
   529 
   528 
   530 def startpgcluster(pyfile):
   529 def startpgcluster(pyfile):
   531     """Start a postgresql cluster next to pyfile and using a random port number"""
   530     """Start a postgresql cluster next to pyfile"""
   532     datadir = join(os.path.dirname(pyfile), 'data',
   531     datadir = join(os.path.dirname(pyfile), 'data',
   533                    'pgdb-%s' % os.path.splitext(os.path.basename(pyfile))[0])
   532                    'pgdb-%s' % os.path.splitext(os.path.basename(pyfile))[0])
   534     if not exists(datadir):
   533     if not exists(datadir):
   535         try:
   534         try:
   536             subprocess.check_call(['initdb', '-D', datadir, '-E', 'utf-8', '--locale=C'])
   535             subprocess.check_call(['initdb', '-D', datadir, '-E', 'utf-8', '--locale=C'])
   540                 raise OSError('"initdb" could not be found. '
   539                 raise OSError('"initdb" could not be found. '
   541                               'You should add the postgresql bin folder to your PATH '
   540                               'You should add the postgresql bin folder to your PATH '
   542                               '(/usr/lib/postgresql/9.1/bin for example).')
   541                               '(/usr/lib/postgresql/9.1/bin for example).')
   543             raise
   542             raise
   544     datadir = os.path.abspath(datadir)
   543     datadir = os.path.abspath(datadir)
   545     pgport = random.randrange(5432, 2**16)
   544     pgport = '5432'
   546     env = os.environ.copy()
   545     env = os.environ.copy()
   547     DEFAULT_PSQL_SOURCES['system']['db-host'] = datadir
   546     sockdir = tempfile.mkdtemp(prefix='cwpg')
   548     DEFAULT_PSQL_SOURCES['system']['db-port'] = str(pgport)
   547     DEFAULT_PSQL_SOURCES['system']['db-host'] = sockdir
   549     options = '-h "" -k %s -p %s' % (datadir, pgport)
   548     DEFAULT_PSQL_SOURCES['system']['db-port'] = pgport
       
   549     options = '-h "" -k %s -p %s' % (sockdir, pgport)
   550     options += ' -c fsync=off -c full_page_writes=off'
   550     options += ' -c fsync=off -c full_page_writes=off'
   551     options += ' -c synchronous_commit=off'
   551     options += ' -c synchronous_commit=off'
   552     try:
   552     try:
   553         subprocess.check_call(['pg_ctl', 'start', '-w', '-D', datadir,
   553         subprocess.check_call(['pg_ctl', 'start', '-w', '-D', datadir,
   554                                '-o', options],
   554                                '-o', options],