added new mount option "hdd_replacement". This function links after succesfully mount...
authorFrank Nehls <domino@users.schwerkraft.elitedvb.net>
Wed, 6 May 2009 10:00:21 +0000 (10:00 +0000)
committerFrank Nehls <domino@users.schwerkraft.elitedvb.net>
Wed, 6 May 2009 10:00:21 +0000 (10:00 +0000)
networkbrowser/src/AutoMount.py
networkbrowser/src/MountEdit.py

index c7ed721..5d71f71 100755 (executable)
@@ -2,11 +2,12 @@
 # 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
 
@@ -47,12 +48,14 @@ class AutoMount():
                # 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")
@@ -64,12 +67,14 @@ class AutoMount():
                        # 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")
@@ -112,7 +117,7 @@ class AutoMount():
                        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("$", "\\$")
@@ -148,13 +153,15 @@ class AutoMount():
                                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:
@@ -163,6 +170,31 @@ class AutoMount():
                                        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:
@@ -194,6 +226,7 @@ class AutoMount():
                                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"]))
@@ -205,6 +238,7 @@ class AutoMount():
                                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"]))
@@ -520,4 +554,3 @@ class AutoMount_Unused:
                        self.MountConsole = None """
 
 iAutoMount = AutoMount()
-
index 7e14cdb..cc6c30e 100755 (executable)
@@ -6,7 +6,7 @@ from Screens.MessageBox import MessageBox
 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
@@ -36,7 +36,7 @@ class AutoMountEdit(Screen, ConfigListScreen):
                 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
@@ -96,6 +96,7 @@ class AutoMountEdit(Screen, ConfigListScreen):
                 self.optionsEntry = None
                 self.usernameEntry = None
                 self.passwordEntry = None
+                self.hdd_replacementEntry = None
 
                 self.sharetypelist = []
                 self.sharetypelist.append(("nfs", _("NFS share")))
@@ -141,6 +142,14 @@ class AutoMountEdit(Screen, ConfigListScreen):
                         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:
@@ -165,6 +174,7 @@ class AutoMountEdit(Screen, ConfigListScreen):
                 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 = []
@@ -178,6 +188,8 @@ class AutoMountEdit(Screen, ConfigListScreen):
                 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:
@@ -239,7 +251,7 @@ class AutoMountEdit(Screen, ConfigListScreen):
 
         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)
@@ -273,6 +285,7 @@ class AutoMountEdit(Screen, ConfigListScreen):
                         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)
@@ -296,7 +309,8 @@ class AutoMountEdit(Screen, ConfigListScreen):
 
         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)
@@ -306,6 +320,7 @@ class AutoMountEdit(Screen, ConfigListScreen):
                         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
@@ -326,4 +341,3 @@ class AutoMountEdit(Screen, ConfigListScreen):
                 if data is not None:
                         if data is True:
                                 self.close()
-