-
Notifications
You must be signed in to change notification settings - Fork 6
/
autoupdate.py
executable file
·79 lines (61 loc) · 2.1 KB
/
autoupdate.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
#!/usr/bin/env python3
from __future__ import print_function
import sys
sys.path.append('isoparser')
import hashlib
import os
import subprocess
import sys
import urllib
import isoparser
import os
import glob
import datetime
import shutil
ISO_DIR = sys.argv[1]
#isos = [os.path.join(ISO_DIR, entry) for entry in os.listdir(ISO_DIR)]
#[iI][sS][oO]
isos = glob.glob(os.path.join(ISO_DIR, '**/*.ISO'), recursive=True)
# pass 1: assign a date to each iso file
def get_latest_timestamp(node):
if node.is_directory and len(node.children):
#all = [get_latest_timestamp(entry) for entry in node.children]
#print(all)
oldest = max([get_latest_timestamp(entry) for entry in node.children])
return oldest
else:
#print(node.name, '\t\t', node.datetime)
#return datetime.datetime.strptime(node.datetime, "%Y-%m-%d %H:%M:%S")
return node.datetime
timestamps = []
for filename in isos:
print(filename)
iso = isoparser.parse(filename)
ts = get_latest_timestamp(iso.root)
#print(iso, ts)
#abort()
timestamps += [ts]
sorted_pairs = sorted(zip(isos, timestamps), key=lambda pair: pair[1])
isos, ts = zip(*sorted_pairs)
print('======================')
print('\n'.join([str(p) for p in sorted_pairs]))
#print('OK?'); input()
# pass 2: extract ISOs and commit chronologically
EXTRACTED_ISO_DIR = '../TempleOS_Archive'
SKIP=1
for FILE_NAME, timestamp in sorted_pairs[SKIP:]:
for file_object in os.listdir(EXTRACTED_ISO_DIR):
if file_object == '.git': continue
file_object_path = os.path.join(EXTRACTED_ISO_DIR, file_object)
if os.path.isfile(file_object_path):
os.unlink(file_object_path)
else:
shutil.rmtree(file_object_path)
print('---- Extracting', FILE_NAME)
subprocess.check_call(['./extract_templeos.py', FILE_NAME, EXTRACTED_ISO_DIR, timestamp])
dir = os.getcwd()
os.chdir(EXTRACTED_ISO_DIR)
print('---- Adding to git')
subprocess.call(['git', 'add', '-A', '.'])
subprocess.check_call(['git', 'commit', '-m', os.path.basename(FILE_NAME), '--date', timestamp])
os.chdir(dir)