8 print("usage: cleancrcmap <in_map> <out_map> <searchdir>")
11 # load and check the old map
12 searchpath
= sys
.argv
[3]
14 with
open(sys
.argv
[1], 'r') as f
:
17 if line
== '' or line
[0] == '#':
20 crcstr
= tok
[0].strip()
21 if crcstr
.startswith('0x'):
22 crc
= int(crcstr
[2:], 16)
25 tok
[1] = tok
[1].strip()
26 [fname
, fext
] = os
.path
.splitext(tok
[1])
27 [fname
, ffmt
] = os
.path
.splitext(fname
)
28 fname
= fname
+ ffmt
[:-1] + '*'
29 matches
= glob
.glob(os
.path
.join(searchpath
, fname
))
31 print("warning: texture '{0}' does not match anything in '{1}'".format(fname
, searchpath
))
34 tup
= (crc
, os
.path
.relpath(s
, searchpath
))
35 if not (tup
in inmap
):
38 # save cleaned up version to the new one
39 with
open(sys
.argv
[2], 'w') as f
:
40 for (crc
, fpath
) in inmap
:
41 f
.write("0x{0:08x}, {1}\n".format(crc
, fpath
))