-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathextract_templeos.py
executable file
·65 lines (51 loc) · 1.87 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
import sys
sys.path.append('isoparser')
import errno
import isoparser
import os
import subprocess
import shutil
ISO_FILE = sys.argv[1]
OUTPUT_DIR = sys.argv[2]
VERSION = sys.argv[3]
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(full_path):
if VERSION >= '2015-02-15 21:43:28':
decompressed_path = full_path[0:len(full_path)-2]
subprocess.check_call(['./TOSZ', '-ascii', full_path, decompressed_path])
os.remove(full_path)
else:
#shutil.copyfile(full_path, decompressed_path)
subprocess.check_call(['./TSZ', '-ascii', full_path])
if full_path.endswith('.Z'):
decompressed_path = full_path[0:len(full_path)-2]
os.rename(full_path, decompressed_path)
def decompress_all_files_in(path):
for item in os.listdir(path):
full_path = os.path.join(path, item)
compressed_extensions = 'APZ ASZ AUZ BIZ CPZ DTZ GLZ HPZ MPZ MUZ TXZ'.split()
if os.path.isdir(full_path):
decompress_all_files_in(full_path)
elif full_path.endswith('.Z') or (len(full_path) >= 4 and full_path[-4] == '.' and full_path[-3:] in compressed_extensions):
decompress(full_path)
# Extract TempleOS disk tree
extract(iso.root, OUTPUT_DIR)
#if VERSION < '2015-02-15 21:43:28':
# subprocess.check_call(['gcc', '-o', 'TSZ', os.path.join(OUTPUT_DIR, 'Linux', 'TSZ.CPP')])
# Decompress compressed files
decompress_all_files_in(OUTPUT_DIR)