Advertisement
Guest User

ListDir Controller for PushService Dreambox

a guest
Jan 26th, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.42 KB | None | 0 0
  1. #######################################################################
  2. #
  3. #    Push Service for Enigma-2
  4. #    Coded by betonme (c) 2012 <glaserfrank(at)gmail.com>
  5. #    Support: http://www.i-have-a-dreambox.com/wbb2/thread.php?threadid=167779
  6. #
  7. #    This program is free software; you can redistribute it and/or
  8. #    modify it under the terms of the GNU General Public License
  9. #    as published by the Free Software Foundation; either version 2
  10. #    of the License, or (at your option) any later version.
  11. #
  12. #    This program is distributed in the hope that it will be useful,
  13. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. #    GNU General Public License for more details.
  16. #
  17. #######################################################################
  18.  
  19. # Config
  20. from Components.config import ConfigYesNo, ConfigText, ConfigNumber, NoSave
  21.  
  22. # Plugin internal
  23. from Plugins.Extensions.PushService.__init__ import _
  24. from Plugins.Extensions.PushService.ControllerBase import ControllerBase
  25.  
  26. # Plugin specific
  27. import os
  28.  
  29.  
  30. # Constants
  31.  
  32. SUBJECT = _("List of Files")
  33.  
  34.  
  35.  
  36.  
  37. class ListDir(ControllerBase):
  38.  
  39.         ForceSingleInstance = True
  40.  
  41.         def __init__(self):
  42.                 # Is called on instance creation
  43.                 ControllerBase.__init__(self)
  44.                 self.movielist= []
  45.  
  46.                 # Default configuration
  47.                 self.setOption( 'path',     NoSave(ConfigText(   default = "/media/hdd/movie/", fixed_size = False )), _("Where to check") )
  48.         self.setOption( 'ext',     NoSave(ConfigText(   default = ".ts", fixed_size = False )), _("file extension") )
  49.  
  50.  
  51.         def run(self, callback, errback):
  52.                 # At the end a plugin has to call one of the functions: callback or errback
  53.                 # Callback should return with at least one of the parameter: Header, body (List of Files)
  54.                 # If empty or none is returned, nothing will be sent
  55.                 path = self.getValue('path')
  56.         ext = self.getValue('ext')                
  57.         movielist = []
  58.                 for file in os.listdir( path ):
  59.                         if file.endswith( ext ):
  60.                                 movielist.append(file)
  61.                 body = "The following files were found: \n" + "\n".join(movielist)
  62.                
  63.         if movielist:
  64.             callback( SUBJECT, body )
  65.         else:
  66.             callback()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement