From ff1cd00ac9c36bc56212d69851ffad52ccba13c9 Mon Sep 17 00:00:00 2001 From: mcmartin Date: Sat, 20 Mar 2010 22:55:37 +0000 Subject: [PATCH] First cut at an RMP verification tool; checks types and keys of an addon against a base content map. git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3533 8092fc87-c524-0410-9efc-e669fe64eaf9 --- tools/rmpver/verify_rmp.py | 61 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 tools/rmpver/verify_rmp.py diff --git a/tools/rmpver/verify_rmp.py b/tools/rmpver/verify_rmp.py new file mode 100644 index 000000000..37671ab01 --- /dev/null +++ b/tools/rmpver/verify_rmp.py @@ -0,0 +1,61 @@ +#!/usr/bin/python + +import sys + +def read_rmp(fname): + lines = file(fname).readlines() + result = {} + errors = [] + for (l, i) in zip(lines, xrange(1, 99999)): + # strip comments + if '#' in l: + l = l[:l.find('#')] + # skip blank or comment lines + if l.strip() == '': + continue + if '=' not in l: + errors.append((i, "no = in resource initializer")) + continue + (key, x) = l.split("=", 1) + if ':' not in x: + errors.append((i, "no : in resource value")) + continue + (restype, resval) = x.split(":", 1) + result[key.strip()] = (i, restype.strip(), resval.strip()) + return (result, errors) + +def used_types(rmp): + v = {} + for x in rmp: + (i, t, z) = rmp[x] + v[t] = 1 + r = v.keys() + r.sort() + return r + +def check_rmp(base, target): + valid_types = used_types(base) + print "Valid types:" + for x in valid_types: print x + for k in target: + (i, t, v) = target[k] + if k not in base: + print "%d: new key '%s'" % (i, k) + if t not in valid_types: + print "%d: new type '%s'" % (i, t) + + +if __name__ == '__main__': + base = sys.argv[1] + target = sys.argv[2] + (b, e) = read_rmp(base) + if e != []: + for (i, x) in e: + print "%d: %s" % (i, x) + print "Errors found in base resource index, cannot continue" + else: + (t, e) = read_rmp(target) + if e != []: + for (i, x) in e: + print "%d: %s" % (i, x) + check_rmp(b, t)