12 from xml.parsers import expat
22 def end_element_handler(tag):
28 def start_element_handler(tag, attr):
40 fname = find_file(fname)
42 if fname != None and key != None:
44 pb = gtk.gdk.pixbuf_new_from_file(fname)
45 val["colorspace"] = pb.get_colorspace()
46 val["alpha"] = pb.get_has_alpha()
47 val["bps"] = pb.get_bits_per_sample()
48 val["width"] = pb.get_width()
49 val["height"] = pb.get_height()
50 val["rowstride"] = pb.get_rowstride()
51 val["data"] = plistlib.Data(pb.get_pixels())
54 fname = find_file(fname)
56 if fname != None and key != None:
57 val = plistlib.readPlist(fname)
60 fname = find_file(fname)
62 if fname != None and key != None:
66 except Exception, err:
67 print >> sys.stderr, ( "Error: %s" % str(err) )
70 if type(current) == types.DictType:
72 elif type(current) == types.TupleType:
76 def cdata_handler(str):
79 def resource_parse_file(infile):
80 parser = expat.ParserCreate()
81 parser.StartElementHandler = start_element_handler
82 parser.EndElementHandler = end_element_handler
83 parser.CharacterDataHandler = cdata_handler
84 parser.ParseFile(infile)
87 print >> sys.stderr, (
88 "Usage: %s [-I <inc path>] <resource list> [resource plist]\n"
90 " Creates a resource plist from a resource list\n\n"
92 " I - Include path to search for files\n"
93 " <resource list> Input resources file\n"
94 " <resource plist> Output resources plist file\n"
103 for inc_dir in inc_list:
104 inc = "%s/%s" % inc_dir, name
105 if os.path.isfile(inc):
108 if os.path.isfile(name):
118 opts, args = getopt.gnu_getopt(sys.argv[1:], OPTS)
119 except getopt.GetoptError, err:
120 print >> sys.stderr, str(err)
126 # add to include list
129 assert False, "unhandled option"
131 if len(args) > 2 or len(args) < 1:
136 infile = open(args[0])
137 except Exception, err:
138 print >> sys.stderr, ( "Error: %s" % str(err) )
142 infile = open(args[0])
143 except Exception, err:
144 print >> sys.stderr, ( "Error: %s" % str(err) )
149 outfile = open(args[1], "w")
150 except Exception, err:
151 print >> sys.stderr, ( "Error: %s" % str(err))
156 resource_parse_file(infile)
157 plistlib.writePlist(pl, outfile)