Beispiel #1
0
    def _import(self, abspath):
        # check same image has not already been imported
        hash = img_md5(abspath)
        photo = DBSession.query(Photo).filter_by(md5sum=hash)
        if photo.count() > 0:
            log.info("Same md5sum already exists in database")
            return photo.first()

        # process and import photos to public/data/photos dir
        info = ip.process_image(abspath, md5sum=hash)
        os.unlink(abspath)

        # import image in db
        photo = Photo()
        photo.uri = info["uri"]
        photo.md5sum = hash
        photo.time = info["date"]
        DBSession.add(photo)
        DBSession.flush()

        return info
Beispiel #2
0
def process(row, msgs):
    fspot_id = row.id
    insert = False
    photo = DBSession.query(Photo).filter_by(fspot_id=fspot_id).first()
    if photo is None:
        insert = True
        photo = Photo()
        src = decode_fspot_uri(
                row.uri if row.last_version is None else row.last_version.uri)
        md5sum = img_md5(src)
        # copy and scale image if needed
        info = IP.process_image(src, md5sum=md5sum)
        # set photo db record
        photo.fspot_id = fspot_id
        photo.uri = info['uri']
        photo.md5sum = md5sum
        photo.time = info['date']

    if insert or not OPTIONS['skip-existing']:
        # update row in db
        if row.description:
            photo.description = row.description
        photo.rating = row.rating
        photo.tags = get_tags([t.name for t in row.tags])

    #TODO: detect if photo version has changed and update photo accordingly

    try:
        uri = photo.uri # keep track of photo.uri outside the DBSession
        DBSession.add(photo)
        transaction.commit()
        if insert:
            msgs.append("Photo %s has been imported in PyGall" % uri)
    except IntegrityError:
        #print "Photo %s already exists in db" % uri
        transaction.abort()
        #TODO: make it possible to update record

    return fspot_id