Skip to content

Instantly share code, notes, and snippets.

@Deledrius
Created November 14, 2019 01:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Deledrius/92985b1b895b7446898fbaaba810e787 to your computer and use it in GitHub Desktop.
Save Deledrius/92985b1b895b7446898fbaaba810e787 to your computer and use it in GitHub Desktop.
A utility for producing a textual overview of a PRP file, used to compare in diffs.
#!/usr/bin/env python
# PRP_as_Text is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PRP_as_Text is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PRP_as_Text. If not, see <http://www.gnu.org/licenses/>.
"""prp_as_text.py
A utility for producing a textual overview of a PRP file,
used to compare in diffs.
by Joseph Davies (deledrius@gmail.com)
* Requires libHSPlasma and PyHSPlasma (https://github.com/H-uru/libhsplasma)
Usage:
./prp_as_text.py pagename.prp
"""
import os
import sys
import textwrap
try:
import PyHSPlasma
except ImportError as e:
print("Required module PyHSPlasma cannot be found.", file=sys.stderr)
sys.exit(1)
## Create our Resource Manager
plResMgr = PyHSPlasma.plResManager()
def main():
version = PyHSPlasma.pvMoul
plResMgr.setVer(version)
page = sys.argv[1]
pageInfo = plResMgr.ReadPage(page)
pageLoc = pageInfo.location
objTypes = plResMgr.getTypes(pageLoc)
typeMap = {}
for otype in objTypes:
typeMap[otype] = {}
keys = frozenset(plResMgr.getKeys(pageLoc, otype))
for key in keys:
typeMap[otype][key.name] = key
types = sorted(typeMap.keys())
for otype in types:
print("Type: {}".format(PyHSPlasma.plFactory.ClassName(otype)))
keys = sorted(typeMap[otype].keys())
for keyname in keys:
print("\t{} : {}".format(typeMap[otype][keyname].name, typeMap[otype][keyname]))
print(textwrap.indent(typeMap[otype][keyname].object.prc, "\t\t"))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment