Skip to content

Commit e3c8206

Browse files
authored
Merge pull request #11 from zhlhlf/master
修复打包system不开机、更改打包输出目录
2 parents 34a3359 + e98c35c commit e3c8206

File tree

5 files changed

+75
-73
lines changed

5 files changed

+75
-73
lines changed

cyrus.py

Lines changed: 72 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -364,14 +364,14 @@ def patch_twrp(BOOTIMG):
364364

365365
if os.path.isfile("new-boot.img"):
366366
print("+ Done")
367-
if not os.path.isdir(V.DNA_DIST_DIR):
368-
os.mkdir(V.DNA_DIST_DIR)
369-
new_boot_img_name = f"{os.path.basename(BOOTIMG).split('.')[0]}{os.path.basename(V.DNA_DIST_DIR)}_twrp.img"
370-
os.rename("new-boot.img", os.path.join(V.DNA_DIST_DIR, new_boot_img_name))
367+
if not os.path.isdir(V.out):
368+
os.mkdir(V.out)
369+
new_boot_img_name = f"{os.path.basename(BOOTIMG).split('.')[0]}{os.path.basename(V.out)}_twrp.img"
370+
os.rename("new-boot.img", os.path.join(V.out, new_boot_img_name))
371371
os.chdir(PWD_DIR)
372372
add_magisk = input("> 是否继续添加Magisk [1/0]: ")
373373
if add_magisk == "1":
374-
patch_magisk(f"{V.DNA_DIST_DIR}{os.path.basename(BOOTIMG).split('.')[0]}_twrp.img")
374+
patch_magisk(f"{V.out}{os.path.basename(BOOTIMG).split('.')[0]}_twrp.img")
375375
os.chdir(PWD_DIR)
376376
if os.path.isdir(f"{V.DNA_MAIN_DIR}bootimg"):
377377
rmdire(f"{V.DNA_MAIN_DIR}bootimg")
@@ -486,10 +486,10 @@ def patch_magisk(bootimg):
486486

