def _run_created_exe(self, test, testdir=None): """ Run executable created by PyInstaller. """ self._msg('EXECUTING TEST ' + self.test_name) # Run the test in a clean environment to make sure they're # really self-contained path = compat.getenv('PATH') compat.unsetenv('PATH') prog = self._find_exepath(test, 'dist') if prog is None: self._plain_msg('ERROR: no file generated by PyInstaller found!') compat.setenv("PATH", path) return 1 else: self._plain_msg("RUNNING: " + prog) old_wd = os.getcwd() os.chdir(os.path.dirname(prog)) prog = os.path.join(os.curdir, os.path.basename(prog)) retcode, out, err = compat.exec_command_all(prog) os.chdir(old_wd) self._msg('STDOUT %s' % self.test_name) self._plain_msg(out) self._msg('STDERR %s' % self.test_name) self._plain_msg(err) compat.setenv("PATH", path) return retcode
def test_exe(test, testdir=None): _msg("EXECUTING TEST", testdir + '/' + test) # Run the test in a clean environment to make sure they're # really self-contained path = compat.getenv("PATH") compat.unsetenv("PATH") prog = find_exepath(test, 'dist') if prog is None: print "ERROR: no file generated by PyInstaller found!" compat.setenv("PATH", path) return 1 else: print "RUNNING:", prog tmp = compat.exec_command_rc(prog) compat.setenv("PATH", path) return tmp
def _run_created_exe(self, test, testdir=None): """ Run executable created by PyInstaller. """ self._msg('EXECUTING TEST ' + self.test_name) # Run the test in a clean environment to make sure they're # really self-contained path = compat.getenv('PATH') compat.unsetenv('PATH') # For Windows we need to keep minimal PATH for sucessful running of some tests. if is_win: # Minimum Windows PATH is in most cases: C:\Windows\system32;C:\Windows compat.setenv('PATH', os.pathsep.join(winutils.get_system_path())) prog = self._find_exepath(test, 'dist') if prog is None: self._plain_msg('ERROR: no file generated by PyInstaller found!') compat.setenv("PATH", path) return 1 else: self._plain_msg("RUNNING: " + prog) old_wd = os.getcwd() os.chdir(os.path.dirname(prog)) # Run executable. prog = os.path.join(os.curdir, os.path.basename(prog)) proc = subprocess.Popen([prog], stdout=subprocess.PIPE, stderr=subprocess.PIPE) # Prints stdout of subprocess continuously. self._msg('STDOUT %s' % self.test_name) while proc.poll() is None: #line = proc.stdout.readline().strip() line = proc.stdout.read(1) self._plain_msg(line, newline=False) # Print any stdout that wasn't read before the process terminated. # See the conversation in https://github.com/pyinstaller/pyinstaller/pull/1092 # for examples of why this is necessary. self._plain_msg(proc.stdout.read(), newline=False) # Print possible stderr at the end. self._msg('STDERR %s' % self.test_name) self._plain_msg(proc.stderr.read()) compat.setenv("PATH", path) # Restore current working directory os.chdir(old_wd) return proc.returncode
def django_dottedstring_imports(django_root_dir): """ Get all the necessary Django modules specified in settings.py. In the settings.py the modules are specified in several variables as strings. """ package_name = os.path.basename(django_root_dir) compat.setenv('DJANGO_SETTINGS_MODULE', '%s.settings' % package_name) # Extend PYTHONPATH with parent dir of django_root_dir. PyInstaller.__pathex__.append(misc.get_path_to_toplevel_modules(django_root_dir)) # Extend PYTHONPATH with django_root_dir. # Many times Django users do not specify absolute imports in the settings module. PyInstaller.__pathex__.append(django_root_dir) ret = eval_script('django-import-finder.py') # Unset environment variables again. compat.unsetenv('DJANGO_SETTINGS_MODULE') return ret
def __exec_python_cmd(cmd): """ Executes an externally spawned Python interpreter and returns anything that was emitted in the standard output as a single string. """ # Prepend PYTHONPATH with pathex pp = os.pathsep.join(PyInstaller.__pathex__) old_pp = compat.getenv('PYTHONPATH') if old_pp: pp = os.pathsep.join([pp, old_pp]) compat.setenv("PYTHONPATH", pp) try: try: txt = compat.exec_python(*cmd) except OSError, e: raise SystemExit("Execution failed: %s" % e) finally: if old_pp is not None: compat.setenv("PYTHONPATH", old_pp) else: compat.unsetenv("PYTHONPATH") return txt.strip()
def __exec_python_cmd(cmd): """ Executes an externally spawned Python interpreter and returns anything that was emitted in the standard output as a single string. """ # Prepend PYTHONPATH with pathex pp = os.pathsep.join(PyInstaller.__pathex__) old_pp = compat.getenv('PYTHONPATH') if old_pp: pp = os.pathsep.join([old_pp, pp]) compat.setenv("PYTHONPATH", pp) try: try: txt = compat.exec_python(*cmd) except OSError, e: raise SystemExit("Execution failed: %s" % e) finally: if old_pp is not None: compat.setenv("PYTHONPATH", old_pp) else: compat.unsetenv("PYTHONPATH") return txt.strip()
def _restorePaths(old): if old is None: compat.unsetenv(envvar) else: compat.setenv(envvar, old)