Esempio n. 1
0
def geograph_image( id ):
    """
    Return geograph image by it's id. Used for displaing as background.
    """
    rootdir = db.getGeographDir(id)
    image = str(id).zfill(6) + ".jpg"
    log.debug("geograph_image: Downloading %s" % os.path.join(rootdir, image))
    #download=true forces download even if browser can display it inline. (still works inline with css for everything except IE)
    return static_file(image, root=rootdir, download=False)
Esempio n. 2
0
def geograph_image(id):
    """
    Return geograph image by it's id. Used for displaing as background.
    """
    rootdir = db.getGeographDir(id)
    image = str(id).zfill(6) + ".jpg"
    log.debug("geograph_image: Downloading %s" % os.path.join(rootdir, image))
    #download=true forces download even if browser can display it inline. (still works inline with css for everything except IE)
    return static_file(image, root=rootdir, download=False)
Esempio n. 3
0
def editGeograph(id):
    """ imports geograph image as if it were uploaded. Creates a new copy of the image and the original image is left untouched """
    response = {}
    #client_ip
    ip = request.environ.get('REMOTE_ADDR')
    #geograph image
    rootdir = db.getGeographDir(id)
    imagename = str(id).zfill(6)
    imagefile = os.path.join(rootdir, imagename + ".jpg")
    log.debug("Downloading %s" % imagefile)
    try:
        media = mediafactory.MediaFactory()
        media.loadFromWeb(ip, imagename + ".jpg", open(imagefile))
        # update coords in exif from geograph database
        (lon, lat, tags) = db.geograph_byid(id)
        log.debug("geograph metadata for " + id)
        log.debug(logtool.pp((lon, lat, tags)))
        #create sessions.js
        media.saveconf()
        updatedata = {
            "GPSLatitude": ` lat `,
            "GPSLongitude": ` lon `,
            "GPSLatitudeRef": "S" if lat < 0 else "N",
            "GPSLongitudeRef": "W" if lon < 0 else "E"
        }
        media.update(updatedata)
        if tags != None:
            media.update({'Tags': tags}, group="Custom")
    except ExifException as e:
        msg = e.shortmsg
        response["error"] = 1
        log.debug("ExifException: " + msg)
        response = {"uuid": media.uuid, "error": 1, "msg": msg}
        return response
    except IOError:
        response["error"] = 1
        response["msg"] = "Could not find geograph file %s." % imagename
        return response
    log.debug(logtool.pp(media.mediamd))
    if media.mediamd != []:
        media.saveconf()
        response = {"uuid": media.uuid, "error": 0, "msg": "Success!"}
    else:
        response["error"] = 1
        response[
            "msg"] = "Could not find any supported format inside %s." % media.filename
    return response
Esempio n. 4
0
def editGeograph(id):
    """ imports geograph image as if it were uploaded. Creates a new copy of the image and the original image is left untouched """
    response = {}
    #client_ip
    ip = request.environ.get('REMOTE_ADDR')
    #geograph image
    rootdir = db.getGeographDir(id)
    imagename = str(id).zfill(6)
    imagefile = os.path.join(rootdir, imagename + ".jpg" )
    log.debug("Downloading %s" % imagefile )
    try:
        media = mediafactory.MediaFactory()
        media.loadFromWeb( ip, imagename + ".jpg", open(imagefile) )
        # update coords in exif from geograph database
        (lon,lat,tags) = db.geograph_byid(id)
        log.debug("geograph metadata for " + id )
        log.debug( logtool.pp( (lon,lat,tags) ) )
        #create sessions.js
        media.saveconf()
        updatedata = {
            "GPSLatitude" : `lat`,
            "GPSLongitude" : `lon`,
            "GPSLatitudeRef" : "S" if lat<0 else "N",
            "GPSLongitudeRef" : "W" if lon<0 else "E"
        }
        media.update(updatedata)
        if tags != None:
            media.update( { 'Tags' : tags }, group="Custom" )
    except ExifException as e:
        msg = e.shortmsg
        response["error"] = 1 
        log.debug("ExifException: " + msg )
        response = { "uuid":media.uuid, "error":1, "msg": msg }
        return response
    except IOError:
        response["error"] = 1 
        response["msg"] = "Could not find geograph file %s." %  imagename
        return response    
    log.debug( logtool.pp(media.mediamd))
    if media.mediamd != []:
         media.saveconf()
         response = { "uuid": media.uuid, "error": 0, "msg":"Success!" }
    else:
         response["error"] = 1 
         response["msg"] = "Could not find any supported format inside %s." %  media.filename
    return response