487487
if os.path.isfile("new-boot.img"):
488488
print("+ Done")
489-
if not os.path.isdir(V.DNA_DIST_DIR):
490-
os.mkdir(V.DNA_DIST_DIR)
489+
if not os.path.isdir(V.out):
490+
os.mkdir(V.out)
491491
new_boot_img_name = os.path.basename(bootimg).split(".")[0] + "_magisk.img"
492-
destination_path = os.path.join(V.DNA_DIST_DIR, new_boot_img_name)
492+
destination_path = os.path.join(V.out, new_boot_img_name)
493493
shutil.move("new-boot.img", destination_path)
494494
if os.path.isdir(V.DNA_MAIN_DIR + "system" + os.sep + "system"):
495495
try:
@@ -543,14 +543,14 @@ def repack_super():
543543
]
544544
parts = []
545545
for i in parts_1:
546-
for file in glob(V.DNA_DIST_DIR + i + '*' + '.img'):
546+
for file in glob(V.out + i + '*' + '.img'):
547547
parts.append(os.path.basename(file).rsplit('.', 1)[0])
548548
argvs = f'lpmake --metadata-size 65536 --super-name super --device super:{V.SETUP_MANIFEST["SUPER_SIZE"]}:{int(V.SETUP_MANIFEST["SUPER_SECTOR"]) * 512} '
549549
if V.SETUP_MANIFEST['IS_VAB'] == '1':
550550
argvs += '--metadata-slots 3 --virtual-ab -F '
551551
for i in parts:
552-
if os.path.isfile(V.DNA_DIST_DIR + i + '.img'):
553-
img_a = V.DNA_DIST_DIR + i + '.img'
552+
if os.path.isfile(V.out + i + '.img'):
553+
img_a = V.out + i + '.img'
554554
file_type = seekfd.gettype(img_a)
555555
if file_type == 'sparse':
556556
new_img_a = imgextractor.ULTRAMAN().APPLE(img_a)
@@ -561,11 +561,11 @@ def repack_super():
561561
else:
562562
argvs += '--metadata-slots 2 '
563563
for i in parts:
564-
if os.path.isfile(V.DNA_DIST_DIR + i + '_b.img'):
565-
img_b = V.DNA_DIST_DIR + i + '_b.img'
566-
img_a = V.DNA_DIST_DIR + i + '.img'
567-
if os.path.isfile(V.DNA_DIST_DIR + i + '_a.img'):
568-
img_a = V.DNA_DIST_DIR + i + '_a.img'
564+
if os.path.isfile(V.out + i + '_b.img'):
565+
img_b = V.out + i + '_b.img'
566+
img_a = V.out + i + '.img'
567+
if os.path.isfile(V.out + i + '_a.img'):
568+
img_a = V.out + i + '_a.img'
569569
file_type_a = seekfd.gettype(img_a)
570570
file_type_b = seekfd.gettype(img_b)
571571
if file_type_a == 'sparse':
@@ -582,22 +582,22 @@ def repack_super():
582582
image_size_b = imgextractor.ULTRAMAN().LEMON(img_b)
583583
argvs += f'--partition {i}_a:readonly:{image_size_a}:{V.SETUP_MANIFEST["GROUP_NAME"]}_a --image {i}_a={img_a} --partition {i}_b:readonly:{image_size_b}:{V.SETUP_MANIFEST["GROUP_NAME"]}_b --image {i}_b={img_b} '
584584
if not parts or "--image" not in argvs:
585-
input('> 未发现002_DNA文件夹下存在可用镜像文件')
585+
input('> 未发现out文件夹下存在可用镜像文件')
586586
return
587587
if V.SETUP_MANIFEST['SUPER_SPARSE'] == '1':
588588
argvs += '--sparse '
589-
argvs += f'--group {V.SETUP_MANIFEST["GROUP_NAME"]}_a:{V.SETUP_MANIFEST["SUPER_SIZE"]} --group {V.SETUP_MANIFEST["GROUP_NAME"]}_b:{V.SETUP_MANIFEST["SUPER_SIZE"]} --output {V.DNA_DIST_DIR + "super.img"} '
589+
argvs += f'--group {V.SETUP_MANIFEST["GROUP_NAME"]}_a:{V.SETUP_MANIFEST["SUPER_SIZE"]} --group {V.SETUP_MANIFEST["GROUP_NAME"]}_b:{V.SETUP_MANIFEST["SUPER_SIZE"]} --output {V.out + "super.img"} '
590590
display(
591591
f'重新合成: super.img <Size:{V.SETUP_MANIFEST["SUPER_SIZE"]}|Vab:{V.SETUP_MANIFEST["IS_VAB"]}|Sparse:{V.SETUP_MANIFEST["SUPER_SPARSE"]}>')
592592
display(f"包含分区:{'|'.join(parts)}")
593593
with CoastTime():
594594
call(argvs)
595595
try:
596-
if os.path.isfile(os.path.join(V.DNA_DIST_DIR, 'super.img')):
596+
if os.path.isfile(os.path.join(V.out, 'super.img')):
597597
for i in parts:
598598
for slot in ('_a', '_b', ''):
599-
if os.path.isfile(os.path.join(V.DNA_DIST_DIR, i + slot + '.img')):
600-
os.remove(os.path.join(V.DNA_DIST_DIR, i + slot + '.img'))
599+
if os.path.isfile(os.path.join(V.out, i + slot + '.img')):
600+
os.remove(os.path.join(V.out, i + slot + '.img'))
601601
except (BaseException, Exception):
602602
...
603603

@@ -613,9 +613,9 @@ def walk_contexts(contexts):
613613

