11 from xml.parsers import expat
21 def end_element_handler(tag):
27 def start_element_handler(tag, attr):
39 fname = find_file(fbase)
41 if fname != None and key != None:
43 pb = gdk.pixbuf_new_from_file(fname)
44 val["colorspace"] = pb.get_colorspace()
45 val["alpha"] = pb.get_has_alpha()
46 val["bps"] = pb.get_bits_per_sample()
47 val["width"] = pb.get_width()
48 val["height"] = pb.get_height()
49 val["rowstride"] = pb.get_rowstride()
50 val["data"] = plistlib.Data(pb.get_pixels())
52 print >> sys.stderr, ( "Error: No such icon file %s" % fbase )
56 fname = find_file(fbase)
58 if fname != None and key != None:
59 val = plistlib.readPlist(fname)
61 print >> sys.stderr, ( "Error: No such plist file %s" % fbase )
65 fname = find_file(fbase)
67 if fname != None and key != None:
71 except Exception, err:
72 print >> sys.stderr, ( "Error: %s" % str(err) )
75 print >> sys.stderr, ( "Error: No such string file %s" % fbase )
79 if type(current) == types.DictType:
81 elif type(current) == types.TupleType:
85 def cdata_handler(str):
88 def resource_parse_file(infile):
89 parser = expat.ParserCreate()
90 parser.StartElementHandler = start_element_handler
91 parser.EndElementHandler = end_element_handler
92 parser.CharacterDataHandler = cdata_handler
93 parser.ParseFile(infile)
96 print >> sys.stderr, (
97 "Usage: %s [-I <inc path>] <resource list> [resource plist]\n"
99 " Creates a resource plist from a resource list\n\n"
101 " I - Include path to search for files\n"
102 " <resource list> Input resources file\n"
103 " <resource plist> Output resources plist file\n"
112 for inc_dir in inc_list:
113 inc = "%s/%s" % (inc_dir, name)
114 if os.path.isfile(inc):
117 if os.path.isfile(name):
127 opts, args = getopt.gnu_getopt(sys.argv[1:], OPTS)
128 except getopt.GetoptError, err:
129 print >> sys.stderr, str(err)
135 # add to include list
138 assert False, "unhandled option"
140 if len(args) > 2 or len(args) < 1:
145 infile = open(args[0])
146 except Exception, err:
147 print >> sys.stderr, ( "Error: %s" % str(err) )
152 outfile = open(args[1], "w")
153 except Exception, err:
154 print >> sys.stderr, ( "Error: %s" % str(err))
159 resource_parse_file(infile)
160 plistlib.writePlist(pl, outfile)