X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/a1a95fe51f648a7fff2cf92c55a2706d6f7fa3e0..00906f2fc0432cede204c7870e6caecf427d7024:/librarian/picture.py?ds=inline diff --git a/librarian/picture.py b/librarian/picture.py index 70b372f..0f5c99a 100644 --- a/librarian/picture.py +++ b/librarian/picture.py @@ -35,6 +35,7 @@ class PictureInfo(WorkInfo): Field(DCNS('subject.type'), 'kinds', salias='kind', multiple=True), Field(DCNS('format.dimensions'), 'dimensions', required=False), + Field(DCNS('format.checksum.sha1'), 'sha1', required=True), Field(DCNS('description.medium'), 'medium', required=False), Field(DCNS('description.dimensions'), 'original_dimensions', required=False), Field(DCNS('format'), 'mime_type', required=False), @@ -153,3 +154,28 @@ class WLPicture(object): def image_file(self, *args, **kwargs): return open(self.image_path, *args, **kwargs) + + def partiter(self): + """ + Iterates the parts of this picture and returns them and their metadata + """ + for part in self.edoc.iter("div"): + pd = {} + pd['type'] = part.get('type') + if pd['type'] == 'area': + pd['coords'] = ((int(part.get('x1')), int(part.get('y1'))), + (int(part.get('x2')), int(part.get('y2')))) + + pd['themes'] = [] + pd['object'] = None + parent = part + while True: + parent = parent.getparent() + if parent is None: + break + if parent.tag == 'sem': + if parent.get('type') == 'theme': + pd['themes'] += map(unicode.strip, unicode(parent.get('theme')).split(',')) + elif parent.get('type') == 'object' and pd['object'] is None: + pd['object'] = parent.get('object') + yield pd