Example #1
0
    def set_tags(self, tag_labels):
        from gallery.db.models import Tag
        tags = []

        for label in tag_labels:
            t = session.query(Tag).filter(Tag.label == label).first()
            if not t:
                t = Tag(label)
                session.add(t)
            
            tags += [ t ]

        self.tags = tags
        session.flush()
Example #2
0
def scan_dir(d, tags):
    files = os.listdir(d)

    for f in files:
        path = os.path.join(d, f)
        if f.startswith('.'):
            continue
        if os.path.isdir(path):
            scan_dir(path, tags + [ f ])

        if os.path.splitext(f.lower())[1] not in [ '.jpg', '.jpeg' ]:
            continue

        photo_tags = tags + [ os.path.splitext(f)[0] ]
        p = Photo(path)
        session.add(p)
        try:
            p.set_tags(set(photo_tags))
        except:
            print(photo_tags)
            raise
        session.flush()