Example #1
0
def exists_impl(pid):
    destpath = app.config['BLOB_STORAGE'].dest(pid)
    exists = os.path.exists(destpath)
    if exists:
        message = '%s %s FOUND at %s' % (iso8601utcnow(), pid, destpath)
    else:
        message = '%s %s NOT FOUND at %s' % (iso8601utcnow(), pid, destpath)
    utcnow = iso8601utcnow()
    return jsonr(dict(
        exists=exists,
        time=utcnow,
        message=message,
        pid=pid,
        path=destpath
    ))
Example #2
0
def exists_impl(pid):
    destpath = app.config[STORAGE].dest(pid)
    exists = app.config[STORAGE].exists(pid)
    if exists:
        message = '%s %s FOUND at %s' % (iso8601utcnow(), pid, destpath)
    else:
        message = '%s %s NOT FOUND at %s' % (iso8601utcnow(), pid, destpath)
    utcnow = iso8601utcnow()
    return jsonr(dict(
        exists=exists,
        time=utcnow,
        message=message,
        pid=pid,
        path=destpath
    ))
Example #3
0
def deposit_impl(pid):
    deposit_data = request.data
    destpath = app.config[STORAGE].dest(pid)
    try:
        os.makedirs(os.path.dirname(destpath))
    except:
        pass
    with open(destpath,'w') as out:
        shutil.copyfileobj(StringIO(deposit_data), out)
    utcnow = iso8601utcnow()
    message = '%s wrote %d bytes to %s' % (utcnow, len(deposit_data), destpath)
    return jsonr(dict(
        status='OK',
        time=utcnow,
        message=message,
        pid=pid,
        path=destpath
    ))
Example #4
0
def deposit_impl(pid):
    zipdata = request.data
    destpath = app.config['BLOB_STORAGE'].dest(pid)
    try:
        os.makedirs(os.path.dirname(destpath))
    except:
        pass
    destpath_part = destpath+'.part'
    with open(destpath_part,'w') as out:
        shutil.copyfileobj(StringIO(zipdata), out)
    os.rename(destpath_part, destpath)
    utcnow = iso8601utcnow()
    message = '%s wrote %d bytes to %s' % (utcnow, len(zipdata), destpath)
    return jsonr(dict(
        status='OK',
        time=utcnow,
        message=message,
        pid=pid,
        path=destpath
    ))
Example #5
0
def bins2atom(bins,link,out=sys.stdout):
    """Output an Atom feed of recent bins from the given filesystem.
    
    Parameters:
    fs - the filesystem (instance of Filesystem)
    link - the feed's self-link
    n - the number of recent entries to include (default: 20)
    date - the latest date to return (default: now)
    out - where to write the feed (default: stdout)
    """
    nsmap = { None: ATOM_NAMESPACE }
    xhtml = { None: 'http://www.w3.org/1999/xhtml' }
    feed = Element('feed', nsmap=nsmap)
    SubElement(feed, 'title').text = 'Imaging FlowCytobot most recent data'
    SubElement(feed, 'subtitle').text = 'Live marine phytoplankton cytometry with imagery'
    author = SubElement(feed, 'author')
    SubElement(author, 'name').text = 'Imaging FlowCytobot'
    SubElement(feed, 'link', href=link, rel='self')
    SubElement(feed, 'id').text = link
    if len(bins) > 0:
        SubElement(feed, 'updated').text = bins[0].iso8601time
    else:
        SubElement(feed,'updated').text = iso8601utcnow()
    for bin in bins:
        t = SubElement(feed, 'entry')
        SubElement(t, 'title').text = bin_title(bin)
        SubElement(t, 'link', href=bin.pid, rel='alternate', type='application/rdf+xml')
        SubElement(t, 'link', href=bin.pid+'.xml', rel='alternate', type='text/xml')
        SubElement(t, 'link', href=bin.pid+'.json', rel='alternate', type='application/json')
        SubElement(t, 'id').text = bin.pid
        SubElement(t, 'updated').text = bin.iso8601time
        content = SubElement(t, 'content', type='xhtml')
        div = SubElement(content, QName(XHTML_NAMESPACE, 'div'), nsmap=xhtml)
        headers = bin.headers()
        for header in sorted(headers.keys()):
            SubElement(div, 'div').text = header + ': ' + str(headers[header])
    ElementTree(feed).write(out, pretty_print=True)