-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrune.py
56 lines (42 loc) · 1.56 KB
/
Prune.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
import argparse
from os import path,getcwd
import json
import sys
FILE=0
START=1
ACTIVE=2
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('--input', required=False, default=path.join(getcwd(),'cutlist.json'),
help='List of file cuts' )
parser.add_argument('--output', required=False, default='',
help='location to write the new cutlist')
opts = parser.parse_args()
return opts
opts = parse_args()
def prune( cutlist ):
new_cutlist = None
for i in cutlist:
if new_cutlist and new_cutlist[-1][START] > i[START]:
print( "ERROR cuts out of order at {0} {1} {2}".format( len(new_cutlist), new_cutlist[-1][START], i[START]))
if not new_cutlist:
new_cutlist = [i]
elif (abs(i[START] - new_cutlist[-1][START]) < 5000):
if len(new_cutlist) > 1 and new_cutlist[-2][FILE] == i[FILE]:
del(new_cutlist[-1])
else:
new_cutlist[-1] = i
elif new_cutlist[-1][FILE] != i[FILE] or new_cutlist[-1][ACTIVE] != i[ACTIVE] and new_cutlist[-1][START] < i[START]:
new_cutlist.append(i)
return new_cutlist
def main():
opts = parse_args()
with open( opts.input ) as f:
cutlist = json.load(f)
cutlist = prune( cutlist )
json.dump(cutlist, sys.stdout, indent=2, separators=(',',': '))
if opts.output:
with open(opts.output, 'w') as f:
json.dump(cutlist, f)
if __name__ == '__main__':
main()