|
| 1 | +import sys |
| 2 | +import gi |
| 3 | +gi.require_version('GdkPixbuf', '2.0') |
| 4 | +from gi.repository import GdkPixbuf |
| 5 | + |
| 6 | +import re |
| 7 | + |
| 8 | +def replace_many(src2dest, buf): |
| 9 | + src_re = re.compile('|'.join(re.escape(word) for word in src2dest)) |
| 10 | + |
| 11 | + def replace_repl(mo): |
| 12 | + return src2dest[mo.group()] |
| 13 | + return src_re.sub(replace_repl, buf) |
| 14 | + |
| 15 | +if __name__ == '__main__': |
| 16 | + pixbuf64 = GdkPixbuf.Pixbuf.new_from_file("data/icons/hicolor/64x64/apps/dropbox.png") |
| 17 | + pixbuf16 = GdkPixbuf.Pixbuf.new_from_file("data/icons/hicolor/16x16/apps/dropbox.png") |
| 18 | + src2dest = {'@PACKAGE_VERSION@': sys.argv[1], |
| 19 | + '@DESKTOP_FILE_DIR@': sys.argv[2], |
| 20 | + '@IMAGEDATA64@': ("GdkPixbuf.Pixbuf.new_from_data(%r, GdkPixbuf.Colorspace.RGB, %r, %r, %r, %r, %r)" % |
| 21 | + (pixbuf64.get_pixels(), pixbuf64.get_has_alpha(), pixbuf64.get_bits_per_sample(), |
| 22 | + pixbuf64.get_width(), pixbuf64.get_height(), pixbuf64.get_rowstride())), |
| 23 | + '@IMAGEDATA16@': ("GdkPixbuf.Pixbuf.new_from_data(%r, GdkPixbuf.Colorspace.RGB, %r, %r, %r, %r, %r)" % |
| 24 | + (pixbuf16.get_pixels(), pixbuf16.get_has_alpha(), pixbuf16.get_bits_per_sample(), |
| 25 | + pixbuf16.get_width(), pixbuf16.get_height(), pixbuf16.get_rowstride())), |
| 26 | + } |
| 27 | + |
| 28 | + buf = sys.stdin.read() |
| 29 | + sys.stdout.write(replace_many(src2dest, buf)) |
0 commit comments