Skip to content

Commit 1ef21f7

Browse files
committed
feat(setup): add setup.py script to optimize files weight and installation process before running main script
1 parent e12fbef commit 1ef21f7

File tree

9 files changed

+3591
-9
lines changed

9 files changed

+3591
-9
lines changed

core/rarfile.py

Lines changed: 3527 additions & 0 deletions
Large diffs are not rendered by default.

libs/wslbuilder.rar

3.6 MB
Binary file not shown.

libs/wslbuilder/archlinux.ico

-66.1 KB
Binary file not shown.

libs/wslbuilder/debian.ico

-66.1 KB
Binary file not shown.

libs/wslbuilder/fedora.ico

-66.1 KB
Binary file not shown.

libs/wslbuilder/ubuntu.ico

-66.1 KB
Binary file not shown.

libs/wslbuilder/wslbuilder.tar

-10.4 MB
Binary file not shown.

setup.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
from os.path import abspath
5+
from shutil import rmtree
6+
7+
from core.rarfile import RarFile
8+
9+
def clearLibs(paths: list[str]) -> None:
10+
if(len(paths)):
11+
for p in paths:
12+
try:
13+
rmtree(p)
14+
15+
except(FileNotFoundError):
16+
pass
17+
18+
def setup() -> bool:
19+
__libs = list[str]([
20+
"wslbuilder"
21+
])
22+
23+
__extractPath = abspath("libs/")
24+
__rarPaths = [ abspath(f"{__extractPath}/{m}.rar") for m in __libs ]
25+
__libsPath = [ abspath(f"{__extractPath}/{m}") for m in __libs ]
26+
27+
print("[ INFO ]: Clearing installation ...")
28+
clearLibs(__libsPath)
29+
30+
for i, rp in enumerate(__rarPaths):
31+
with RarFile(rp) as __rf:
32+
try:
33+
print(f" ( ) Unpacking {rp} ... [{i}/{len(__rarPaths)}]", end="\r")
34+
__rf.extractall(__extractPath)
35+
print(f" (*) {rp} Unpacked{' '*16}")
36+
37+
except(Exception) as e:
38+
clearLibs(__libsPath)
39+
print(f"[ ERROR ]: {e}{' '*(16+len(rp))}")
40+
return(False)
41+
42+
print("[ OK ]: Installation finished !")
43+
return(True)
44+
45+
if(__name__ == "__main__"):
46+
setup()

tools/wslBuilder.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
"""
1111

1212
from os import listdir, mkdir, remove, rmdir, system as shell
13-
from os.path import abspath, dirname, getsize
13+
from os.path import abspath, dirname, getsize, isdir
1414

1515
import re
16+
from token import EXACT_TOKEN_TYPES
1617

1718
from core import stringSize
1819
from core.colors import Colors
@@ -136,15 +137,23 @@ def _export(self, args: list[str]) -> None:
136137
def _init(self) -> None:
137138
__libspath = abspath(f"{self.__path}/../libs/wslbuilder")
138139

139-
shell(f"wsl --import wslbuilder {__libspath} {__libspath}/wslbuilder.tar")
140-
shell("wsl -s wslbuilder")
141-
shell("wsl apk update")
142-
shell("wsl apk add docker openrc")
140+
try:
141+
if(not isdir(__libspath)):
142+
raise(FileNotFoundError)
143+
144+
shell(f"wsl --import wslbuilder {__libspath} {__libspath}/wslbuilder.tar")
145+
shell("wsl -s wslbuilder")
146+
shell("wsl apk update")
147+
shell("wsl apk add docker openrc")
148+
149+
if(self.__checkDockerStatus()):
150+
if(shell("wsl service docker start")):
151+
shell('wsl touch "/../run/openrc/softlevel"')
152+
shell("wsl service docker start")
143153

144-
if(self.__checkDockerStatus()):
145-
if(shell("wsl service docker start")):
146-
shell('wsl touch "/../run/openrc/softlevel"')
147-
shell("wsl service docker start")
154+
except(FileNotFoundError):
155+
print(f"{Icons.err}WSLBuilder libs doesn't exist at {__libspath}")
156+
print(f'{Icons.tips}Don\'t forget to run "python setup.py" to unpack the libs')
148157

149158
def _list(self) -> None:
150159
__distros = listdir(self.__path)

0 commit comments

Comments
 (0)