Example #1
0
 def childForSegment(self, segment: str,
                     request: TwistedRequest) -> IResource:
     task = self.job.getTask(segment)
     if task is None:
         return NotFoundResource(
             f'Task "{segment}" does not exist in this job')
     run = task.getLatestRun()
     return TaskResource(self.resourceDB, self.path.child(segment),
                         self.user, run)
Example #2
0
 def childForSegment(self, segment: str,
                     request: TwistedRequest) -> IResource:
     jobId = f'{self.day}-{segment}'
     try:
         job = self.jobDB[jobId]
     except KeyError:
         return NotFoundResource(f'Job "{jobId}" does not exist')
     else:
         return JobResource(self.resourceDB, self.path.child(segment),
                            self.user, job)
Example #3
0
    def render_GET(self, request: TwistedRequest) -> object:
        # Convert path to Unicode.
        try:
            segments = [segment.decode() for segment in request.postpath]
        except UnicodeDecodeError:
            return ClientErrorResource('Path is not valid UTF-8')

        # Look up path in ZIP directory tree.
        tree = ZipTree.get(self.zipPath.path)
        try:
            node = tree.find(segments)
        except KeyError:
            return NotFoundResource('No ZIP entry matches path "%s"' %
                                    '/'.join(segments)).render(request)

        if isinstance(node, ZipTreeNode):
            # Path ends at a directory.
            return self.renderDirectory(request, tree.zipFile, node)
        else:
            # Path ends at a file.
            return self.renderFile(request, tree.zipFile, node)
Example #4
0
    def childForSegment(self, segment: str,
                        request: TwistedRequest) -> IResource:
        path = self.path.child(segment)
        dirPath = self.path.filePath
        for ext, plainClass in (('.gz', PlainGzipArtifact),
                                ('.zip', PlainZipArtifact)):
            # Serve the archive's contents.
            filePath = dirPath.child(segment + ext)
            if filePath.isfile():
                return self.reportForFile(filePath, path, request)
            # Serve the archive itself.
            if segment.endswith(ext):
                filePath = path.filePath
                if request.method == b'PUT' or filePath.isfile():
                    return plainClass(filePath)

        if request.method == b'PUT':
            return ClientErrorResource('Uploads must use gzip or ZIP format')
        else:
            return NotFoundResource(
                f'No artifact named "{segment}" exists for this task')
Example #5
0
    def getChildWithDefault(self, path: bytes, request: Request) -> IResource:
        if not path:
            return self

        try:
            segment = unquote_plus(path.decode(), errors='strict')
        except UnicodeError:
            return ClientErrorResource('Path is not valid')

        name, ext = splitext(segment)
        if not ext:
            fmt = DataFormat.AUTO
        elif ext == '.json':
            fmt = DataFormat.JSON
        else:
            return NotFoundResource('Currently only ".json" is supported')

        try:
            user = self._userDB[name]
        except KeyError:
            return NoUserResource(self._userDB, self._tokenDB, name)
        else:
            return UserResource(self._userDB, self._tokenDB,
                                UserData.fromUserAccount(user), fmt)
Example #6
0
 def getChild(self, path: bytes, request: TwistedRequest) -> IResource:
     name = request.prepath[-2].decode()
     return NotFoundResource(f'Artifact "{name}" cannot contain subitems')
Example #7
0
 def getChild(self, path: bytes, request: TwistedRequest) -> IResource:
     return NotFoundResource('Cannot access subitems from full archive')
Example #8
0
 def getChildWithDefault(self, path: bytes, request: Request) -> IResource:
     return NotFoundResource('Records do not support subpaths')