def __assert_unid(self, unid, format=None): # {{{ "Accept input UNID, and return storage UNID." assert unid and isinstance(unid, basestring) and \ ALIAS_re.match(unid), \ "Invalid aliased ID: %s " % unid self.__assert_alias() assert unid[1:].startswith(self.alias.handle), \ "Improper UNID for alias. " format = self.__assert_format(format) if unid.endswith('.'+format): unid = unid[:-len(format)] return unid
def __assert_unid(self, unid, format=None): # {{{ "Accept input UNID, and always return storage UNID." assert unid and isinstance(unid, basestring) and \ ALIAS_re.match(unid), \ "Invalid aliased ID: %s " % unid self.__assert_alias() assert unid[1:].startswith(self.alias.handle), \ "Improper UNID for alias. " if format: if self.alias.unid_includes_format: if self.alias.strip_extension: if unid.endswith('.'+format): unid = unid[:-len(format)] elif not unid.endswith('.'+format): unid += '.'+format else: if self.alias.strip_extension: assert unid.endswith('.'+format) unid = unid[:-len(format)] self.__assert_format(format) return unid
def stat(self, unid, digest=None): """ Returns True value when UNID is in storage and up to date, or false when it needs (re)processing. Passing a digest will assure failure when known digest is different. Otherwise a remote HTTP request may be needed for remote content. """ assert ALIAS_re.match(unid), "Invalid aliased ID: %s " % unid info = self.store.getinfo(self.alias, unid).next() if info and digest: if unid_digest != info.digest: logger.info("%s invalidated by digest", unid) return False else: return True elif hasattr(self.alias, 'remote_path'): source_id = self.__remote_id(unid) logger.info("Checking remote path for %s (%s)", unid, source_id) res = None if info: # Known remote UNID res = model.Resource.get_or_insert( hashlib.md5(source_id).hexdigest(), remote_id=source_id) rst = fetch_uriref(source_id, info.time, res.etag, info.digest) else: # Check for existince of remote source rst = fetch_uriref(source_id) if rst: return False contents, time, etag, digest = rst src = None if info: src = info.parent() logger.warning("Remote update (%s): %s", self.alias.handle, source_id) else: logger.warning("New remote source (%s): %s ", self.alias.handle, source_id) src, info = self.store.add(self.alias, unid, contents, digest=digest, time=time) #srcdigest = 'Content-MD5' res = model.Resource.get_or_insert( digest, remote_id=source_id) assert isinstance(contents, unicode) #src = info.parent() #src.source = contents #src.doctree = None #src.put() #info.digest = digest #info.time = time #info.put() #res.etag = etag #res.put() return False elif info: return True else: raise exception.NotFound(unid) else: return False