1 from Plugins.Plugin import PluginDescriptor
2 from Components.Scanner import scanDevice
3 from Screens.InfoBar import InfoBar
4 from os import access, F_OK, R_OK
7 print "execute", option
11 (_, scanner, files, session) = option
12 scanner.open(files, session)
14 def mountpoint_choosen(option):
18 from Screens.ChoiceBox import ChoiceBox
20 print "scanning", option
21 (description, mountpoint, session) = option
22 res = scanDevice(mountpoint)
24 list = [ (r.description, r, res[r], session) for r in res ]
27 from Screens.MessageBox import MessageBox
28 if access(mountpoint, F_OK|R_OK):
29 session.open(MessageBox, _("No displayable files on this medium found!"), MessageBox.TYPE_ERROR)
31 print "ignore", mountpoint, "because its not accessible"
34 session.openWithCallback(execute, ChoiceBox,
35 title = _("The following files were found..."),
39 from Screens.ChoiceBox import ChoiceBox
41 from Components.Harddisk import harddiskmanager
43 parts = [ (r.description, r.mountpoint, session) for r in harddiskmanager.getMountedPartitions(onlyhotplug = False)]
46 if not access(x[1], F_OK|R_OK):
48 session.openWithCallback(mountpoint_choosen, ChoiceBox, title = _("Please Select Medium to be Scanned"), list = parts)
50 def main(session, **kwargs):
54 mountpoint_choosen(args)
56 from Components.Harddisk import harddiskmanager
59 if menuid != "mainmenu":
62 from Tools.BoundFunction import boundFunction
63 return [(("%s (files)") % r.description, boundFunction(menuEntry, r.description, r.mountpoint), "hotplug_%s" % r.mountpoint, None) for r in harddiskmanager.getMountedPartitions(onlyhotplug = True)]
67 def partitionListChanged(action, device):
69 if InfoBar.instance.execing:
70 if action == 'add' and device.is_hotplug:
71 print "mountpoint", device.mountpoint
72 print "description", device.description
73 print "force_mounted", device.force_mounted
74 mountpoint_choosen((device.description, device.mountpoint, global_session))
76 print "main infobar is not execing... so we ignore hotplug event!"
78 print "hotplug event.. but no infobar"
80 def sessionstart(reason, session):
82 global_session = session
84 def autostart(reason, **kwargs):
87 harddiskmanager.on_partition_list_change.append(partitionListChanged)
89 harddiskmanager.on_partition_list_change.remove(partitionListChanged)
92 def Plugins(**kwargs):
94 PluginDescriptor(name="MediaScanner", description=_("Scan Files..."), where = PluginDescriptor.WHERE_PLUGINMENU, fnc=main),
95 # PluginDescriptor(where = PluginDescriptor.WHERE_MENU, fnc=menuHook),
96 PluginDescriptor(where = PluginDescriptor.WHERE_SESSIONSTART, fnc = sessionstart),
97 PluginDescriptor(where = PluginDescriptor.WHERE_AUTOSTART, fnc = autostart)