-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharchive.py
More file actions
executable file
·63 lines (48 loc) · 1.56 KB
/
archive.py
File metadata and controls
executable file
·63 lines (48 loc) · 1.56 KB
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
#!/usr/bin/env python3
import re
import os
import subprocess
def _parse_sequence_number(value):
return int(value[:3])
def main():
results = os.listdir('.')
# filter the results into things that look like transactions
filtered = filter(
lambda p: re.match(r'^\d{3}\..+\.json$', p) is not None,
results,
)
# build the transaction sets
transaction_sets = {}
for item in sorted(filtered):
seq = _parse_sequence_number(item)
# update the list of transaction items
existing = transaction_sets.get(seq, [])
existing.append(item)
transaction_sets[seq] = existing
for seq, items in transaction_sets.items():
contents_count = 0
tx_count = 0
sig_count = 0
for item in items:
if re.search(r'sig\.json$', item):
sig_count += 1
elif re.search(r'contents\.json$', item):
contents_count += 1
elif re.search(r'tx\.json$', item):
tx_count += 1
else:
print('Unknown file type', item)
assert False
# sanity check the counts
assert contents_count == 1
assert sig_count >= 2
assert tx_count == 1
# add all the items to the git staging area
for item in items:
cmd = ['git', 'mv', item, 'archive/']
subprocess.check_call(cmd)
# commit
cmd = ['git', 'commit', '-m', f'[{seq:03}] Archive TX']
subprocess.check_call(cmd)
if __name__ == '__main__':
main()