当前位置: 首页>>代码示例>>Python>>正文


Python Template.files方法代码示例

本文整理汇总了Python中Cheetah.Template.Template.files方法的典型用法代码示例。如果您正苦于以下问题:Python Template.files方法的具体用法?Python Template.files怎么用?Python Template.files使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cheetah.Template.Template的用法示例。


在下文中一共展示了Template.files方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: QueryContainer

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import files [as 别名]
    def QueryContainer(self, handler, query):

        # Reject a malformed request -- these attributes should only
        # appear in requests to send_file, but sometimes appear here
        badattrs = ('Rotation', 'Width', 'Height', 'PixelShape')
        for i in badattrs:
            if i in query:
                handler.send_error(404)
                return

        subcname = query['Container'][0]
        cname = subcname.split('/')[0]
        local_base_path = self.get_local_base_path(handler, query)
        if not handler.server.containers.has_key(cname) or \
           not self.get_local_path(handler, query):
            handler.send_error(404)
            return

        def ImageFileFilter(f):
            goodexts = ('.jpg', '.gif', '.png', '.bmp', '.tif', '.xbm',
                        '.xpm', '.pgm', '.pbm', '.ppm', '.pcx', '.tga',
                        '.fpx', '.ico', '.pcd', '.jpeg', '.tiff')
            return os.path.splitext(f)[1].lower() in goodexts

        def media_data(f):
            if f.name in self.media_data_cache:
                return self.media_data_cache[f.name]

            item = {}
            item['path'] = f.name
            item['part_path'] = f.name.replace(local_base_path, '', 1)
            item['name'] = os.path.split(f.name)[1]
            item['is_dir'] = f.isdir
            item['rotation'] = 0
            item['cdate'] = '%#x' % f.cdate
            item['mdate'] = '%#x' % f.mdate

            self.media_data_cache[f.name] = item
            return item

        t = Template(photo_template, filter=EncodeUnicode)
        t.name = subcname
        t.container = cname
        t.files, t.total, t.start = self.get_files(handler, query,
            ImageFileFilter)
        t.files = map(media_data, t.files)
        t.quote = quote
        t.escape = escape
        page = str(t)

        handler.send_response(200)
        handler.send_header('Content-Type', 'text/xml')
        handler.send_header('Content-Length', len(page))
        handler.send_header('Connection', 'close')
        handler.end_headers()
        handler.wfile.write(page)
开发者ID:armooo,项目名称:pytivo,代码行数:58,代码来源:photo.py

示例2: QueryContainer

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import files [as 别名]
    def QueryContainer(self, handler, query):

        # Reject a malformed request -- these attributes should only
        # appear in requests to send_file, but sometimes appear here
        badattrs = ('Rotation', 'Width', 'Height', 'PixelShape')
        for i in badattrs:
            if i in query:
                handler.send_error(404)
                return

        local_base_path = self.get_local_base_path(handler, query)
        if not self.get_local_path(handler, query):
            handler.send_error(404)
            return

        def ImageFileFilter(f):
            goodexts = ('.jpg', '.gif', '.png', '.bmp', '.tif', '.xbm',
                        '.xpm', '.pgm', '.pbm', '.ppm', '.pcx', '.tga',
                        '.fpx', '.ico', '.pcd', '.jpeg', '.tiff', '.nef')
            return os.path.splitext(f)[1].lower() in goodexts

        def media_data(f):
            if f.name in self.media_data_cache:
                return self.media_data_cache[f.name]

            item = {}
            item['path'] = f.name
            item['part_path'] = f.name.replace(local_base_path, '', 1)
            item['name'] = os.path.basename(f.name)
            item['is_dir'] = f.isdir
            item['rotation'] = 0
            item['cdate'] = '%#x' % f.cdate
            item['mdate'] = '%#x' % f.mdate

            self.media_data_cache[f.name] = item
            return item

        t = Template(PHOTO_TEMPLATE, filter=EncodeUnicode)
        t.name = query['Container'][0]
        t.container = handler.cname
        t.files, t.total, t.start = self.get_files(handler, query,
            ImageFileFilter)
        t.files = map(media_data, t.files)
        t.quote = quote
        t.escape = escape

        handler.send_xml(str(t))
开发者ID:WeekdayFiller,项目名称:pytivo,代码行数:49,代码来源:photo.py

示例3: QueryContainer

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import files [as 别名]

