blob: 0986a2165152fe358da05cc190fb1f4dedaf7ba6 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#!/usr/bin/env python
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002
3import os
4import sys
5import glob
6import shutil
7import errno
8
9def mkdir(d):
10 try:
11 os.makedirs(d)
12 except OSError as e:
13 if e.errno != errno.EEXIST:
14 raise e
15
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050016if len(sys.argv) < 5:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050017 print("Incorrect number of arguments specified")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050018 print("syntax: gen-lockedsig-cache <locked-sigs.inc> <input-cachedir> <output-cachedir> <nativelsbstring>")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050019 sys.exit(1)
20
Patrick Williamsf1e5d692016-03-30 15:21:19 -050021print('Reading %s' % sys.argv[1])
Patrick Williamsc124f4f2015-09-15 14:41:29 -050022sigs = []
23with open(sys.argv[1]) as f:
24 for l in f.readlines():
25 if ":" in l:
26 sigs.append(l.split(":")[2].split()[0])
27
Patrick Williamsf1e5d692016-03-30 15:21:19 -050028print('Gathering file list')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050029files = set()
30for s in sigs:
31 p = sys.argv[2] + "/" + s[:2] + "/*" + s + "*"
32 files |= set(glob.glob(p))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050033 p = sys.argv[2] + "/%s/" % sys.argv[4] + s[:2] + "/*" + s + "*"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050034 files |= set(glob.glob(p))
35
Patrick Williamsf1e5d692016-03-30 15:21:19 -050036print('Processing files')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050037for f in files:
Patrick Williamsf1e5d692016-03-30 15:21:19 -050038 sys.stdout.write('Processing %s... ' % f)
39 _, ext = os.path.splitext(f)
40 if not ext in ['.tgz', '.siginfo', '.sig']:
41 # Most likely a temp file, skip it
42 print('skipping')
43 continue
44 dst = os.path.join(sys.argv[3], os.path.relpath(f, sys.argv[2]))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050045 destdir = os.path.dirname(dst)
46 mkdir(destdir)
47
48 if os.path.exists(dst):
49 os.remove(dst)
50 if (os.stat(f).st_dev == os.stat(destdir).st_dev):
Patrick Williamsf1e5d692016-03-30 15:21:19 -050051 print('linking')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050052 os.link(f, dst)
53 else:
Patrick Williamsf1e5d692016-03-30 15:21:19 -050054 print('copying')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050055 shutil.copyfile(f, dst)
Patrick Williamsf1e5d692016-03-30 15:21:19 -050056
57print('Done!')