"""Quick'n'Dirty Python script to generate example XML for the drawers Place in the Kupu package root, adjust vars and run with a Python with PIL installed (obviously it wouldn't be too hard to either remove the dependency or let the script handle non-images, but this wasn't the usecase for now ;) """ import os, re from PIL import Image path = 'kupuimages' title = 'Kupu buttons' outputfile = 'kupudrawers/kupubuttons.xml' filereg = '\.png$' os.chdir('common') xml = ('\n' '\n' ' %(outputfile)s\n' ' kupuimages/kupulibrary.png\n' ' %(title)s\n' ' %(outputfile)s\n' ' \n') % {'path': path, 'title': title, 'outputfile': outputfile, } reg = re.compile(filereg) chunks = [] for f in os.listdir(path): if reg.search(f): img = Image.open('%s/%s' % (path, f)) vars = {'filename': f, 'title': '.'.join(f.split('.')[:-1]), 'path': '%s/%s' % (path, f), 'size': os.path.getsize('%s/%s' % (path, f)), 'width': img.size[0], 'height': img.size[1], } chunks.append((' \n' ' %(path)s\n' ' %(title)s\n' ' \n' ' %(size)s\n' ' %(height)s\n' ' %(width)s\n' ' \n') % vars) xml += ''.join(chunks) + ' \n\n' open(outputfile, 'w').write(xml)