Changeset a0bb213a2bf17582d50549a14fabeeca44ab24dc

Show
Ignore:
Timestamp:
12/30/07 00:27:01 (1 year ago)
Author:
William McBrine <wmcbrine@gmail.com>
git-committer:
William McBrine <wmcbrine@gmail.com> 1198996021 -0500
git-parent:

[22be2e4c19ddc2ad9e8edce0a31a274421a66c3d]

git-author:
William McBrine <wmcbrine@gmail.com> 1198996021 -0500
Message:

Unified item_count()

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugin.py

    r22be2e4 ra0bb213  
    6161    def item_count(self, handler, query, cname, files): 
    6262        """Return only the desired portion of the list, as specified by  
    63            ItemCount, AnchorItem and AnchorOffset 
     63           ItemCount, AnchorItem and AnchorOffset. 'files' is either a  
     64           list of strings, OR a list of objects with a 'name' attribute. 
    6465        """ 
    6566        totalFiles = len(files) 
     
    8081                anchor = os.path.normpath(anchor) 
    8182 
     83                if type(files[0]) == str: 
     84                    filenames = files 
     85                else: 
     86                    filenames = [x.name for x in files] 
    8287                try: 
    83                     index = files.index(anchor) 
     88                    index = filenames.index(anchor) 
    8489                except ValueError: 
    8590                    print 'Anchor not found:', anchor  # just use index = 0 
  • plugins/music/music.py

    r6c43706 ra0bb213  
    171171        handler.end_headers() 
    172172        handler.wfile.write(page) 
    173  
    174     def item_count(self, handler, query, cname, files): 
    175         """Return only the desired portion of the list, as specified by  
    176            ItemCount, AnchorItem and AnchorOffset 
    177         """ 
    178         totalFiles = len(files) 
    179         index = 0 
    180  
    181         if query.has_key('ItemCount'): 
    182             count = int(query['ItemCount'][0]) 
    183  
    184             if query.has_key('AnchorItem'): 
    185                 bs = '/TiVoConnect?Command=QueryContainer&Container=' 
    186                 local_base_path = self.get_local_base_path(handler, query) 
    187  
    188                 anchor = query['AnchorItem'][0] 
    189                 if anchor.startswith(bs): 
    190                     anchor = anchor.replace(bs, '/') 
    191                 anchor = unquote(anchor) 
    192                 anchor = anchor.replace(os.path.sep + cname, local_base_path) 
    193                 anchor = os.path.normpath(anchor) 
    194  
    195                 filenames = [x.name for x in files] 
    196                 try: 
    197                     index = filenames.index(anchor) 
    198                 except ValueError: 
    199                     print 'Anchor not found:', anchor  # just use index = 0 
    200  
    201                 if count > 0: 
    202                     index += 1 
    203  
    204                 if query.has_key('AnchorOffset'): 
    205                     index += int(query['AnchorOffset'][0]) 
    206  
    207                 #foward count 
    208                 if count > 0: 
    209                     files = files[index:index + count] 
    210                 #backwards count 
    211                 elif count < 0: 
    212                     if index + count < 0: 
    213                         count = -index 
    214                     files = files[index + count:index] 
    215                     index += count 
    216  
    217             else:  # No AnchorItem 
    218  
    219                 if count >= 0: 
    220                     files = files[:count] 
    221                 elif count < 0: 
    222                     index = count % len(files) 
    223                     files = files[count:] 
    224  
    225         return files, totalFiles, index 
    226173 
    227174    def get_files(self, handler, query, filterFunction=None): 
  • plugins/photo/photo.py

    r052b7c8 ra0bb213  
    305305        handler.wfile.write(page) 
    306306 
    307     def item_count(self, handler, query, cname, files): 
    308         """Return only the desired portion of the list, as specified by  
    309            ItemCount, AnchorItem and AnchorOffset 
    310         """ 
    311         totalFiles = len(files) 
    312         index = 0 
    313  
    314         if query.has_key('ItemCount'): 
    315             count = int(query['ItemCount'][0]) 
    316  
    317             if query.has_key('AnchorItem'): 
    318                 bs = '/TiVoConnect?Command=QueryContainer&Container=' 
    319                 local_base_path = self.get_local_base_path(handler, query) 
    320  
    321                 anchor = query['AnchorItem'][0] 
    322                 if anchor.startswith(bs): 
    323                     anchor = anchor.replace(bs, '/') 
    324                 anchor = unquote(anchor) 
    325                 anchor = anchor.replace(os.path.sep + cname, local_base_path) 
    326                 anchor = os.path.normpath(anchor) 
    327  
    328                 filenames = [x.name for x in files] 
    329                 try: 
    330                     index = filenames.index(anchor) 
    331                 except ValueError: 
    332                     pass  # anchor not found, just use index = 0 
    333  
    334                 if count > 0: 
    335                     index += 1 
    336  
    337                 if query.has_key('AnchorOffset'): 
    338                     index += int(query['AnchorOffset'][0]) 
    339  
    340                 #foward count 
    341                 if count > 0: 
    342                     files = files[index:index + count] 
    343                 #backwards count 
    344                 elif count < 0: 
    345                     if index + count < 0: 
    346                         count = -index 
    347                     files = files[index + count:index] 
    348                     index += count 
    349  
    350             else:  # No AnchorItem 
    351  
    352                 if count >= 0: 
    353                     files = files[:count] 
    354                 elif count < 0: 
    355                     index = count % len(files) 
    356                     files = files[count:] 
    357  
    358         return files, totalFiles, index 
    359  
    360307    def get_files(self, handler, query, filterFunction): 
    361308