コード例 #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
ファイル: views.py プロジェクト: exploratour/exploratour
    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),
        )
コード例 #3
0
 def get_media(val):
     path = os.path.join(config.BAMBOO_MEDIA_PATH, val)
     if not os.path.exists(path):
         path = guess_path_case(path)
     if not os.path.exists(path):
         print "Missing file:", path
     mtype = mimetype(path)
     referenced_media.append((os.path.join(config.BAMBOO_MEDIA_URL, val), path))
     return path, mtype
コード例 #4
0
    def thumbiconurl(self, public_path):
        def mimetypeurl(type):
            """Get the URL of an icon for a mimetype.

            """
            if type is None:
                iconname = 'unknown.png'
            else:
                iconname = safename_re.sub('_', type.lower()) + '.png'
                iconfile = os.path.join(config.staticdir, 'icons', 'thumbs', iconname)
                if not os.path.exists(iconfile):
                    iconname = safename_re.sub('_', type.split('/')[0].lower()) + '.png'
                    iconfile = os.path.join(config.staticdir, 'icons', 'thumbs', iconname)
                if not os.path.exists(iconfile):
                    iconname = 'unknown.png'
            return self.url('static', 'icons', 'thumbs', iconname)
        return mimetypeurl(mimetype(public_path))