In Loki We Trust The many projects of Lokkju, Inc

partner
27Aug/100

Flex SWC class parser

Quick tool that prints out all the available classes exported by a SWC file.

Usage swfinfo.py [file [...]]

#!/usr/bin/python
# Filename: swc-info.pl
# Author : Lokkju Brennr <lokkju@lokkju.com>
# License : GPL
# Copyright 2010 

import sys
import getopt
import zipfile
from xml.etree import ElementTree

def usage():
  print "%s <swcfile>" % (sys.argv[0])
  print "  Prints all classes exported by the provided swc(s).  Supports wildcard globbing"
  sys.exit(2)
  
def main():
  # parse command line options
  if len(sys.argv) < 2:
    usage()
  files = sys.argv[1:]
  for swcfile in files:
    z = zipfile.ZipFile(swcfile,'r')
    catalog = z.open("catalog.xml")
    catalogxml = catalog.read()
    catalog.close()
    z.close()
    tree = ElementTree.XML(catalogxml)
    defs = tree.findall(".//{http://www.adobe.com/flash/swccatalog/9}def")
    for d in defs:
      id = d.attrib.get("id")
      type = d.attrib.get("type")
      if type is None:
        print "%s:%s" % (swcfile,id)
if __name__ == "__main__":
    main()
feedback
   
about
handbook