-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathPackageMake.py
169 lines (138 loc) · 5.02 KB
/
PackageMake.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
151
152
153
154
155
156
157
158
159
160
import os
import re
import shutil
from typing import Any, List, Dict, Tuple, Optional, IO
import utils
def desc_file_creat(desc_path: str, desc_conf: Dict) -> IO:
"""
creat <desc.txt> file
reference: <https://android.googlesource.com/platform/frameworks/base/+/master/cmds/bootanimation/FORMAT.md>
:param desc_path: path to desc.txt
:param desc_conf:
desc_dict = {
'width': '1080',
'height': '1920',
'fps': '30',
'parts': [
{'type': 'p', 'count': '0', 'pause': '0', 'path': 'part0'},
{'type': 'c', 'count': '0', 'pause': '0', 'path': 'part1'}
]
}
:return: file IO
"""
width = desc_conf.get('width')
height = desc_conf.get('height')
fps = desc_conf.get('fps')
with open(desc_path, mode="w+", newline='\n') as desc_f:
content = "{} {} {}\n".format(width, height, fps)
for part in desc_conf.get('parts'):
content += "{} {} {} {}\n".format(part['type'], part['count'], part['pause'], part['path'])
desc_f.write(content)
return desc_f
def bootani_zip_file_creat(zipped_dir_path: str, bootani_zip_path: str) -> None:
"""
creat <bootanimation.zip>
:param zipped_dir_path: directory to be zipped
:param bootani_zip_path: path to <bootanimation.zip>
:return: None
"""
utils.dir2zipfile(zipped_dir_path, bootani_zip_path, incl_emptydir=True)
def template_prepare(template_dir_path: str, template_file_name: str, download_url: str, unzip_dir_path: str) -> None:
"""
download and unzip Magisk template
:param template_dir_path: directory content template
:param template_file_name: template file name
:param download_url: Magisk template url
:param unzip_dir_path: path to unzip
:return: None
"""
# TODO: 更新 updater-binary
template_file_path = os.path.join(template_dir_path, template_file_name)
if not os.path.exists(template_file_path):
utils.download_file(download_url, template_file_path)
utils.unzipfile(template_file_path, unzip_dir_path)
def update_binary_modify(update_binary_file_path: str, module_installer_sh_url: str):
utils.download_file(module_installer_sh_url, update_binary_file_path)
pass
def module_prop_modify(module_prop_file_path: str, module_prop_conf: Dict) -> None:
"""
<module.prop> modify
:param module_prop_file_path: path to <module.prop> file
:param module_prop_conf:
{
'mid': 'bootanimation-000'
'name': 'BootAnimation'
'version': '1.0'
'versionCode': '2018103101'
'author': 'Zarcher'
'description': 'A Boot Animation Magisk Module'
}
:return: None
"""
content_list = [
f"id={module_prop_conf.get('mid')}\n",
f"name={module_prop_conf.get('name')}\n",
f"version={module_prop_conf.get('version')}\n",
f"versionCode={module_prop_conf.get('versionCode')}\n",
f"author={module_prop_conf.get('author')}\n",
f"description={module_prop_conf.get('description')}\n"
]
content = ''.join(content_list)
with open(module_prop_file_path, 'w+', newline='\n') as mp_f:
mp_f.write(content)
def module_config_modify(module_config_file_path: str, module_config_conf: Optional[Dict] = None) -> None:
"""
module <config.sh> modify
:param module_config_file_path:
:param module_config_conf:
{
'ui_print': 'ui_print " Boot Animation "\n'
'REPLACE': 'REPLACE="\n\n"'
}
:return:
"""
if module_config_conf is None:
sub_contents = [
'ui_print " A Boot Animation Magisk Module "\n',
'REPLACE="\n' + '' + '\n"'
]
else:
sub_contents = [
module_config_conf.get('ui_print'),
module_config_conf.get('REPLACE')
]
patts = [
re.compile('ui_print " Magisk Module Template "\n'),
re.compile('REPLACE="\n"')
]
with open(module_config_file_path, 'r', newline='\n') as f:
content = f.read()
with open(module_config_file_path, 'w', newline='\n') as f:
for patt, sub_content in zip(patts, sub_contents):
# print(re.findall(patt, content))
content = re.sub(patt, sub_content, content)
f.write(content)
def module_pack(bootani_zip_path: str, module_media_dir_path: str, placeholder_path: str, template_dir_path: str,
module_export_file_path: str) -> None:
"""
pack the module
:param bootani_zip_path:
:param module_media_dir_path:
:param placeholder_path:
:param template_dir_path:
:param module_export_file_path:
:return: None
"""
os.makedirs(module_media_dir_path)
shutil.move(bootani_zip_path, module_media_dir_path)
os.remove(placeholder_path)
utils.dir2zipfile(template_dir_path, module_export_file_path)
def clean(export_temp_dir_path) -> None:
"""
clean temporary directory
:param export_temp_dir_path: temporary directory path to be cleaned
:return:
"""
shutil.rmtree(export_temp_dir_path)
if __name__ == '__main__':
pass