Codebase list python-procrunner / e40c851
Resolve executable names on Windows Add a new keyword 'win32resolve' which only takes effect on Windows and is enabled by default. This causes procrunner to call the Win32 API FindExecutable() function to try and lookup non-.exe files with the corresponding name. This means .bat/.cmd/etc.. files can now be run without explicitly specifying their extension. Markus Gerstel 5 years ago
3 changed file(s) with 31 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
00 =======
11 History
22 =======
3
4 0.5.0
5 -----
6
7 * New keyword 'win32resolve' which only takes effect on Windows and is enabled
8 by default. This causes procrunner to call the Win32 API FindExecutable()
9 function to try and lookup non-.exe files with the corresponding name. This
10 means .bat/.cmd/etc.. files can now be run without explicitly specifying
11 their extension.
312
413 0.4.0 (2018-04-23)
514 ------------------
615
716 * Python 2.7 support on Windows. Python3 not yet supported on Windows.
817
9 0.3.0
10 -----
18 0.3.0 (2018-04-17)
19 ------------------
1120
1221 * run_process() renamed to run()
1322 * Python3 compatibility fixes
77 import select
88 import six
99 import subprocess
10 import sys
1011 import time
1112 import timeit
1213 import warnings
221222
222223 def run(command, timeout=None, debug=False, stdin=None, print_stdout=True,
223224 print_stderr=True, callback_stdout=None, callback_stderr=None,
224 environment=None, environment_override=None):
225 environment=None, environment_override=None, win32resolve=True):
225226 '''Run an external process.
226227
227228 :param array command: Command line to be run, specified as array.
237238 :param dict environment: The full execution environment for the command.
238239 :param dict environment_override: Change environment variables from the
239240 current values for command execution.
241 :param win32resolve: If on Windows, find the appropriate executable first.
242 This allows running of .bat, .cmd, etc. files without
243 explicitly specifying their extension.
240244 :return: A dictionary containing stdout, stderr, runtime, exitcode,
241245 and more.
242246 '''
260264 if environment_override:
261265 env = copy.copy(env)
262266 env.update(environment_override)
267
268 if win32resolve and sys.platform == 'win32':
269 try:
270 import win32api
271 _, found_executable = win32api.FindExecutable(command[0])
272 logger.debug("Resolved %s as %s", command[0], found_executable)
273 command[0] = found_executable
274 except ImportError:
275 logger.warn("Could not resolve executable name: package win32api missing")
276 except Exception as e:
277 if not hasattr(e, 'winerror'): raise
278 logger.warn("Error trying to resolve the executable: %s", getattr(e, 'strerror', str(e)))
263279
264280 p = subprocess.Popen(command, shell=False, stdin=stdin_pipe, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env)
265281
00 #!/usr/bin/env python
11 # -*- coding: utf-8 -*-
22
3 """The setup script."""
4
53 from setuptools import setup, find_packages
4 import sys
65
76 with open('README.rst') as readme_file:
87 readme = readme_file.read()
1110 history = history_file.read()
1211
1312 requirements = ['six']
13 if sys.platform == 'win32':
14 requirements.append('pywin32')
1415
1516 setup_requirements = ['pytest-runner', 'six']
1617