4b2b937036fa09c3550fb102035d5d895e2e2518
[enigma2.git] / lib / python / Plugins / Extensions / MediaScanner / plugin.py
1 from Plugins.Plugin import PluginDescriptor
2 from Components.Scanner import scanDevice
3
4 def execute(option):
5         print "execute", option
6         if option is None:
7                 return
8
9         (_, scanner, files, session) = option
10         scanner.open(files, session)
11
12 def mountpoint_choosen(option):
13         if option is None:
14                 return
15
16         from Screens.ChoiceBox import ChoiceBox
17
18         (description, mountpoint, session) = option
19         res = scanDevice(mountpoint)
20
21         list = [ (r.description, r, res[r], session) for r in res ]
22
23         if list == [ ]:
24                 print "nothing found"
25                 return
26
27         session.openWithCallback(execute, ChoiceBox, 
28                 title = "The following files were found...",
29                 list = list)
30
31 def scan(session):
32         from Screens.ChoiceBox import ChoiceBox
33
34         from Components.Harddisk import harddiskmanager
35
36         parts = [ (r.description, r.mountpoint, session) for r in harddiskmanager.getMountedPartitions(onlyhotplug = False)]
37         if len(parts):
38                 session.openWithCallback(mountpoint_choosen, ChoiceBox, title = _("Please Select Medium to be Scanned"), list = parts)
39
40 def main(session, **kwargs):
41         scan(session)
42
43 def menuEntry(*args):
44         mountpoint_choosen(args)
45
46 def menuHook(menuid):
47         if menuid != "mainmenu": 
48                 return [ ]
49
50         from Components.Harddisk import harddiskmanager
51         from Tools.BoundFunction import boundFunction
52         return [(_("Show files from %s") % r.description, boundFunction(menuEntry, r.description, r.mountpoint), "hotplug", None) for r in harddiskmanager.getMountedPartitions(onlyhotplug = True)]
53
54 def Plugins(**kwargs):
55         return [ PluginDescriptor(name="MediaScanner", description="Scan Files...", where = PluginDescriptor.WHERE_PLUGINMENU, fnc=main),
56                 PluginDescriptor(where = PluginDescriptor.WHERE_MENU, fnc=menuHook)]