# for localized messages
from __init__ import _
from re import compile as re_compile
-from os import path as os_path, mkdir, rmdir
+from os import path as os_path, symlink, listdir, unlink, readlink, remove
from enigma import eTimer
from Components.Console import Console
from Components.Harddisk import harddiskmanager #global harddiskmanager
+from Tools.Directories import isMount, removeDir, createDir
from xml.etree.cElementTree import parse as cet_parse
# Read out NFS Mounts
for nfs in tree.findall("nfs"):
for mount in nfs.findall("mount"):
- data = { 'isMounted': False, 'active': False, 'ip': False, 'sharename': False, 'sharedir': False, 'username': False, 'password': False, 'mounttype' : False, 'options' : False }
+ data = { 'isMounted': False, 'active': False, 'ip': False, 'sharename': False, 'sharedir': False, 'username': False, \
+ 'password': False, 'mounttype' : False, 'options' : False, 'hdd_replacement' : False }
try:
data['mounttype'] = 'nfs'.encode("UTF-8")
data['active'] = getValue(mount.findall("active"), False).encode("UTF-8")
if data["active"] == 'True' or data["active"] == True:
self.activeMountsCounter +=1
+ data['hdd_replacement'] = getValue(mount.findall("hdd_replacement"), "False").encode("UTF-8")
data['ip'] = getValue(mount.findall("ip"), "192.168.0.0").encode("UTF-8")
data['sharedir'] = getValue(mount.findall("sharedir"), "/exports/").encode("UTF-8")
data['sharename'] = getValue(mount.findall("sharename"), "MEDIA").encode("UTF-8")
# Read out CIFS Mounts
for nfs in tree.findall("cifs"):
for mount in nfs.findall("mount"):
- data = { 'isMounted': False, 'active': False, 'ip': False, 'sharename': False, 'sharedir': False, 'username': False, 'password': False, 'mounttype' : False, 'options' : False }
+ data = { 'isMounted': False, 'active': False, 'ip': False, 'sharename': False, 'sharedir': False, 'username': False, \
+ 'password': False, 'mounttype' : False, 'options' : False, 'hdd_replacement' : False }
try:
data['mounttype'] = 'cifs'.encode("UTF-8")
data['active'] = getValue(mount.findall("active"), False).encode("UTF-8")
if data["active"] == 'True' or data["active"] == True:
self.activeMountsCounter +=1
+ data['hdd_replacement'] = getValue(mount.findall("hdd_replacement"), "False").encode("UTF-8")
data['ip'] = getValue(mount.findall("ip"), "192.168.0.0").encode("UTF-8")
data['sharedir'] = getValue(mount.findall("sharedir"), "/exports/").encode("UTF-8")
data['sharename'] = getValue(mount.findall("sharename"), "MEDIA").encode("UTF-8")
if data['active'] == 'True' or data['active'] is True:
path = '/media/net/'+ data['sharename']
if os_path.exists(path) is False:
- mkdir(path)
+ createDir(path)
tmpsharedir = data['sharedir'].replace(" ", "\\ ")
if tmpsharedir[-1:] == "$":
tmpdir = tmpsharedir.replace("$", "\\$")
if self.automounts.has_key(data['sharename']):
self.automounts[data['sharename']]['isMounted'] = True
desc = data['sharename']
+ if self.automounts[data['sharename']]['hdd_replacement'] == 'True': #hdd replacement hack
+ self.makeHDDlink(path)
harddiskmanager.addMountedPartition(path, desc)
else:
if self.automounts.has_key(data['sharename']):
self.automounts[data['sharename']]['isMounted'] = False
if os_path.exists(path):
if not os_path.ismount(path):
- rmdir(path)
+ removeDir(path)
harddiskmanager.removeMountedPartition(path)
if self.MountConsole:
self.callback = callback
self.timer.startLongTimer(10)
+ def makeHDDlink(self, path):
+ hdd_dir = '/media/hdd'
+ print "[AutoMount.py] symlink %s %s" % (path, hdd_dir)
+ if os_path.islink(hdd_dir):
+ if readlink(hdd_dir) != path:
+ remove(hdd_dir)
+ symlink(path, hdd_dir)
+ elif isMount(hdd_dir) is False:
+ if os_path.isdir(hdd_dir):
+ self.rm_rf(hdd_dir)
+ try:
+ symlink(path, hdd_dir)
+ except OSError:
+ print "[AutoMount.py] add symlink fails!"
+ if os_path.exists(hdd_dir + '/movie') is False:
+ createDir(hdd_dir + '/movie')
+
+ def rm_rf(self, d): # only for removing the ipkg stuff from /media/hdd subdirs
+ for path in (os_path.join(d,f) for f in listdir(d)):
+ if os_path.isdir(path):
+ self.rm_rf(path)
+ else:
+ unlink(path)
+ removeDir(d)
+
def mountTimeout(self):
self.timer.stop()
if self.MountConsole:
list.append('<nfs>\n')
list.append(' <mount>\n')
list.append(''.join([" <active>", str(sharedata['active']), "</active>\n"]))
+ list.append(''.join([" <hdd_replacement>", str(sharedata['hdd_replacement']), "</hdd_replacement>\n"]))
list.append(''.join([" <ip>", sharedata['ip'], "</ip>\n"]))
list.append(''.join([" <sharename>", sharedata['sharename'], "</sharename>\n"]))
list.append(''.join([" <sharedir>", sharedata['sharedir'], "</sharedir>\n"]))
list.append('<cifs>\n')
list.append(' <mount>\n')
list.append(''.join([" <active>", str(sharedata['active']), "</active>\n"]))
+ list.append(''.join([" <hdd_replacement>", str(sharedata['hdd_replacement']), "</hdd_replacement>\n"]))
list.append(''.join([" <ip>", sharedata['ip'], "</ip>\n"]))
list.append(''.join([" <sharename>", sharedata['sharename'], "</sharename>\n"]))
list.append(''.join([" <sharedir>", sharedata['sharedir'], "</sharedir>\n"]))
self.MountConsole = None """
iAutoMount = AutoMount()
-
from Screens.VirtualKeyBoard import VirtualKeyBoard
from Components.ActionMap import ActionMap
from Components.Button import Button
-from Components.config import config, ConfigIP, NoSave, ConfigText, ConfigEnableDisable, ConfigPassword, ConfigSelection, getConfigListEntry
+from Components.config import config, ConfigIP, NoSave, ConfigText, ConfigEnableDisable, ConfigPassword, ConfigSelection, getConfigListEntry, ConfigYesNo
from Components.ConfigList import ConfigListScreen
from Components.Label import Label
from Components.Pixmap import Pixmap
self.mountinfo = mountinfo
if self.mountinfo is None:
#Initialize blank mount enty
- self.mountinfo = { 'isMounted': False, 'active': False, 'ip': False, 'sharename': False, 'sharedir': False, 'username': False, 'password': False, 'mounttype' : False, 'options' : False }
+ self.mountinfo = { 'isMounted': False, 'active': False, 'ip': False, 'sharename': False, 'sharedir': False, 'username': False, 'password': False, 'mounttype' : False, 'options' : False, 'hdd_replacement' : False }
self.applyConfigRef = None
self.updateConfigRef = None
self.optionsEntry = None
self.usernameEntry = None
self.passwordEntry = None
+ self.hdd_replacementEntry = None
self.sharetypelist = []
self.sharetypelist.append(("nfs", _("NFS share")))
password = self.mountinfo['password']
else:
password = ""
+ if self.mountinfo.has_key('hdd_replacement'):
+ hdd_replacement = self.mountinfo['hdd_replacement']
+ if hdd_replacement == 'True':
+ hdd_replacement = True
+ if hdd_replacement == 'False':
+ hdd_replacement = False
+ else:
+ hdd_replacement = False
if sharename is False:
sharename = "Sharename"
if sharedir is False:
self.usernameConfigEntry = NoSave(ConfigText(default = username, visible_width = 50, fixed_size = False))
self.passwordConfigEntry = NoSave(ConfigPassword(default = password, visible_width = 50, fixed_size = False))
self.mounttypeConfigEntry = NoSave(ConfigSelection(self.sharetypelist, default = mounttype ))
+ self.hdd_replacementConfigEntry = NoSave(ConfigYesNo(default = hdd_replacement))
def createSetup(self):
self.list = []
self.list.append(self.ipEntry)
self.sharedirEntry = getConfigListEntry(_("Server share"), self.sharedirConfigEntry)
self.list.append(self.sharedirEntry)
+ self.hdd_replacementEntry = getConfigListEntry(_("use as HDD replacement"), self.hdd_replacementConfigEntry)
+ self.list.append(self.hdd_replacementEntry)
if self.mounttypeConfigEntry.value == "cifs":
self.optionsConfigEntry = NoSave(ConfigText(default = "rw", visible_width = 50, fixed_size = False))
else:
def selectionChanged(self):
current = self["config"].getCurrent()
- if current == self.activeEntry or current == self.ipEntry or current == self.mounttypeEntry:
+ if current == self.activeEntry or current == self.ipEntry or current == self.mounttypeEntry or current == self.hdd_replacementEntry:
self["ButtonGreen"].hide()
self["VKeyIcon"].hide()
self["VirtualKB"].setEnabled(False)
iAutoMount.setMountsAttribute(self.sharenameConfigEntry.value, "options", self.optionsConfigEntry.value)
iAutoMount.setMountsAttribute(self.sharenameConfigEntry.value, "username", self.usernameConfigEntry.value)
iAutoMount.setMountsAttribute(self.sharenameConfigEntry.value, "password", self.passwordConfigEntry.value)
+ iAutoMount.setMountsAttribute(self.sharenameConfigEntry.value, "hdd_replacement", self.hdd_replacementConfigEntry.value)
self.updateConfigRef = None
self.updateConfigRef = self.session.openWithCallback(self.updateConfigfinishedCB, MessageBox, _("Please wait while updating your network mount..."), type = MessageBox.TYPE_INFO, enable_input = False)
def applyConfig(self, ret = False):
if (ret == True):
- data = { 'isMounted': False, 'active': False, 'ip': False, 'sharename': False, 'sharedir': False, 'username': False, 'password': False, 'mounttype' : False, 'options' : False }
+ data = { 'isMounted': False, 'active': False, 'ip': False, 'sharename': False, 'sharedir': False, \
+ 'username': False, 'password': False, 'mounttype' : False, 'options' : False, 'hdd_replacement' : False }
data['active'] = self.activeConfigEntry.value
data['ip'] = self.ipConfigEntry.getText()
data['sharename'] = re_sub("\W", "", self.sharenameConfigEntry.value)
data['mounttype'] = self.mounttypeConfigEntry.value
data['username'] = self.usernameConfigEntry.value
data['password'] = self.passwordConfigEntry.value
+ data['hdd_replacement'] = self.hdd_replacementConfigEntry.value
self.applyConfigRef = None
self.applyConfigRef = self.session.openWithCallback(self.applyConfigfinishedCB, MessageBox, _("Please wait for activation of your network mount..."), type = MessageBox.TYPE_INFO, enable_input = False)
iAutoMount.automounts[self.sharenameConfigEntry.value] = data
if data is not None:
if data is True:
self.close()
-