614614
def recompress(source, fsconfig, contexts, dumpinfo, flag=8):
615615
label = os.path.basename(source)
616-
if not os.path.isdir(V.DNA_DIST_DIR):
617-
os.makedirs(V.DNA_DIST_DIR)
618-
distance = V.DNA_DIST_DIR + label + ".img"
616+
if not os.path.isdir(V.out):
617+
os.makedirs(V.out)
618+
distance = V.out + label + ".img"
619619
if os.path.isfile(distance):
620620
os.remove(distance)
621621
fspatch.main(source, fsconfig)
@@ -706,8 +706,8 @@ def recompress(source, fsconfig, contexts, dumpinfo, flag=8):
706706
if V.SETUP_MANIFEST["REPACK_EROFS_IMG"] == "0":
707707
if V.SETUP_MANIFEST["REPACK_TO_RW"] == "1":
708708
os.system(f"resize2fs -M {distance}")
709-
op_list = V.DNA_TEMP_DIR + "dynamic_partitions_op_list"
710-
new_op_list = V.DNA_DIST_DIR + "dynamic_partitions_op_list"
709+
op_list = V.input + "dynamic_partitions_op_list"
710+
new_op_list = V.out + "dynamic_partitions_op_list"
711711
if os.path.isfile(op_list) or os.path.isfile(new_op_list):
712712
if not os.path.isfile(new_op_list):
713713
shutil.copyfile(op_list, new_op_list)
@@ -723,19 +723,20 @@ def recompress(source, fsconfig, contexts, dumpinfo, flag=8):
723723
if V.SETUP_MANIFEST["IS_VAB"] == "1":
724724
for partition in ('system_a', 'system_ext_a', 'product_a', 'vendor_a',
725725
'odm_a'):
726-
CONTENT += f"resize {partition} 4294967296\n"
726+
CONTENT += f"resize {partition} 2\n"
727727

728728
else:
729729
for partition in ('system', 'system_ext', 'product', 'vendor', 'odm'):
730730
for slot in ('_a', '_b'):
731-
CONTENT += f"resize {partition}{slot} 4294967296\n"
731+
CONTENT += f"resize {partition}{slot} 2\n"
732732

