Skip to content

Instantly share code, notes, and snippets.

@branan
Last active January 1, 2016 11:49
Show Gist options
  • Save branan/8140231 to your computer and use it in GitHub Desktop.
Save branan/8140231 to your computer and use it in GitHub Desktop.
#!/opt/local/bin/python2.6
from __future__ import print_function
import optparse
import PyHSPlasma
from PyHSPlasma import *
def indent(text):
"\n".join([" %s" % (line) for line in text.splitlines()])
def diff_span(sources, name, id, a, b):
return (False, "")
def diff_drawable(sources, name, a, b):
return (False, "")
def diff_object(sources, name, a, b):
(different, info) = diff_drawable(sources, name, a.draw, b.draw)
if different:
print("%s differs:" % (name))
print(indent(info))
if __name__ == "__main__":
usage = "usage: %prog [options] prp_a prp_b [object [object ...]]"
parser = optparse.OptionParser(usage=usage)
parser.add_option("-d", "--debug", help="Enable developer output", action="store_true")
(options, args) = parser.parse_args()
if len(args) < 2:
print("Must specify the two PRPs to diff")
exit(1)
sources = (args[0], args[1]) # make a nice tuple of our two sources
objects = args[2:]
# Create our two resmanagers
# Since we expect the two pages to have the same key, they need to
# be in isolated resmgrs
resmgrs = (plResManager(), plResManager())
pages = [None, None]
for i in range(2):
info = resmgrs[i].ReadPage(sources[i])
pages[i] = resmgrs[i].getKeys(info.location, plFactory.kSceneObject)
if objects:
for i in range(2):
pages[i] = [k for k in pages[i] if k.name in objects]
# We now have two pages of keys. We need to pair up those keys, or
# print a warning if a key exists in only one list.
keys = []
for n in [k.name for k in pages[0]]:
k0 = [k for k in pages[0] if k.name == n]
k1 = [k for k in pages[1] if k.name == n]
if not k0:
continue
if not k1:
continue
pages[0].remove(k0[0])
pages[1].remove(k1[0])
keys.append((k0[0],k1[0]))
if pages[0]:
print("The following objects exist only in %s" % (sources[0]))
for k in pages[0]:
print(" %s" % (k.name))
if pages[1]:
print("The following objects exist only in %s" % (sources[1]))
for k in pages[1]:
print(" %s" % (k.name))
for k in keys:
obj0 = resmgrs[0].getObject(k[0])
obj1 = resmgrs[1].getObject(k[1])
diff_object(sources, k[0].name, obj0, obj1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment