예제 #1
0
    def get_file_info(self, public_path):
        path = media_mapper._map_path(public_path)
        if path is None:
            return None

        filename = os.path.basename(public_path)
        mtype = mimetype(filename)

        type = thumbtype(path)
        summary = None
        if type == 'text':
            fd = open(path)
            try:
                summary = fd.read(100) + '...'
            except IOError:
                pass

        return dict(name=filename,
                    mimetype=mtype,
                    type=type,
                    thumburl=None, # unused
                    src=public_path,
                    summary=summary,
                    url=self.url("media", path=public_path),
                    size=os.path.getsize(path),
                    mtime=isotime(os.path.getmtime(path)),
                    hidden=_local_is_hidden(path),
                )
예제 #2
0
    def get_file_info(self, public_path):
        path = self._map_path(public_path)
        if path is None:
            raise cherrypy.HTTPError(404)

        filename = os.path.basename(public_path)
        mtype = mimetype(filename)

        type = thumbtype(path)
        turl = None
        summary = None
        if type == "icon":
            turl = mimetypeurl(mtype)
        elif type == "text":
            turl = mimetypeurl(mtype)
            fd = open(path)
            try:
                summary = fd.read(100) + "..."
            except IOError:
                pass
        else:
            turl = url("thumbnail", path=public_path)

        return dict(
            name=filename,
            mimetype=mtype,
            type=type,
            thumburl=turl,
            src=public_path,
            summary=summary,
            url=url("media", path=public_path),
            size=os.path.getsize(path),
            mtime=isotime(os.path.getmtime(path)),
            hidden=_local_is_hidden(path),
        )