Skip to content

Commit 2d6534d

Browse files
committed
Basic installer
1 parent a9ef66d commit 2d6534d

File tree

5 files changed

+106
-68
lines changed

5 files changed

+106
-68
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
__pycache__/
2-
priv/
32

43
# Pyinstaller build files
54
dist/
65
build/
76
*.spec
7+
8+
# Installer data
9+
installer.py
10+
python/

main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,5 +297,5 @@ def run_section(self, section: str) -> Any:
297297
os._exit(1)
298298

299299
inter.load_sections(code, file)
300-
file = file.replace("\\", "/").replace("/", ".").removesuffix(".xt")
300+
file = file.replace("\\", "/").replace("/", ".").removesuffix(".xt").removeprefix("./")
301301
[inter.run_section(s) for s in [f"{file}.global", f"{file}.main"]]

scripts/assets/x2.ico

4.19 KB
Binary file not shown.

scripts/build.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Copyright 2022 iiPython
2+
# Build the installer.py file
3+
4+
# Modules
5+
import os
6+
import io
7+
import shutil
8+
import zipfile
9+
from base64 import b85encode
10+
11+
try:
12+
from main import __version__ as x2_version
13+
14+
except ImportError:
15+
x2_version = input("x2 version: ")
16+
17+
# Initialization
18+
to_include = [f for f in os.listdir() if f not in [
19+
".git", "__pycache__", "md", "scripts", ".xtconfig", "main.xt",
20+
"build", "dist", "installer.py", "installer.spec"
21+
]]
22+
print("Including all of the following:\n", "\n\t- ".join([""] + to_include).lstrip("\n"))
23+
if not input("Is this correct (y/N)? ").lower() == "y":
24+
exit(1)
25+
26+
# Build our zip file into memory
27+
print("Zipping to memory ...")
28+
bio = io.BytesIO()
29+
with zipfile.ZipFile(bio, "w") as zf:
30+
for fn in to_include:
31+
if os.path.isfile(fn):
32+
zf.write(fn, fn)
33+
34+
else:
35+
for path, _, files in os.walk(fn):
36+
if "__pycache__" in path:
37+
continue
38+
39+
for file in files:
40+
fp = os.path.join(path, file)
41+
zf.write(fp, fp)
42+
43+
print(" ..done!")
44+
45+
# Create installer.py
46+
print("Writing to installer.py ...")
47+
installer_raw = f"""# Copyright 2022 iiPython
48+
# This file is autogenerated, please do not modify it.
49+
50+
# Modules
51+
import os
52+
import io
53+
import shutil
54+
import zipfile
55+
from base64 import b85decode
56+
57+
# Pre-install notice
58+
print("x2 Installer for {x2_version}\\n")
59+
print("Please note: this installer uses UP TO 2GB OF RAM!")
60+
print("Ensure you have 2gb of RAM available, then type 'proceed' to continue.")
61+
62+
if input("> ") != "proceed":
63+
exit(0)
64+
65+
print()
66+
67+
# Handle installation
68+
x2_dir = os.path.join(os.path.expanduser("~"), "x2")
69+
if os.path.isdir(x2_dir):
70+
if (input("x2 is already installed, upgrade (y/N)? ") or "n").lower() != "y":
71+
exit(0)
72+
73+
shutil.rmtree(x2_dir)
74+
75+
with zipfile.ZipFile(io.BytesIO(b85decode({b85encode(bio.getvalue())})), "r") as zf:
76+
zf.extractall(x2_dir)
77+
78+
shutil.move(os.path.join(x2_dir, "main.py"), os.path.join(x2_dir, "x2.py"))
79+
80+
# Create batch launcher
81+
with open(os.path.join(x2_dir, "x2.bat"), "w+") as launcher:
82+
launcher.write("@echo off\\ntitle x2\\n\\"%~dp0python\python.exe\\" \\"%~dp0x2.py\\" %*")
83+
84+
if (input("Add x2 to PATH (Y/n)? ") or "y").lower() == "y":
85+
os.system(f"setx PATH \\"%PATH%;{{x2_dir}}\\"")
86+
87+
# Finished with install
88+
print("\\nInstallation finished successfully.\\nMake sure you reopen all terminals for PATH to take effect.")
89+
input()
90+
""" # noqa
91+
del bio
92+
93+
with open("installer.py", "w+") as installer:
94+
installer.write(installer_raw)
95+
96+
print(" ..done!")
97+
98+
# Build with pyinstaller
99+
if shutil.which("pyinstaller"):
100+
if input("pyinstaller was found, build now (y/N)? ").lower() == "y":
101+
os.system("pyinstaller -i scripts/assets/x2.ico -F installer.py")

tests/test.xt

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)