Vassal-python - tool for helping module developers automate repetitive changes

Hi Jason,

Nice.

I have another tool to manipulate a VASSAL module. It takes a different approach to yours, in that it deals with the ZIP file and the DOM of buildFile.xml and moduledata directly.

You can find it at

Basically, its use is something like

  • Open the module using zipfile.ZipFile
  • Get the buildFile.xml entry in the module
    • Parse in the DOM via xml.dom.minidom
    • Manipulate the DOM
  • Write new buildFile.xml
  • Update the module ZIP file

The tools have functions to

  • Get specific elements in the DOM, e.g, a map, board, pieceslot, and so on
  • Add specific elements to the DOM, e.g., a map, a grid, a board, a pieceslot, and so on
  • Encode and decode (some) piece traits. This is not complete, but can be extended as needed.

Most of the things going on are using plain Python. If one need some sort of image manipulation, or the like, then one can use for example PIL.

The tool was developed to help facilitate exporting a VASSAL module from LaTeX sources, and as such isn’t a true standalone Python module. However, if one does something like

import wgexport as wg 
from zipfile import ZipFile 

with ZipFile('module.vmod','r') as vmod:
     build = wg.get_doc(vmod.read('buildFile.xml'))

# Use wg functions, e.g., 
pieces = wg.get_pieces(build,asdict=True)
mypiece = pieces['mypiece']
parts       = wg.get_piece_parts(mypiece.childNode[0].nodeValue)
# Parts is a list of piece traits which can be changed, amended to, and so on 
... # More stuff using wg and xml.dom functions etc. 

with ZipFile('module.vmod','r') as vmod:
      with ZipFile('temp.vmod','w') as newvmod:
            newvmod.comment = vmod.comment # preserve the comment
            for item in vmod.infolist():
                if item.filename != 'buildFile.xml':
                    newvmod.writestr(item, vmod.read(item.filename))
            newvmod.writestr('buildFile.xml', build.toprettyxml(indent=' ',
                                                                                            encoding="UTF-8",
                                                                                            standalone=False))

one will get a new module file temp.vmod with the buildFile.xml updated according to that specified in the script.

Note, it is possible to build an entire module from scratch (well, external images need to be there already) using the tool (which is how I use it to export from PDF and JSON created from LaTeX).

Anyways, I though you might find it interesting.

Yours,

Christian

1 Like