blob: c93b2c0b99bed52b9bf7d218a4a6c98218472c6f [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#!/usr/bin/env python
2#
3# gen-lockedsig-cache <locked-sigs.inc> <input-cachedir> <output-cachedir>
4#
5
6import os
7import sys
8import glob
9import shutil
10import errno
11
12def mkdir(d):
13 try:
14 os.makedirs(d)
15 except OSError as e:
16 if e.errno != errno.EEXIST:
17 raise e
18
19if len(sys.argv) < 3:
20 print("Incorrect number of arguments specified")
21 sys.exit(1)
22
23sigs = []
24with open(sys.argv[1]) as f:
25 for l in f.readlines():
26 if ":" in l:
27 sigs.append(l.split(":")[2].split()[0])
28
29files = set()
30for s in sigs:
31 p = sys.argv[2] + "/" + s[:2] + "/*" + s + "*"
32 files |= set(glob.glob(p))
33 p = sys.argv[2] + "/*/" + s[:2] + "/*" + s + "*"
34 files |= set(glob.glob(p))
35
36for f in files:
37 dst = f.replace(sys.argv[2], sys.argv[3])
38 destdir = os.path.dirname(dst)
39 mkdir(destdir)
40
41 if os.path.exists(dst):
42 os.remove(dst)
43 if (os.stat(f).st_dev == os.stat(destdir).st_dev):
44 os.link(f, dst)
45 else:
46 shutil.copyfile(f, dst)