-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTools.py
executable file
·101 lines (78 loc) · 3.24 KB
/
Tools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env /usr/bin/python
import os
import re
import json
from time import sleep
from auto_everything.base import Python, Terminal, IO
from auto_everything.develop import YRPC
from auto_everything.disk import Disk
from auto_everything.develop import Develop
from auto_everything.time import Time
py = Python()
io_ = IO()
terminal = Terminal()
yrpc = YRPC()
disk = Disk()
develop = Develop()
time_ = Time()
class Tools():
def __init__(self) -> None:
self.project_root_folder = disk.get_directory_path(os.path.realpath(os.path.abspath(__file__)))
self.src_project_root_folder = disk.join_paths(self.project_root_folder, "src")
def build_package(self):
terminal.run(f"""
rm -fr dist/
python3 -m pip install --upgrade build
python3 -m build
""")
def publish_package(self):
terminal.run(f"""
python3 -m pip install --upgrade twine
python3 -m twine upload dist/*
""")
def build(self):
virtual_env_folder = disk.join_paths(self.project_root_folder, ".venv")
activate_file = disk.join_paths(virtual_env_folder, "bin/activate")
terminal.run(f"""
#python3 -m venv {virtual_env_folder}
#source {activate_file}
rm -fr dist/
python3 -m pip install pyinstaller==5.13.0 --break-system-packages
#python3 -m pip install "git+https://github.com/yingshaoxo/auto_everything.git@dev"
#python3 -m PyInstaller yppm/main.py --noconfirm --onefile --add-data "./yppm/resources:resources" --hidden-import auto_everything --name yppm
python3 -m PyInstaller yppm/main.py --noconfirm --add-data "./yppm/resources:resources" --add-data "./yppm/auto_everything:auto_everything" --hidden-import auto_everything --name yppm
rm -fr dist/yppm/resources/backend_and_frontend_project
tar -czvf dist/yppm.tar.gz -C dist/yppm .
""")
def install(self):
self.build()
print("\nPlease input your root password: ")
terminal.run(f"""
sudo -S echo 'Working on...'
sudo rm -fr /usr/bin/yppm
sudo rm -fr /usr/bin/yppm_folder
sudo rm -fr /root/yppm.tar.gz
sudo mv dist/yppm.tar.gz /root/yppm.tar.gz
sudo mkdir -p /usr/bin/yppm_folder
sudo tar -xzvf /root/yppm.tar.gz -C /usr/bin/yppm_folder
sudo chmod a+rx /usr/bin/yppm_folder/yppm
sudo ln -s /usr/bin/yppm_folder/yppm /usr/bin/yppm
sudo chmod a+rx /usr/bin/yppm
echo 'Done'
""", wait=True)
def dev(self):
print("\n\n\nIn watching, when you change code, I'll do the compile and installation for you.")
watch_folder = disk.join_paths(self.project_root_folder, "yppm")
while True:
changed = develop.whether_a_folder_has_changed(watch_folder)
if changed == True:
sleep(60)
develop.whether_a_folder_has_changed(watch_folder)
try:
self.install()
except Exception as e:
print(e)
print("\n\n\nIn watching, when you change code, I'll do the compile and installation for you.")
sleep(5)
py.make_it_runnable()
py.fire2(Tools)