forked from cia-foundation/TempleOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextract_templeos.py
executable file
·48 lines (37 loc) · 1.17 KB
/
extract_templeos.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
#!/usr/bin/env python
import sys
sys.path.append('isoparser')
import errno
import isoparser
import os
import subprocess
ISO_FILE = sys.argv[1]
OUTPUT_DIR = sys.argv[2]
iso = isoparser.parse(ISO_FILE)
def make_sure_path_exists(path):
try:
os.makedirs(path)
except OSError as exception:
if exception.errno != errno.EEXIST:
raise
def extract(node, path):
make_sure_path_exists(path)
for entry in node.children:
full_path = os.path.join(path, entry.name)
if entry.is_directory:
extract(entry, full_path)
else:
open(full_path, 'wb').write(entry.content)
def decompress_all_files_in(path):
for item in os.listdir(path):
full_path = os.path.join(path, item)
if os.path.isdir(full_path):
decompress_all_files_in(full_path)
elif full_path.endswith('.Z'):
decompressed_path = full_path[0:len(full_path)-2]
subprocess.check_call(['./TOSZ', '-ascii', full_path, decompressed_path])
os.remove(full_path)
# Extract TempleOS disk tree
extract(iso.root, OUTPUT_DIR)
# Decompress compressed files
decompress_all_files_in(OUTPUT_DIR)