Exemplo n.º 1
0
 def getTotalPages(self, *args):
     comicsFile = None
     if len(args) > 0:
         comicsFile = "/".join(args)
     if "comicsFile" in self.params:
         comicsFile = self.params["comicsFile"][0]
     cf = ComicsFile(os.path.join(self.comicsRoot, comicsFile))
     try:
         self.start_response("200 OK", [("Content-Type", "text/plain")])
         return [str(cf.getNumPages())]
     except:
         pass
Exemplo n.º 2
0
    def do_GET(self):
        """Serve a GET request."""

        self.send_response(200)

        if self.path != "/img":
            self.send_header("Content-type", "text/html")
            self.end_headers()
            retval = '<h1 style="color: red; text-align: center;">Hola, CGI</h1>'
            mf = StringIO(retval)
            self.copyfile(mf, self.wfile)
        else:
            cf = ComicsFile(os.path.join("contents", "lsh", "comics", "Legion CD 1", "0028-Adventure Comics 312.cbr"))
            ctype, data = cf.getImgTypeAndData(0, 0.5)
            self.send_header("Content-type", ctype)
            self.end_headers()
            mf = StringIO(data)
            self.copyfile(mf, self.wfile)

        return
Exemplo n.º 3
0
    def showTheThumb(self, *args):
        try:
            comicsFile = ""
            index = 0
            proportion = 0.2

            if len(args) > 0:
                index = int(args[0])
            if len(args) > 1:
                proportion = float(args[1])
            if "comicsFile" in self.params:
                comicsFile = self.params["comicsFile"][0]
            if "index" in self.params:
                index = int(self.params["index"][0])
            if "proportion" in self.params:
                sys.stderr.writelines([str(self.params["proportion"])])
                proportion = float(self.params["proportion"][0])

            cf = ComicsFile(os.path.join(self.comicsRoot, comicsFile))
            return cf.wsgiThumb(self.start_response, index, proportion)
        except:
            pass
Exemplo n.º 4
0
    def getContents(self):
        try:
            self.start_response("200 OK", [("Content-Type", "text/plain")])

            tmpli = os.path.split(self.comicsRoot)

            if not "folder" in self.params:
                folder = self.comicsRoot
                #               shownFolder = tmpli[len(tmpli) - 1]
                shownFolder = ""
            else:
                folder = os.path.join(self.comicsRoot, self.params["folder"][0])
                #               shownFolder = os.path.join(tmpli[len(tmpli) - 1], self.params['folder'][0])
                shownFolder = self.params["folder"][0]
            if not "page" in self.params:
                page = 1
            else:
                page = int(self.params["page"][0])
                if page < 1:
                    page = 1
            if not "pageLen" in self.params:
                pageLen = 5
            else:
                pageLen = int(self.params["pageLen"][0])

            res = os.walk(folder).next()
            contents = []

            if res[1]:
                res[1].sort()
                for f in res[1]:
                    contents.append({"itemName": f, "itemType": "folder"})
            if res[2]:
                res[2].sort()
                for f in res[2]:
                    if ComicsFile.isComicsFile(os.path.join(res[0], f)):
                        contents.append({"itemName": f, "itemType": "comics"})

            retval = {"folder": shownFolder}
            retval["pageLen"] = pageLen
            retval["totalPages"] = int(math.ceil((len(contents) * 1.0) / pageLen))
            if page > retval["totalPages"]:
                page = retval["totalPages"]
            retval["page"] = page
            start = (page - 1) * pageLen
            end = start + pageLen
            contents = contents[start:end]
            retval["contents"] = contents
            return [json.dumps(retval)]
        except:
            pass