1 from Plugins.Plugin import PluginDescriptor
3 from Screens.Screen import Screen
4 from Components.ActionMap import ActionMap
5 from Components.Label import Label
6 from Components.Sources.StaticText import StaticText
8 from Screens.MessageBox import MessageBox
10 from Components.PluginComponent import plugins
12 from Components.Pixmap import Pixmap
13 from Components.Console import Console
14 from Components.FileList import FileList
16 from Components.ConfigList import ConfigListScreen
17 from Components.config import config, getConfigListEntry, ConfigSubsection, ConfigYesNo, ConfigText, ConfigDirectory, ConfigSelection
26 "mountpoint":"/media/net/",
29 config.plugins.netdrivesetup = ConfigSubsection()
30 config.plugins.netdrivesetup.type = ConfigSelection(default=_default["type"], choices=[("ftp", _("FTP"))])
31 config.plugins.netdrivesetup.server = ConfigText(default=_default["server"], visible_width=60, fixed_size=False)
32 config.plugins.netdrivesetup.userid = ConfigText(default=_default["userid"], visible_width=60, fixed_size=False)
33 config.plugins.netdrivesetup.passwd = ConfigText(default=_default["passwd"], visible_width=60, fixed_size=False)
34 config.plugins.netdrivesetup.mountpoint = ConfigDirectory(default=_default["mountpoint"])
35 config.plugins.netdrivesetup.startup = ConfigYesNo(default=_default["startup"])
43 class NetDrivebrowser(Screen):
45 <screen name="NetDrivebrowser" position="center,120" size="600,390" title="NetDrive Setup > Mount Point">
46 <ePixmap pixmap="skin_default/buttons/red.png" position="5,0" size="140,40" alphatest="on" />
47 <ePixmap pixmap="skin_default/buttons/green.png" position="155,0" size="140,40" alphatest="on" />
48 <ePixmap pixmap="skin_default/buttons/yellow.png" position="305,0" size="140,40" alphatest="on" />
49 <ePixmap pixmap="skin_default/buttons/blue.png" position="455,0" size="140,40" alphatest="on" />
51 <widget source="key_red" render="Label" position="5,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" foregroundColor="#ffffff" transparent="1" />
52 <widget source="key_green" render="Label" position="155,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" foregroundColor="#ffffff" transparent="1" />
53 <widget source="key_yellow" render="Label" position="305,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" foregroundColor="#ffffff" transparent="1" />
54 <widget source="key_blue" render="Label" position="455,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#18188b" foregroundColor="#ffffff" transparent="1" />
56 <widget source="status" render="Label" position="0,40" zPosition="1" size="600,40" font="Regular;18" halign="center" valign="center" />
57 <widget name="filelist" position="0,80" size="600,310" scrollbarMode="showOnDemand" />
60 def __init__(self, session):
61 self.session = session
63 Screen.__init__(self, session)
65 self["actions"] = ActionMap(["OkCancelActions", "ShortcutActions", "WizardActions", "ColorActions", ], {
66 "red" : self.OnKeyRed,
67 "green" : self.OnKeyGreen,
69 "cancel": self.OnKeyCancel,
71 "down" : self.OnKeyDown,
72 "left" : self.OnKeyLeft,
73 "right" : self.OnKeyRight,
76 inhibitdirs = ["/bin", "/boot", "/dev", "/etc", "/lib", "/proc", "/sbin", "/sys", "/usr", "/var"]
77 self["filelist"] = FileList("/", showDirectories=True, showFiles=False, inhibitMounts=[], inhibitDirs=inhibitdirs)
78 self["status"] = StaticText(_(" "))
80 self["key_red"] = StaticText(_("Close"))
81 self["key_green"] = StaticText(_("Select"))
82 self["key_yellow"] = StaticText(_(" "))
83 self["key_blue"] = StaticText(_(" "))
87 def UpdateStatus(self):
88 current = self["filelist"].getSelection()[0]
89 self["status"].setText(current)
95 self.close(self["status"].getText())
98 if not self["filelist"].canDescent():
100 self["filelist"].descent()
103 def OnKeyCancel(self):
107 self["filelist"].down()
111 self["filelist"].up()
115 self["filelist"].pageUp()
118 def OnKeyRight(self):
119 self["filelist"].pageDown()
122 class NetDriveSetup(ConfigListScreen, Screen):
124 <screen name="NetDriveSetup" position="center,120" size="600,390" title="Network Drive Setup">
125 <ePixmap pixmap="skin_default/buttons/red.png" position="5,0" size="140,40" alphatest="on" />
126 <ePixmap pixmap="skin_default/buttons/green.png" position="155,0" size="140,40" alphatest="on" />
127 <ePixmap pixmap="skin_default/buttons/yellow.png" position="305,0" size="140,40" alphatest="on" />
128 <ePixmap pixmap="skin_default/buttons/blue.png" position="455,0" size="140,40" alphatest="on" />
130 <widget source="key_red" render="Label" position="5,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" foregroundColor="#ffffff" transparent="1" />
131 <widget source="key_green" render="Label" position="155,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" foregroundColor="#ffffff" transparent="1" />
132 <widget source="key_yellow" render="Label" position="305,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" foregroundColor="#ffffff" transparent="1" />
133 <widget source="key_blue" render="Label" position="455,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#18188b" foregroundColor="#ffffff" transparent="1" />
135 <widget name="config" position="5,70" size="590,250" scrollbarMode="showOnDemand" />
136 <widget name="introduction" position="5,335" size="590,60" font="Regular;18" halign="center" />
137 <widget name="VKeyIcon" pixmap="skin_default/buttons/key_text.png" position="565,365" zPosition="10" size="35,25" transparent="1" alphatest="on" />
140 def __init__(self, session):
142 self.session = session
143 Screen.__init__(self, session)
144 ConfigListScreen.__init__(self, self.configlist)
146 self["actions"] = ActionMap(["OkCancelActions", "ColorActions", "WizardActions",], {
147 "ok" : self.OnKeyOK2,
148 "cancel": self.OnKeyCancel,
149 "green" : self.OnKeyGreen,
150 "red" : self.OnKeyRed,
151 "yellow": self.OnKeyYellow,
152 "blue" : self.OnKeyBlue,
155 self["VirtualKB"] = ActionMap(["VirtualKeyboardActions" ], {
156 "showVirtualKeyboard": self.KeyText,
159 self["VKeyIcon"] = Pixmap()
160 self["key_red"] = StaticText(_("Close"))
161 self["key_green"] = StaticText(_("Mount"))
162 self["key_yellow"] = StaticText(_("Default"))
163 self["key_blue"] = StaticText(_("Save"))
164 self["introduction"] = Label(" ")
167 "type" :config.plugins.netdrivesetup.type.value,
168 "server":config.plugins.netdrivesetup.server.value,
169 "userid":config.plugins.netdrivesetup.userid.value,
170 "passwd":config.plugins.netdrivesetup.passwd.value,
171 "mountpoint":config.plugins.netdrivesetup.mountpoint.value,
172 "startup":config.plugins.netdrivesetup.startup.value,
174 self.console = Console()
175 self.configEntryMountPoint = None
177 self.MakeConfigList()
178 self.onLayoutFinish.append(self.LayoutFinished)
181 def IsMounted(self=None):
182 local = config.plugins.netdrivesetup.mountpoint.value
183 if local[len(local)-1] == '/':
185 mounts = file('/proc/mounts').read()
186 for mountpoint in mounts.splitlines():
187 if mountpoint.find('curlftpfs') >= 0 and mountpoint.find(local) >= 0:
188 print "[NetDriveSetup] Already mounted"
190 print "[NetDriveSetup] No mounted point"
194 def Umount(self=None):
195 command = "umount %s" % (config.plugins.netdrivesetup.mountpoint.value)
196 ret = NetDriveSetup.Execute(command, self)
199 def Execute(command, owner=None):
200 print "[NetDriveSetup] Excute :", command
201 def ConsoleFinishCB(result, retval, extra_args=None):
204 if not isempty(result):
205 owner.UpdateInfo(result)
207 owner.LayoutFinished()
212 owner.console.ePopen(command, ConsoleFinishCB)
215 def RunCurlFTPFS(self=None):
216 if (isempty(config.plugins.netdrivesetup.server.value) or
217 isempty(config.plugins.netdrivesetup.userid.value) or
218 isempty(config.plugins.netdrivesetup.passwd.value) or
219 isempty(config.plugins.netdrivesetup.mountpoint.value)):
220 print "[NetDriveSetup] Option Empty..\n SVR [%(server)s], MP [%(mountpoint)s], ID [%(userid)s], PWD [%(passwd)s]" % {
221 "server":config.plugins.netdrivesetup.server.value,
222 "userid":config.plugins.netdrivesetup.userid.value,
223 "passwd":config.plugins.netdrivesetup.passwd.value,
224 "mountpoint":config.plugins.netdrivesetup.mountpoint.value
228 if(NetDriveSetup.IsMounted()):
229 NetDriveSetup.Umount()
231 command = "modprobe fuse && curlftpfs %(server)s %(mountpoint)s -o user=%(userid)s:%(passwd)s,allow_other" % {
232 "server":config.plugins.netdrivesetup.server.value,
233 "userid":config.plugins.netdrivesetup.userid.value,
234 "passwd":config.plugins.netdrivesetup.passwd.value,
235 "mountpoint":config.plugins.netdrivesetup.mountpoint.value
237 NetDriveSetup.Execute(command, self)
239 def LayoutFinished(self):
240 if(NetDriveSetup.IsMounted()):
241 self.SetGreenButtonText("Umount")
242 else: self.SetGreenButtonText("Mount")
245 def SetGreenButtonText(self, data):
246 self["key_green"].setText(data)
248 def UpdateInfo(self, data=None):
250 self["introduction"].setText(data)
253 local = config.plugins.netdrivesetup.mountpoint.value
254 if local[len(local)-1] == '/':
256 mounts = file('/proc/mounts').read()
257 for mountpoint in mounts.splitlines():
258 if mountpoint.find('curlftpfs') >= 0 and mountpoint.find(local) >= 0:
260 self["introduction"].setText(info)
262 def MakeConfigList(self):
263 self.UpdateConfigList()
265 def UpdateConfigList(self):
267 self.configEntryMountPoint = getConfigListEntry(_("Mount Point"), config.plugins.netdrivesetup.mountpoint)
269 self.configlist.append(getConfigListEntry(_("Server"), config.plugins.netdrivesetup.server))
270 self.configlist.append(getConfigListEntry(_("User ID"), config.plugins.netdrivesetup.userid))
271 self.configlist.append(getConfigListEntry(_("Password"), config.plugins.netdrivesetup.passwd))
272 self.configlist.append(self.configEntryMountPoint)
273 self.configlist.append(getConfigListEntry(_("Enable mount automatically while start"), config.plugins.netdrivesetup.startup))
274 self["config"].list = self.configlist
275 self["config"].l.setList(self.configlist)
278 config.plugins.netdrivesetup.type.save()
279 config.plugins.netdrivesetup.server.save()
280 config.plugins.netdrivesetup.userid.save()
281 config.plugins.netdrivesetup.passwd.save()
282 config.plugins.netdrivesetup.mountpoint.save()
283 config.plugins.netdrivesetup.startup.save()
284 config.plugins.netdrivesetup.save()
285 config.plugins.save()
289 print "[NetDriveSetup] Restore default setting..."
290 config.plugins.netdrivesetup.type.value = self.backup["type"]
291 config.plugins.netdrivesetup.server.value = self.backup["server"]
292 config.plugins.netdrivesetup.userid.value = self.backup["userid"]
293 config.plugins.netdrivesetup.passwd.value = self.backup["passwd"]
294 config.plugins.netdrivesetup.mountpoint.value = self.backup["mountpoint"]
295 config.plugins.netdrivesetup.startup.value = self.backup["startup"]
297 def NetDrivebrowserCB(self, data):
298 if data is None: return
299 if isempty(data): data = "/"
300 config.plugins.netdrivesetup.mountpoint.value = data
302 def OnKeyGreen(self):
304 self["introduction"].setText("Plesae, wait..")
305 if self["key_green"].getText() == "Mount":
306 NetDriveSetup.RunCurlFTPFS(self)
307 else: NetDriveSetup.Umount(self)
309 def OnKeyCancel(self):
321 if self["config"].getCurrent() != self.configEntryMountPoint:
323 self.session.openWithCallback(self.NetDrivebrowserCB, NetDrivebrowser)
325 def OnKeyYellow(self):
326 print "[NetDriveSetup] Setting default values.."
327 config.plugins.netdrivesetup.type.value = _default["type"]
328 config.plugins.netdrivesetup.server.value = _default["server"]
329 config.plugins.netdrivesetup.userid.value = _default["userid"]
330 config.plugins.netdrivesetup.passwd.value = _default["passwd"]
331 config.plugins.netdrivesetup.mountpoint.value = _default["mountpoint"]
332 config.plugins.netdrivesetup.startup.value = _default["startup"]
333 self.UpdateConfigList()
335 def SessionStartMain(session, **kwargs):
336 if not config.plugins.netdrivesetup.startup.value:
338 NetDriveSetup.RunCurlFTPFS()
340 def PluginMain(session, **kwargs):
341 session.open(NetDriveSetup)
343 def MenuSelected(selected, **kwargs):
344 if selected == "system":
345 return [(_("NetDrive Setup"), PluginMain, "netdrivesetup", 80)]
348 def Plugins(**kwargs):
350 l.append(PluginDescriptor(name=_("NetDrive Setup"), description="Mount a FTP server", where=PluginDescriptor.WHERE_PLUGINMENU, fnc=PluginMain))
351 l.append(PluginDescriptor(where=PluginDescriptor.WHERE_MENU, fnc=MenuSelected))
352 l.append(PluginDescriptor(where=PluginDescriptor.WHERE_SESSIONSTART, fnc=SessionStartMain))