2 # -*- coding: utf-8 -*-
7 from shutil import rmtree,copytree
10 from lxml import etree
11 from lxml.builder import ElementMaker
13 from treecutter import constants as const
15 class PhotoAlbum(object):
16 def __init__(self, uri):
20 def thumbnail(self,infile,size):
21 file, ext = os.path.splitext(infile)
22 im = Image.open(infile)
23 im.thumbnail(size, Image.ANTIALIAS)
24 im.save(file + "."+str(size(0))+"x"+str(size(1))+, "JPG")
27 rootdirs = [self.uri+'/'+d for d in dirs]
28 for rootdir,d in zip(rootdirs,dirs):
33 for root, subdir, files in os.walk(d):
35 self.filelist.append(os.path.join(root,file))
38 db = ElementMaker(namespace=const.DB_NS, nsmap=const.NSMAP)
40 for f in self.filelist:
41 co.append(db.filename(db.link(f,**{const.XLINK+"href": f})))
44 def recursively_empty(e):
47 return all((recursively_empty(c) for c in e.iterchildren()))
50 context = etree.iterwalk(xml)
51 for action, elem in context:
52 parent = elem.getparent()
53 if recursively_empty(elem):
56 if __name__ == "__main__":
57 for arg in sys.argv[1:]:
64 album = PhotoAlbum(argument)
69 #print(etree.tostring(cxml, pretty_print=True))
70 #sys.stdout.write(out.encode('utf-8'))
71 sys.stdout.write(etree.tostring(axml,encoding='UTF-8',pretty_print=True))