#.........这里部分代码省略.........
            #if track[0].isdigit:
            #    track = ' '.join(track.split(' ')[1:])

            #item['SongTitle'] = track
            #item['AlbumTitle'] = album
            #item['ArtistName'] = artist

            ext = os.path.splitext(f.name)[1].lower()
            fname = f.name

            try:
                # If the file is an mp3, let's load the EasyID3 interface
                if ext == '.mp3':
                    audioFile = MP3(fname, ID3=EasyID3)
                else:
                    # Otherwise, let mutagen figure it out
                    audioFile = mutagen.File(fname)

                if audioFile:
                    # Pull the length from the FileType, if present
                    if audioFile.info.length > 0:
                        item['Duration'] = int(audioFile.info.length * 1000)

                    # Grab our other tags, if present
                    def get_tag(tagname, d):
                        for tag in ([tagname] + TAGNAMES[tagname]):
                            try:
                                if tag in d:
                                    value = d[tag][0]
                                    if not isinstance(value, str):
                                        value = str(value)
                                    return value
                            except:
                                pass
                        return ''

                    artist = get_tag('artist', audioFile)
                    title = get_tag('title', audioFile)
                    if artist == 'Various Artists' and '/' in title:
                        artist, title = [x.strip() for x in title.split('/')]
                    item['ArtistName'] = artist
                    item['SongTitle'] = title
                    item['AlbumTitle'] = get_tag('album', audioFile)
                    item['AlbumYear'] = get_tag('date', audioFile)[:4]
                    item['MusicGenre'] = get_tag('genre', audioFile)
            except Exception as msg:
                logger.error(msg)

            ffmpeg_path = config.get_bin('ffmpeg')
            if 'Duration' not in item and ffmpeg_path:
                cmd = [ffmpeg_path, '-hide_banner', '-nostdin', '-i', fname]
                ffmpeg = subprocess.Popen(cmd, stderr=subprocess.PIPE,
                                               stdout=subprocess.PIPE)

                # wait 10 sec if ffmpeg is not back give up
                for i in range(200):
                    time.sleep(.05)
                    if not ffmpeg.poll() == None:
                        break

                if ffmpeg.poll() != None:
                    output = ffmpeg.stderr.read()
                    d = durre(output)
                    if d:
                        millisecs = ((int(d.group(1)) * 3600 +
                                      int(d.group(2)) * 60 +
                                      int(d.group(3))) * 1000 +
                                     int(d.group(4)) *
                                     (10 ** (3 - len(d.group(4)))))
                    else:
                        millisecs = 0
                    item['Duration'] = millisecs

            if 'Duration' in item and ffmpeg_path:
                item['params'] = 'Yes'

            self.media_data_cache[f.name] = item
            return item

        subcname = query['Container'][0]
        local_base_path = self.get_local_base_path(handler, query)

        if not self.get_local_path(handler, query):
            handler.send_error(404)
            return

        if os.path.splitext(subcname)[1].lower() in PLAYLISTS:
            t = Template(PLAYLIST_TEMPLATE)
            t.files, t.total, t.start = self.get_playlist(handler, query)
        else:
            t = Template(FOLDER_TEMPLATE)
            t.files, t.total, t.start = self.get_files(handler, query,
                                                       AudioFileFilter)
        t.files = list(map(media_data, t.files))
        t.container = handler.cname
        t.name = subcname
        t.quote = quote
        t.escape = escape

        handler.send_xml(str(t))
开发者ID:mlippert,项目名称:pytivo,代码行数:104,代码来源:music.py

示例4: Template

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import files [as 别名]
            if 'Duration' in item and ffmpeg_path:
                item['params'] = 'Yes'

            self.media_data_cache[f.name] = item
            return item

        subcname = query['Container'][0]
        local_base_path = self.get_local_base_path(handler, query)

        if not self.get_local_path(handler, query):
            handler.send_error(404)
            return

        if os.path.splitext(subcname)[1].lower() in PLAYLISTS:
            t = Template(PLAYLIST_TEMPLATE, filter=EncodeUnicode)
            t.files, t.total, t.start = self.get_playlist(handler, query)
        else:
            t = Template(FOLDER_TEMPLATE, filter=EncodeUnicode)
            t.files, t.total, t.start = self.get_files(handler, query,
                                                       AudioFileFilter)
        t.files = map(media_data, t.files)
        t.container = handler.cname
        t.name = subcname
        t.quote = quote
        t.escape = escape

        handler.send_xml(str(t))

    def QueryItem(self, handler, query):
        uq = urllib.unquote_plus
        splitpath = [x for x in uq(query['Url'][0]).split('/') if x]
开发者ID:akolster,项目名称:pytivo,代码行数:33,代码来源:music.py


注:本文中的Cheetah.Template.Template.files方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。