示例#1
0
 def is_expired(self, key):
     if key:
         timediff = datetime.now() - self.utc_to_local(parse_ts(key.last_modified))
         return timediff.seconds > self.context.config.STORAGE_EXPIRATION_SECONDS
     else:
         # If our key is bad just say we're expired
         return True
示例#2
0
 def is_expired(self, key):
     if key:
         timediff = datetime.now() - self.utc_to_local(parse_ts(key.last_modified))
         return timediff.seconds > self.context.config.STORAGE_EXPIRATION_SECONDS
     else:
         #If our key is bad just say we're expired
         return True
示例#3
0
    def last_updated(self):
        path = self.context.request.url
        file_abspath = self.normalize_path(path)
        file_key = self.storage.get_key(file_abspath)

        if not file_key or self.is_expired(file_key):
            return None

        return self.utc_to_local(parse_ts(file_key.last_modified))
示例#4
0
def videochats():
    for fn, line in videochatlines():
        data = json.loads(line)
        date = data.get('date', None)
        if date is not None:
            date = parse_ts(date)
        #print('data: {}'.format(data))
        d, _ = os.path.split(fn)
        proj = d.split(os.sep)[2]
        yield proj, date, fn
示例#5
0
    def last_updated(self):
        path = self.context.request.url
        file_abspath = self.normalize_path(path)
        file_key = self.storage.get_key(file_abspath)

        if not file_key or self.is_expired(file_key):
            logger.debug("[RESULT_STORAGE] s3 key not found at %s" % file_abspath)
            return None

        return self.utc_to_local(parse_ts(file_key.last_modified))
示例#6
0
 def _authenticate(self):
     if not self._token_holder or self._token_holder["expires"] < time.time():
         result = self._post("authentication.json", dict(
             username=self.settings["login"],
             password=self.settings["password"],
         ), no_auth=True)
         response = result["response"]
         token = response["token"]
         expires = parse_ts(response["expires"]).timestamp() - 100
         self._token_holder.update(dict(token=token, expires=expires))
示例#7
0
    def _cache_folder_info(self, norm_path: Tuple[str]):
        self._authenticate()
        if norm_path not in self._folder_folders:
            if norm_path:
                parent_path = norm_path[:-1]
                self._cache_folder_info(parent_path)
                folder_id = self._folder_infos[norm_path].folder_id
            else:
                folder_id = self.root_folder_id

            info = self._get("files/%s" % folder_id)

            folders = info["response"]["folders"]
            folder_infos = []
            for folder in folders:
                folder_id = folder["id"]
                title = folder["title"]
                updated = parse_ts(folder["updated"]).timestamp()
                if title != "...":
                    path = (*norm_path, title.strip().lower())
                    folder_info = FolderInfo(folder_id, title, updated)
                    self._folder_infos[path] = folder_info
                    folder_infos.append(folder_info)
            self._folder_folders[norm_path] = sorted(folder_infos, key=lambda fi: fi.title)

            files = info["response"]["files"]
            file_infos = []
            for file in files:
                file_id = file["id"]
                title = file["title"]
                updated = parse_ts(file["updated"]).timestamp()
                size = int(file["pureContentLength"])
                view_url = file["viewUrl"]
                path = (*norm_path, title.strip().lower())
                file_info = FileInfo(file_id, title, updated, size, view_url)
                self._file_infos[path] = file_info
                file_infos.append(file_info)
            self._folder_files[norm_path] = sorted(file_infos, key=lambda fi: fi.title)

        if norm_path not in self._folder_infos:
            raise KeyError("No such folder: %s" % "/".join(norm_path))
示例#8
0
    def is_expired(self, key):
        if key:
            expire_in_seconds = self.context.config.get('RESULT_STORAGE_EXPIRATION_SECONDS', None)

            #Never expire
            if expire_in_seconds is None or expire_in_seconds == 0:
                return False

            timediff = datetime.now() - self.utc_to_local(parse_ts(key.last_modified))
            return timediff.seconds > expire_in_seconds
        else:
            #If our key is bad just say we're expired
            return True
示例#9
0
    def is_expired(self, key):
        if key:
            expire_in_seconds = self._get_config('EXPIRATION_SECONDS')

            # Never expire
            if expire_in_seconds is None or expire_in_seconds == 0:
                return False

            timediff = datetime.now() - self.utc_to_local(parse_ts(key.last_modified))
            return timediff.seconds > self._get_config('EXPIRATION_SECONDS')
        else:
            #If our key is bad just say we're expired
            return True
示例#10
0
    def is_expired(self, key):
        if key:
            expire_in_seconds = self.context.config.get(
                'STORAGE_EXPIRATION_SECONDS', None)

            if expire_in_seconds is None or expire_in_seconds == 0:
                return False

            timediff = (datetime.now() -
                        self.utc_to_local(parse_ts(key.last_modified)))
            return timediff.seconds > expire_in_seconds
        else:
            return True