mirror of
https://github.com/kiwix/kiwix-build.git
synced 2025-06-28 05:49:33 +00:00
Correctly set the environment.
When running command without `shell=True`, python's subproccess will look for variable `"PATH"` and `b"PATH"` and will complain if both are set. So the defaultdict should not return something for `b"PATH"`. We also escape space ` ` in the environment variables to not break everything with directory containing space.
This commit is contained in:
@ -8,6 +8,7 @@ import urllib.request
|
||||
import urllib.error
|
||||
import ssl
|
||||
import subprocess
|
||||
import re
|
||||
from collections import namedtuple, defaultdict
|
||||
|
||||
from kiwixbuild._global import neutralEnv, option
|
||||
@ -39,13 +40,25 @@ def xrun_find(name):
|
||||
return output[:-1].decode()
|
||||
|
||||
|
||||
regex_space = re.compile(r'((?<!\\) )')
|
||||
def escape_path(path):
|
||||
path = str(path)
|
||||
return regex_space.sub(r'\ ', path)
|
||||
|
||||
|
||||
class Defaultdict(defaultdict):
|
||||
def __getattr__(self, name):
|
||||
return self[name]
|
||||
|
||||
|
||||
def DefaultEnv():
|
||||
return Defaultdict(str, os.environ)
|
||||
class DefaultEnv(Defaultdict):
|
||||
def __init__(self):
|
||||
super().__init__(str, os.environ)
|
||||
|
||||
def __getitem__(self, name):
|
||||
if name == b'PATH':
|
||||
raise KeyError
|
||||
return super().__getitem__(name)
|
||||
|
||||
|
||||
def remove_duplicates(iterable, key_function=None):
|
||||
@ -265,7 +278,7 @@ def extract_archive(archive_path, dest_dir, topdir=None, name=None):
|
||||
def run_command(command, cwd, context, *, env=None, input=None):
|
||||
os.makedirs(cwd, exist_ok=True)
|
||||
if env is None:
|
||||
env = Defaultdict(str, os.environ)
|
||||
env = DefaultEnv()
|
||||
log = None
|
||||
try:
|
||||
if not option('verbose'):
|
||||
|
Reference in New Issue
Block a user