Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # |
| 3 | # gen-lockedsig-cache <locked-sigs.inc> <input-cachedir> <output-cachedir> |
| 4 | # |
| 5 | |
| 6 | import os |
| 7 | import sys |
| 8 | import glob |
| 9 | import shutil |
| 10 | import errno |
| 11 | |
| 12 | def mkdir(d): |
| 13 | try: |
| 14 | os.makedirs(d) |
| 15 | except OSError as e: |
| 16 | if e.errno != errno.EEXIST: |
| 17 | raise e |
| 18 | |
| 19 | if len(sys.argv) < 3: |
| 20 | print("Incorrect number of arguments specified") |
| 21 | sys.exit(1) |
| 22 | |
| 23 | sigs = [] |
| 24 | with 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 | |
| 29 | files = set() |
| 30 | for 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 | |
| 36 | for 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) |