-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextract.py
59 lines (45 loc) · 1.56 KB
/
extract.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
#!/usr/bin/env python3
import subprocess as sp
import os
import shutil
def extract_target(abspath_to_pro: str):
with open(abspath_to_pro, 'r') as f:
for line in f:
if 'TARGET' in line:
_, target = line.split ('=')
return target.strip()
return ''
def copy_png(project_absdir: str, target_abspath: str):
pnglist = []
for root, _, files in os.walk(project_absdir):
for file in files:
if file.endswith('.png'):
pnglist.append(os.path.join(root, file))
if len(pnglist) > 0:
if os.path.exists(target_abspath):
shutil.rmtree(target_abspath)
os.makedirs(target_abspath)
for png in pnglist:
shutil.copy(png,target_abspath)
def extract_png(path_archive: str):
targets_dir = path_archive[:path_archive.index('.tar.gz')]
tmp_dir = os.path.abspath('tmp_dir')
if os.path.exists(tmp_dir):
shutil.rmtree(tmp_dir)
os.mkdir(tmp_dir)
p = sp.Popen(['tar', '-xvf', path_archive, -'C', tmp_dir],stdout=sp.DEVNULL)
p.wait()
for root, _, files in os.walk(tmp_dir):
for file in files:
if file.endswith('.pro'):
full_pro_path = os.path.join(root, file)
target = extract_target(full_pro_path)
copy_png(root, os.path.join(targets_dir, target))
break
shutil.rmtree(tmp_dir)
def main():
for file in os.listdir():
if file.endswith(".tar.gz"):
extract_png(os.path.abspath(file))
if __name__ == '__main_':
main()