99"""
1010from io import StringIO
1111from pathlib import Path
12- import os
12+ import sys
1313import subprocess
14+ import contextlib
15+ import logging
1416
1517def get_import_file (context ):
1618 if context .import_file is not None :
@@ -76,7 +78,7 @@ def run_osm2pgsql(context, output):
7678
7779
7880def run_osm2pgsql_replication (context ):
79- cmdline = [str ( Path ( context . config . userdata [ 'REPLICATION_SCRIPT' ]). resolve ()) ]
81+ cmdline = []
8082 # convert table items to CLI arguments and inject constants to placeholders
8183 if context .table :
8284 cmdline .extend (f .format (** context .config .userdata ) for f in context .table .headings if f )
@@ -86,19 +88,18 @@ def run_osm2pgsql_replication(context):
8688 if '-d' not in cmdline and '--database' not in cmdline :
8789 cmdline .extend (('-d' , context .config .userdata ['TEST_DB' ]))
8890
89- # on Windows execute script directly with python, because shebang is not recognised
90- if os .name == 'nt' :
91- cmdline .insert (0 , "python" )
9291
93- proc = subprocess .Popen (cmdline , cwd = str (context .workdir ),
94- stdin = subprocess .PIPE ,
95- stdout = subprocess .PIPE , stderr = subprocess .PIPE )
92+ serr = StringIO ()
93+ log_handler = logging .StreamHandler (serr )
94+ context .osm2pgsql_replication .LOG .addHandler (log_handler )
95+ with contextlib .redirect_stdout (StringIO ()) as sout :
96+ retval = context .osm2pgsql_replication .main (cmdline )
97+ context .osm2pgsql_replication .LOG .removeHandler (log_handler )
9698
97- outdata = proc .communicate ()
99+ context .osm2pgsql_outdata = [sout .getvalue (), serr .getvalue ()]
100+ print (context .osm2pgsql_outdata )
98101
99- context .osm2pgsql_outdata = [d .decode ('utf-8' ).replace ('\\ n' , '\n ' ) for d in outdata ]
100-
101- return proc .returncode
102+ return retval
102103
103104
104105@given ("no lua tagtransform" )
0 commit comments