Commit 6c256c76 authored by Jason R. Coombs's avatar Jason R. Coombs

Extract _adjust_header method

--HG--
extra : rebase_source : 63809401ac0769504a143981e518ef31488ea400
parent 8d09363e
...@@ -1832,16 +1832,11 @@ class WindowsScriptWriter(ScriptWriter): ...@@ -1832,16 +1832,11 @@ class WindowsScriptWriter(ScriptWriter):
launcher_type = 'gui' launcher_type = 'gui'
ext = '-script.pyw' ext = '-script.pyw'
old = ['.pyw'] old = ['.pyw']
new_header = re.sub('(?i)python.exe','pythonw.exe',header)
else: else:
launcher_type = 'cli' launcher_type = 'cli'
ext = '-script.py' ext = '-script.py'
old = ['.py','.pyc','.pyo'] old = ['.py','.pyc','.pyo']
new_header = re.sub('(?i)pythonw.exe','python.exe',header) hdr = cls._adjust_header(type_, header)
if os.path.exists(new_header[2:-1].strip('"')) or sys.platform!='win32':
hdr = new_header
else:
hdr = header
blockers = [name+x for x in old] blockers = [name+x for x in old]
yield (name+ext, hdr+script_text, 't', blockers) yield (name+ext, hdr+script_text, 't', blockers)
yield ( yield (
...@@ -1857,6 +1852,23 @@ class WindowsScriptWriter(ScriptWriter): ...@@ -1857,6 +1852,23 @@ class WindowsScriptWriter(ScriptWriter):
m_name = name + '.exe.manifest' m_name = name + '.exe.manifest'
yield (m_name, load_launcher_manifest(name), 't') yield (m_name, load_launcher_manifest(name), 't')
@staticmethod
def _adjust_header(type_, orig_header):
"""
Make sure 'pythonw' is used for gui and and 'python' is used for
console (regardless of what sys.executable is).
"""
pattern = 'pythonw.exe'
repl = 'python.exe'
if type_ == 'gui':
pattern, repl = repl, pattern
new_header = re.sub(string=orig_header, pattern=re.escape(pattern),
repl=repl, flags=re.IGNORECASE)
clean_header = new_header[2:-1].strip('"')
if sys.platform == 'win32' and not os.path.exists(clean_header):
# the adjusted version doesn't exist, so return the original
return orig_header
return new_header
# for backward-compatibility # for backward-compatibility
get_script_args = ScriptWriter.get_script_args get_script_args = ScriptWriter.get_script_args
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment