Package Subtitles :: Module Discoverer
[hide private]
[frames] | no frames]

Source Code for Module Subtitles.Discoverer

 1  #!/usr/bin/env python 
 2  # 
 3  #       discoverer.py 
 4  #        
 5  #       Copyright 2008 Joao Mesquita <jmesquita@gmail.com> 
 6  #        
 7  #       This program is free software; you can redistribute it and/or modify 
 8  #       it under the terms of the GNU General Public License as published by 
 9  #       the Free Software Foundation; either version 3 of the License, or 
10  #       (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  #       You should have received a copy of the GNU General Public License 
18  #       along with this program; if not, write to the Free Software 
19  #       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
20  #       MA 02110-1301, USA. 
21   
22  import os, glob 
23  from . import Formats 
24   
25  discover_funcs = [] 
26   
27  format_path = os.path.dirname(Formats.__file__) 
28  modules = glob.glob(os.path.join(format_path, '*.py')) 
29  for module in modules: 
30      module = __import__('Formats.' + os.path.basename(module)[:-3],  
31          globals(), locals(), ['discover'], 1) 
32      if hasattr(module, 'discover'): 
33          discover_funcs.append(module.discover) 
34   
35 -def discoverer(file):
36 """ 37 This procedure will negotiate and return the proper subtitle class to 38 handle the specific format. If it returns None, format is not yet 39 supported. 40 """ 41 42 for func in discover_funcs: 43 print "Testing this func: %s" % func 44 handle = func(file) 45 if handle is not None: 46 print "I have found a handle: %s" % handle 47 return handle(file) 48 else: 49 print '----'
50