8000 replace winpythonini.vbs per winpythonini.py · winpython/winpython@0f30924 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0f30924

Browse files
committed
replace winpythonini.vbs per winpythonini.py
1 parent d2ed0d9 commit 0f30924

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

make.py

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,10 @@ def _create_batch_scripts_initial(self):
878878
rem remove some potential last \
879879
if "%WINPYWORKDIR1:~-1%"=="\" set WINPYWORKDIR1=%WINPYWORKDIR1:~0,-1%
880880
881-
FOR /F "delims=" %%i IN ('cscript /nologo "%~dp0WinpythonIni.vbs"') DO set winpythontoexec=%%i
881+
rem 2024-09-22 pythonify
882+
rem FOR /F "delims=" %%i IN ('cscript /nologo "%~dp0WinpythonIni.vbs"') DO set winpythontoexec=%%i
883+
FOR /F "delims=" %%i IN ('""%WINPYDIR%\python.exe" "%~dp0WinpythonIni.py""') DO set winpythontoexec=%%i
884+
882885
%winpythontoexec%set winpythontoexec=
883886
884887
rem 2024-08-18: we go initial directory WINPYWORKDIR if no direction and we are on icon directory
@@ -967,6 +970,62 @@ def _create_batch_scripts_initial(self):
967970
""",
968971
)
969972

973+
self.create_batch_script(
974+
"WinPythonIni.py", # Replaces winpython.vbs
975+
r"""
976+
'prepares a dynamic list of variables settings from a .ini file'
977+
import os
978+
import subprocess
979+
980+
def get_file(file_name):
981+
if file_name.startswith("..\\"):
982+
file_name = os.path.join(os.path.dirname(os.path.dirname(__file__)), file_name[3:])
983+
elif file_name.startswith(".\\"):
984+
file_name = os.path.join(os.path.dirname(__file__), file_name[2:])
985+
with open(file_name, 'r') as file:
986+
return file.read()
987+
988+
def translate(line, env):
989+
parts = line.split('%')
990+
for i in range(1, len(parts), 2):
991+
if parts[i] in env:
992+
parts[i] = env[parts[i]]
993+
return ''.join(parts)
994+
995+
def main():
996+
import sys
997+
args = sys.argv[1:]
998+
file_name = args[0] if args else "..\\settings\\winpython.ini"
999+
1000+
my_lines = get_file(file_name).splitlines()
1001+
segment = "environment"
1002+
txt = ""
1003+
env = os.environ.copy() # later_version: env = os.environ
1004+
1005+
for l in my_lines:
1006+
if l.startswith("["):
1007+
segment = l[1:].split("]")[0]
1008+
elif not l.startswith("#") and "=" in l:
1009+
data = l.split("=", 1)
1010+
if segment == "debug" and data[0].strip() == "state":
1011+
data[0] = "WINPYDEBUG"
1012+
if segment in ["environment", "debug"]:
1013+
txt += f"set {data[0].strip()}={translate(data[1].strip(), env)}&& "
1014+
env[data[0].strip()] = translate(data[1].strip(), env)
1015+
if segment == "debug" and data[0].strip() == "state":
1016+
txt += f"set WINPYDEBUG={data[1].strip()}&&"
1017+
1018+
print(txt)
1019+
# later_version:
1020+
# p = subprocess.Popen(["start", "cmd", "/k", "set"], shell = True) # Needs to be shell since start isn't an executable, its a shell cmd
1021+
# p.wait() # I can wait until finished (although it too finishes after start finishes)
1022+
1023+
if __name__ == "__main__":
1024+
main()
1025+
""",
1026+
)
1027+
1028+
9701029
def _create_batch_scripts(self):
9711030
"""Create batch scripts"""
9721031
self._print("Creating batch scripts")

0 commit comments

Comments
 (0)
0