-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·150 lines (128 loc) · 3.97 KB
/
setup.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# for Windows : python setup.py py2exe
# for macOS : python3 setup.py py2app
from setuptools import setup
import platform
import glob
import sys
import os
import shutil
import base64
# Path setting
mainPath = "AdCleaner.py"
hostlist = "hosts_list.txt"
buildFolder = "build"
# Make build folder
try:
shutil.rmtree(buildFolder)
except FileNotFoundError:
pass
os.mkdir(buildFolder)
file = open(mainPath, "r", encoding = 'UTF-8')
mainProgram = file.read()
file.close()
print("Code encoding...")
mainProgram = mainProgram.encode("utf-8")
mainProgramEncode = base64.b64encode(mainProgram)
file = open(f"{buildFolder}/{mainPath}", "w", encoding = 'UTF-8')
file.write(f"""import base64
import os
import re
import sys
import eel
import ctypes
import shutil
import socket
import asyncio
import platform
import subprocess
import urllib.request
code = base64.b64decode({mainProgramEncode})
exec(code.decode("utf-8"))""")
file.close()
print("Copy file...")
shutil.copy2("./hosts_list.txt", f"./{buildFolder}/hosts_list.txt")
print("Copy folder...")
shutil.copytree("./web", f"./{buildFolder}/web")
# For build
ProgramVersion = "2.0"
if platform.system() == "Darwin":
setup(
name = 'AdCleaner',
version = ProgramVersion,
author = 'An Jaebeom',
app = [f"{buildFolder}/{mainPath}"],
data_files=[
(f'{buildFolder}/web', glob.glob('web/*.*')),
(f'{buildFolder}/web/css', glob.glob('web/css/*.*')),
(f'{buildFolder}/web/img', glob.glob('web/img/*.*')),
(f'{buildFolder}/web/js', glob.glob('web/js/*.*'))
],
setup_requires=['py2app'],
options={
'py2app': {
'iconfile':'icon.icns',
'includes': ['base64',
'os',
're',
'sys',
'eel',
'ctypes',
'shutil',
'socket',
'asyncio',
'platform',
'subprocess',
'urllib.request']
}
},
)
elif platform.system() == "Windows":
import py2exe
import py2exe.build_exe
def isSystemDLL(pathname):
dlls = ("libfreetype-6.dll", "libogg-0.dll", "sdl_ttf.dll")
if os.path.basename(pathname).lower() in dlls:
return 0
return py2exe.build_exe.isSystemDLL(pathname)
py2exe.build_exe.isSystemDLL = isSystemDLL
sys.argv.append('py2exe')
setup(
name = 'AdCleaner',
version = ProgramVersion,
author = 'An Jaebeom',
setup_requires=["py2app"],
options = {
'py2exe': {
'bundle_files': 1, # doesn't work on win64
'compressed': True,
'includes': ['base64',
'os',
're',
'sys',
'eel',
'ctypes',
'shutil',
'socket',
'asyncio',
'platform',
'subprocess',
'urllib.request']
}
},
data_files = [
(f'{buildFolder}/web', glob.glob('web/*.*')),
(f'{buildFolder}/web/css', glob.glob('web/css/*.*')),
(f'{buildFolder}/web/img', glob.glob('web/img/*.*')),
(f'{buildFolder}/web/js', glob.glob('web/js/*.*'))
],
windows = [{
'script': f"{buildFolder}/{mainPath}",
'icon_resources': [
(1, 'logo.ico')
]
}],
zipfile=None,
)
else:
print("Build fail")
print("Finish!")