def is_embargoed(silo, id, refresh=False): # TODO evaluate r.expire settings for these keys - popularity resets ttl or increases it? e = None e_d = None try: e = r.get("%s:%s:embargoed" % (silo.state['storage_dir'], id)) e_d = r.get("%s:%s:embargoed_until" % (silo.state['storage_dir'], id)) except: pass if refresh or (not e or not e_d): if silo.exists(id): item = silo.get_item(id) e = item.metadata.get("embargoed") e_d = item.metadata.get("embargoed_until") if e not in ['false', 0, False]: e = True else: e = False try: r.set("%s:%s:embargoed" % (silo.state['storage_dir'], id), e) r.set("%s:%s:embargoed_until" % (silo.state['storage_dir'], id), e_d) except: pass return (e, e_d)
def is_embargoed(silo, id, refresh=False): # TODO evaluate r.expire settings for these keys - popularity resets ttl or increases it? e = None e_d = None try: e = r.get("%s:%s:embargoed" % (silo.state['storage_dir'], id)) e_d = r.get("%s:%s:embargoed_until" % (silo.state['storage_dir'], id)) except: pass if refresh or (not e or not e_d): if silo.exists(id): item = silo.get_item(id) e = item.metadata.get("embargoed") e_d = item.metadata.get("embargoed_until") if e not in ['false', 0, False]: e = True else: e = False try: r.set("%s:%s:embargoed" % (silo.state['storage_dir'], id), e) r.set( "%s:%s:embargoed_until" % (silo.state['storage_dir'], id), e_d) except: pass return (e, e_d)
def create_new(silo, id, creator, title=None, embargoed=None, embargoed_until=None, embargo_days_from_now=None, **kw): item = silo.get_item(id, startversion="0") item.metadata['createdby'] = creator item.metadata['uuid'] = uuid4().hex item.add_namespace('oxds', "http://vocab.ox.ac.uk/dataset/schema#") item.add_triple(item.uri, u"rdf:type", "oxds:DataSet") item.metadata['embargoed_until'] = '' item.del_triple(item.uri, u"oxds:isEmbargoed") item.del_triple(item.uri, u"oxds:embargoedUntil") try: r.set("%s:%s:embargoed_until" % (silo.state['storage_dir'], id), ' ') except: pass e, e_d = get_embargo_values(embargoed=embargoed, embargoed_until=embargoed_until, embargo_days_from_now=embargo_days_from_now) if e: item.metadata['embargoed'] = True item.add_triple(item.uri, u"oxds:isEmbargoed", 'True') try: r.set("%s:%s:embargoed" % (silo.state['storage_dir'], id), True) except: pass if e_d: item.metadata['embargoed_until'] = e_d item.add_triple(item.uri, u"oxds:embargoedUntil", e_d) try: r.set("%s:%s:embargoed_until" % (silo.state['storage_dir'], id), e_d) except: pass else: item.metadata['embargoed'] = False item.add_triple(item.uri, u"oxds:isEmbargoed", 'False') try: r.set("%s:%s:embargoed" % (silo.state['storage_dir'], id), False) except: pass item.add_triple(item.uri, u"dcterms:identifier", id) item.add_triple(item.uri, u"dcterms:mediator", creator) item.add_triple(item.uri, u"dcterms:publisher", ag.publisher) item.add_triple(item.uri, u"dcterms:created", datetime.now()) item.add_triple(item.uri, u"oxds:currentVersion", item.currentversion) if RIGHTS and RIGHTS.startswith('http'): item.add_triple(item.uri, u"dcterms:rights", URIRef(RIGHTS)) elif RIGHTS: item.add_triple(item.uri, u"dcterms:rights", Literal(RIGHTS)) if LICENSE and LICENSE.startswith('http'): item.add_triple(item.uri, u"dcterms:license", URIRef(LICENSE)) elif LICENSE: item.add_triple(item.uri, u"dcterms:license", Literal(LICENSE)) #TODO: Add current version metadata if title: item.add_triple(item.uri, u"rdfs:label", title) item.sync() return item
def create_new(silo, id, creator, title=None, embargoed=None, embargoed_until=None, embargo_days_from_now=None, **kw): item = silo.get_item(id, startversion="0") item.metadata['createdby'] = creator item.metadata['uuid'] = uuid4().hex item.add_namespace('oxds', "http://vocab.ox.ac.uk/dataset/schema#") item.add_triple(item.uri, u"rdf:type", "oxds:DataSet") item.metadata['embargoed_until'] = '' item.del_triple(item.uri, u"oxds:isEmbargoed") item.del_triple(item.uri, u"oxds:embargoedUntil") try: r.set("%s:%s:embargoed_until" % (silo.state['storage_dir'], id), ' ') except: pass e, e_d = get_embargo_values(embargoed=embargoed, embargoed_until=embargoed_until, embargo_days_from_now=embargo_days_from_now) if e: item.metadata['embargoed'] = True item.add_triple(item.uri, u"oxds:isEmbargoed", 'True') try: r.set("%s:%s:embargoed" % (silo.state['storage_dir'], id), True) except: pass if e_d: item.metadata['embargoed_until'] = e_d item.add_triple(item.uri, u"oxds:embargoedUntil", e_d) try: r.set( "%s:%s:embargoed_until" % (silo.state['storage_dir'], id), e_d) except: pass else: item.metadata['embargoed'] = False item.add_triple(item.uri, u"oxds:isEmbargoed", 'False') try: r.set("%s:%s:embargoed" % (silo.state['storage_dir'], id), False) except: pass item.add_triple(item.uri, u"dcterms:identifier", id) item.add_triple(item.uri, u"dcterms:mediator", creator) item.add_triple(item.uri, u"dcterms:publisher", PUBLISHER) item.add_triple(item.uri, u"dcterms:created", datetime.now()) item.add_triple(item.uri, u"oxds:currentVersion", item.currentversion) if RIGHTS and RIGHTS.startswith('http'): item.add_triple(item.uri, u"dcterms:rights", URIRef(RIGHTS)) elif RIGHTS: item.add_triple(item.uri, u"dcterms:rights", Literal(RIGHTS)) if LICENSE and LICENSE.startswith('http'): item.add_triple(item.uri, u"dcterms:license", URIRef(LICENSE)) elif LICENSE: item.add_triple(item.uri, u"dcterms:license", Literal(LICENSE)) #TODO: Add current version metadata if title: item.add_triple(item.uri, u"rdfs:label", title) item.sync() return item