summaryrefslogtreecommitdiff
path: root/scripts/gen-lockedsig-cache
blob: 26e9b63a303b8812aa5dd3c15a1a4bda2c252e57 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python3

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) < 5:
    print("Incorrect number of arguments specified")
    print("syntax: gen-lockedsig-cache <locked-sigs.inc> <input-cachedir> <output-cachedir> <nativelsbstring>")
    sys.exit(1)

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

print('Gathering file list')
files = set()
for s in sigs:
    p = sys.argv[2] + "/" + s[:2] + "/*" + s + "*"
    files |= set(glob.glob(p))
    p = sys.argv[2] + "/%s/" % sys.argv[4] + s[:2] + "/*" + s + "*"
    files |= set(glob.glob(p))

print('Processing files')
for f in files:
    sys.stdout.write('Processing %s... ' % f)
    _, ext = os.path.splitext(f)
    if not ext in ['.tgz', '.siginfo', '.sig']:
        # Most likely a temp file, skip it
        print('skipping')
        continue
    dst = os.path.join(sys.argv[3], os.path.relpath(f, sys.argv[2]))
    destdir = os.path.dirname(dst)
    mkdir(destdir)

    if os.path.exists(dst):
        os.remove(dst)
    if (os.stat(f).st_dev == os.stat(destdir).st_dev):
        print('linking')
        os.link(f, dst)
    else:
        print('copying')
        shutil.copyfile(f, dst)

print('Done!')