summaryrefslogtreecommitdiff
path: root/scripts/gen-lockedsig-cache
blob: dfb282efd4a8e4d2ea817e3f602cabf3f430da63 (plain)
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
#!/usr/bin/env python
#
# gen-lockedsig-cache <locked-sigs.inc> <input-cachedir> <output-cachedir>
#

import os
import sys
import glob
import shutil
import errno

def mkdir(d):
    try:
        os.makedirs(d)
    except OSError as e:
        if e.errno != errno.EEXIST:
            raise e

if len(sys.argv) < 3:
    print("Incorrect number of arguments specified")
    sys.exit(1)

sigs = []
with open(sys.argv[1]) as f:
    for l in f.readlines():
        if ":" in l:
            sigs.append(l.split(":")[2].split()[0])

files = set()
for s in sigs:
    p = sys.argv[2] + "/" + s[:2] + "/*" + s + "*"
    files |= set(glob.glob(p))
    p = sys.argv[2] + "/*/" + s[:2] + "/*" + s + "*"
    files |= set(glob.glob(p))

for f in files:
    dst = f.replace(sys.argv[2], sys.argv[3])
    mkdir(os.path.dirname(dst))
    os.link(f, dst)