733733
with open(new_op_list, "w", encoding="UTF-8", newline="\n") as ST:
734734
ST.write(CONTENT)
735735
renew_size = os.path.getsize(distance)
736736
with open(new_op_list, "r", encoding="UTF-8") as f_r:
737+
data = f_r.readlines()
737738
with open(new_op_list, "w", encoding="UTF-8") as f_w:
738-
for line in f_r.readlines():
739+
for line in data:
739740
if f"resize {label} " in line:
740741
line = f"resize {label} {renew_size}\n"
741742
elif f"resize {label}_a " in line:
@@ -758,8 +759,8 @@ def recompress(source, fsconfig, contexts, dumpinfo, flag=8):
758759
print("Error moving file:", e)
759760
if flag > 8:
760761
display(f"重新生成: {label}.new.dat ...", 3)
761-
img2sdat.main(distance, V.DNA_DIST_DIR, 4, label)
762-
newdat = V.DNA_DIST_DIR + label + ".new.dat"
762+
img2sdat.main(distance, V.out, 4, label)
763+
newdat = V.out + label + ".new.dat"
763764
if os.path.isfile(newdat):
764765
print(" Done")
765766
os.remove(distance)
@@ -903,9 +904,9 @@ def decompress_img(source, distance, keep=1):
903904
shutil.rmtree(distance)
904905
os.makedirs(distance)
905906
boot_utils(source, distance)
906-
if not os.path.isdir(V.DNA_CONF_DIR):
907-
os.makedirs(V.DNA_CONF_DIR)
908-
boot_info = V.DNA_CONF_DIR + os.path.basename(distance) + '_kernel.txt'
907+
if not os.path.isdir(V.config):
908+
os.makedirs(V.config)
909+
boot_info = V.config + os.path.basename(distance) + '_kernel.txt'
909910
open(boot_info, 'w', encoding='utf-8').close()
910911
elif file_type == 'sparse':
911912
display(f'正在转换: Unsparse Format [{os.path.basename(source)}] ...')
@@ -917,8 +918,8 @@ def decompress_img(source, distance, keep=1):
917918
if file_type in ['ext', 'erofs', 'super']:
918919
if file_type != 'ext':
919920
display(f'正在分解: {os.path.basename(source)} <{file_type}>', 3)
920-
if not os.path.isdir(V.DNA_CONF_DIR):
921-
os.makedirs(V.DNA_CONF_DIR)
921+
if not os.path.isdir(V.config):
922+
os.makedirs(V.config)
922923
if file_type == 'ext':
923924
with Console().status(f"[yellow]正在提取{os.path.basename(source)}[/]"):
924925
try:
@@ -928,7 +929,7 @@ def decompress_img(source, distance, keep=1):
928929
os.unlink(source)
929930
else:
930931
if file_type == 'erofs':
931-
with open(V.DNA_CONF_DIR + os.path.basename(distance) + '_size.txt', 'w') as sf:
932+
with open(V.config + os.path.basename(distance) + '_size.txt', 'w') as sf:
932933
sf.write(str(os.path.getsize(source)))
933934
if 'unsparse' in os.path.basename(source):
934935
try:
@@ -938,14 +939,14 @@ def decompress_img(source, distance, keep=1):
938939
source = source.replace('.unsparse', '')
939940
call(f'extract.erofs -i {source.replace(os.sep, "/")} -o {V.DNA_MAIN_DIR} -x')
940941
elif file_type == 'super':
941-
call(f'lpunpack {source} {V.DNA_TEMP_DIR}')
942-
for img in glob(V.DNA_TEMP_DIR + '*_b.img'):
942+
call(f'lpunpack {source} {V.input}')
943+
for img in glob(V.input + '*_b.img'):
943944
if not V.SETUP_MANIFEST['IS_VAB'] == '1' or os.path.getsize(img) == 0:
944945
os.remove(img)
945946
else:
946947
decompress_img(img, V.DNA_MAIN_DIR + os.path.basename(img).rsplit('.', 1)[0], keep=0)
947948
else:
948-
for img in glob(V.DNA_TEMP_DIR + '*_a.img'):
949+
for img in glob(V.input + '*_a.img'):
949950
new_source = img.rsplit('_', 1)[0] + '.img'
950951
try:
951952
os.rename(img, new_source)
@@ -967,10 +968,10 @@ def decompress_img(source, distance, keep=1):
967968
'').replace('.img',
968969
'') + '_fs_config'
969970
if os.path.isfile(contexts) and os.path.isfile(fsconfig):
970-
new_contexts = V.DNA_CONF_DIR + os.path.basename(source).replace('.unsparse.img',
971+
new_contexts = V.config + os.path.basename(source).replace('.unsparse.img',
971972
'').replace(
972973
'.img', '') + '_contexts.txt'
973-
new_fsconfig = V.DNA_CONF_DIR + os.path.basename(source).replace('.unsparse.img',
974+
new_fsconfig = V.config + os.path.basename(source).replace('.unsparse.img',
974975
'').replace(
975976
'.img', '') + '_fsconfig.txt'
976977
shutil.copy(contexts, new_contexts)
@@ -1165,15 +1166,15 @@ def decompress(infile, flag=4):
11651166

11661167
def envelop_project():
11671168
V.DNA_MAIN_DIR = PWD_DIR + V.project + os.sep
1168-
V.DNA_TEMP_DIR = V.DNA_MAIN_DIR + "001_DNA" + os.sep
1169-
V.DNA_CONF_DIR = V.DNA_MAIN_DIR + "000_DNA" + os.sep
1170-
V.DNA_DIST_DIR = V.DNA_MAIN_DIR + "002_DNA" + os.sep
1169+
V.input = V.DNA_MAIN_DIR + "001_DNA" + os.sep
1170+
V.config = V.DNA_MAIN_DIR + "config" + os.sep
1171+
V.out = V.DNA_MAIN_DIR + "out" + os.sep
11711172
if IS_ARM64:
1172-
V.DNA_TEMP_DIR = ROM_DIR + "D.N.A" + os.sep + V.project + os.sep + "001_DNA" + os.sep
1173-
V.DNA_DIST_DIR = ROM_DIR + "D.N.A" + os.sep + V.project + os.sep + "002_DNA" + os.sep
1174-
if not os.path.isdir(V.DNA_TEMP_DIR):
1175-
os.makedirs(V.DNA_TEMP_DIR)
1176-
if not os.path.isdir(V.DNA_TEMP_DIR):
1173+
V.input = ROM_DIR + "D.N.A" + os.sep + V.project + os.sep + "001_DNA" + os.sep
1174+
V.out = ROM_DIR + "D.N.A" + os.sep + V.project + os.sep + "out" + os.sep
1175+
if not os.path.isdir(V.input):
1176+
os.makedirs(V.input)
1177+
if not os.path.isdir(V.input):
11771178
os.makedirs(V.DNA_MAIN_DIR)
11781179
if not os.path.isdir(V.DNA_MAIN_DIR):
11791180
os.makedirs(V.DNA_MAIN_DIR)
@@ -1191,8 +1192,8 @@ def extract_zrom(rom):
11911192
print(f'> 解压缩: {os.path.basename(rom)}')
11921193
envelop_project()
11931194
fantasy_zip.close()
1194-
if os.path.isfile(V.DNA_TEMP_DIR + 'payload.bin'):
1195-
decompress_bin(fantasy_zip.extract('payload.bin', V.DNA_TEMP_DIR), V.DNA_TEMP_DIR,
1195+
if os.path.isfile(V.input + 'payload.bin'):
1196+
decompress_bin(fantasy_zip.extract('payload.bin', V.input), V.input,
11961197
input(f'> {RED}选择提取方式: [0]全盘提取 [1]指定镜像{CLOSE} >> '))
11971198
menu_main()
11981199
elif 'run.sh' in zip_lists:
@@ -1220,16 +1221,16 @@ def extract_zrom(rom):
12201221
infile = []
12211222
print(f'> 解压缩: {os.path.basename(rom)}')
12221223
envelop_project()
1223-
fantasy_zip.extractall(V.DNA_TEMP_DIR)
1224+
fantasy_zip.extractall(V.input)
12241225
fantasy_zip.close()
12251226
if [part_name for part_name in sorted(zip_lists) if part_name.endswith(".new.dat.br")]:
1226-
infile = glob(V.DNA_TEMP_DIR + '*.br')
1227+
infile = glob(V.input + '*.br')
12271228
able = 2
12281229
elif [part_name for part_name in zip_lists if part_name.endswith(".new.dat")]:
1229-
infile = glob(V.DNA_TEMP_DIR + '*.dat')
1230+
infile = glob(V.input + '*.dat')
12301231
able = 3
12311232
elif [part_name for part_name in zip_lists if part_name.endswith(".img")]:
1232-
infile = glob(V.DNA_TEMP_DIR + '*.img')
1233+
infile = glob(V.input + '*.img')
12331234
able = 4
12341235
if not infile:
12351236
input('> 仅支持含有payload.bin/*.new.dat/*.new.dat.br/*.img的zip固件')
@@ -1454,10 +1455,10 @@ def menu_more():
14541455
patch_addons()
14551456
elif int(option) in [6, 7]:
14561457
currentbootimg = None
1457-
if os.path.isfile(V.DNA_DIST_DIR + "boot.img"):
1458-
currentbootimg = V.DNA_DIST_DIR + "boot.img"
1459-
elif os.path.isfile(V.DNA_TEMP_DIR + "boot.img"):
1460-
currentbootimg = V.DNA_TEMP_DIR + "boot.img"
1458+
if os.path.isfile(V.out + "boot.img"):
1459+
currentbootimg = V.out + "boot.img"
1460+
elif os.path.isfile(V.input + "boot.img"):
1461+
currentbootimg = V.input + "boot.img"
14611462
if not currentbootimg:
14621463
continue
14631464
if os.path.isfile(currentbootimg):
@@ -1541,40 +1542,40 @@ def menu_main():
15411542
if int(option) in menu_actions.keys():
15421543
menu_actions[int(option)]()
15431544
elif int(option) == 1:
1544-
infile = V.DNA_TEMP_DIR + 'payload.bin'
1545+
infile = V.input + 'payload.bin'
15451546
if not os.path.exists(infile):
15461547
input("未发现Payload.Bin")
15471548
else:
1548-
decompress_bin(infile, V.DNA_TEMP_DIR,
1549+
decompress_bin(infile, V.input,
15491550
input(f'> {RED}选择提取方式: [0]全盘提取 [1]指定镜像{CLOSE} >> '))
15501551
elif int(option) in [2, 3, 4]:
15511552
quiet()
1552-
decompress(glob(V.DNA_TEMP_DIR + {2: "*.br", 3: "*.new.dat", 4: "*.img"}[int(option)]), int(option))
1553+
decompress(glob(V.input + {2: "*.br", 3: "*.new.dat", 4: "*.img"}[int(option)]), int(option))
15531554
elif int(option) == 5:
1554-
infile = glob(V.DNA_TEMP_DIR + '*.win*')
1555-
for i in glob(V.DNA_TEMP_DIR + '*.win'):
1555+
infile = glob(V.input + '*.win*')
1556+
for i in glob(V.input + '*.win'):
15561557
infile.append(i)
15571558
quiet()
15581559
decompress_win(list(set(sorted(infile))))
15591560
elif int(option) in [8, 9, 10]:
15601561
quiet()
15611562
if int(option) == 8:
1562-
for file in glob(V.DNA_CONF_DIR + '*_kernel.txt'):
1563+
for file in glob(V.config + '*_kernel.txt'):
15631564
f_basename = os.path.basename(file).rsplit('_', 1)[0]
15641565
source = V.DNA_MAIN_DIR + f_basename
15651566
if os.path.isdir(source):
15661567
if not V.JM:
15671568
display(f'是否合成: {f_basename}.img [1/0]: ', end='')
15681569
if input() != '1':
15691570
continue
1570-
boot_utils(source, V.DNA_DIST_DIR, 2)
1571-
for file in glob(V.DNA_CONF_DIR + '*_contexts.txt'):
1571+
boot_utils(source, V.out, 2)
1572+
for file in glob(V.config + '*_contexts.txt'):
15721573
f_basename = os.path.basename(file).rsplit('_', 1)[0]
15731574
source = V.DNA_MAIN_DIR + f_basename
15741575
if os.path.isdir(source):
1575-
fsconfig = V.DNA_CONF_DIR + f_basename + '_fsconfig.txt'
1576-
contexts = V.DNA_CONF_DIR + f_basename + '_contexts.txt'
1577-
infojson = V.DNA_CONF_DIR + f_basename + '_info.txt'
1576+
fsconfig = V.config + f_basename + '_fsconfig.txt'
1577+
contexts = V.config + f_basename + '_contexts.txt'
1578+
infojson = V.config + f_basename + '_info.txt'
15781579
if not os.path.isfile(infojson):
15791580
infojson = None
15801581
if V.SETUP_MANIFEST['REPACK_EROFS_IMG'] == '0' and V.SETUP_MANIFEST['REPACK_TO_RW'] == '1':

fspatch.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33
import os
4+
from typing import Generator
45

56

67
def scanfs(file) -> dict:
@@ -18,7 +19,7 @@ def scanfs(file) -> dict:
1819
return filesystem_config
1920

2021

21-
def scan_dir(folder) -> list:
22+
def scan_dir(folder) -> Generator:
2223
allfiles = ['/', '/lost+found', f'/{os.path.basename(folder)}/lost+found', f'/{os.path.basename(folder)}/']
2324
if os.name == 'nt':
2425
yield os.path.basename(folder).replace('\\', '')

imgextractor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def Simg2Rimg(self, target):
255255
return unsparse_file
256256

257257
def EXT4_EXTRACTOR(self):
258-
CONFIGS_DIR = os.path.dirname(self.EXTRACT_DIR) + os.sep + '000_DNA' + os.sep
258+
CONFIGS_DIR = os.path.dirname(self.EXTRACT_DIR) + os.sep + 'config' + os.sep
259259
if not os.path.isdir(CONFIGS_DIR):
260260
os.mkdir(CONFIGS_DIR)
261261
dna_contexts = CONFIGS_DIR + self.FileName + '_contexts.txt'

local/bin/e2fsdroid.exe

2.79 MB
Binary file not shown.

local/bin/mke2fs.exe

761 KB
Binary file not shown.

0 commit comments

Comments
 (0)