whitespace cleanup,
[enigma2-plugins.git] / networkbrowser / src / AutoMount.py
1 # -*- coding: utf-8 -*-\r
2 # for localized messages\r
3 from __init__ import _\r
4 from re import compile as re_compile\r
5 from os import path as os_path, mkdir, rmdir\r
6 \r
7 from enigma import eTimer\r
8 from Components.Console import Console\r
9 from Components.Harddisk import harddiskmanager #global harddiskmanager\r
10 \r
11 from xml.etree.cElementTree import parse as cet_parse\r
12 \r
13 XML_FSTAB = "/etc/enigma2/automounts.xml"\r
14 \r
15 class AutoMount():\r
16         """Manages Mounts declared in a XML-Document."""\r
17         def __init__(self):\r
18                 self.automounts = {}\r
19                 self.restartConsole = Console()\r
20                 self.MountConsole = Console()\r
21                 self.removeConsole = Console()\r
22                 self.activeMountsCounter = 0\r
23                 # Initialize Timer\r
24                 self.callback = None\r
25                 self.timer = eTimer()\r
26                 self.timer.callback.append(self.mountTimeout)\r
27 \r
28                 self.getAutoMountPoints()\r
29 \r
30         def getAutoMountPoints(self, callback = None):\r
31                 # Initialize mounts to empty list\r
32                 automounts = []\r
33                 self.automounts = {}\r
34                 self.activeMountsCounter = 0\r
35 \r
36                 if not os_path.exists(XML_FSTAB):\r
37                         return\r
38                 tree = cet_parse(XML_FSTAB).getroot()\r
39 \r
40                 def getValue(definitions, default):\r
41                         # Initialize Output\r
42                         ret = ""\r
43                         # How many definitions are present\r
44                         Len = len(definitions)\r
45                         return Len > 0 and definitions[Len-1].text or default\r
46                 # Config is stored in "mountmanager" element\r
47                 # Read out NFS Mounts\r
48                 for nfs in tree.findall("nfs"):\r
49                         for mount in nfs.findall("mount"):\r
50                                 data = { 'isMounted': False, 'active': False, 'ip': False, 'sharename': False, 'sharedir': False, 'username': False, 'password': False, 'mounttype' : False, 'options' : False }\r
51                                 try:\r
52                                         data['mounttype'] = 'nfs'.encode("UTF-8")\r
53                                         data['active'] = getValue(mount.findall("active"), False).encode("UTF-8")\r
54                                         if data["active"] == 'True' or data["active"] == True:\r
55                                                 self.activeMountsCounter +=1\r
56                                         data['ip'] = getValue(mount.findall("ip"), "192.168.0.0").encode("UTF-8")\r
57                                         data['sharedir'] = getValue(mount.findall("sharedir"), "/exports/").encode("UTF-8")\r
58                                         data['sharename'] = getValue(mount.findall("sharename"), "MEDIA").encode("UTF-8")\r
59                                         data['options'] = getValue(mount.findall("options"), "rw,nolock").encode("UTF-8")\r
60                                         print "NFSMOUNT",data\r
61                                         self.automounts[data['sharename']] = data\r
62                                 except Exception, e:\r
63                                         print "[MountManager] Error reading Mounts:", e\r
64                         # Read out CIFS Mounts\r
65                 for nfs in tree.findall("cifs"):\r
66                         for mount in nfs.findall("mount"):\r
67                                 data = { 'isMounted': False, 'active': False, 'ip': False, 'sharename': False, 'sharedir': False, 'username': False, 'password': False, 'mounttype' : False, 'options' : False }\r
68                                 try:\r
69                                         data['mounttype'] = 'cifs'.encode("UTF-8")\r
70                                         data['active'] = getValue(mount.findall("active"), False).encode("UTF-8")\r
71                                         if data["active"] == 'True' or data["active"] == True:\r
72                                                 self.activeMountsCounter +=1\r
73                                         data['ip'] = getValue(mount.findall("ip"), "192.168.0.0").encode("UTF-8")\r
74                                         data['sharedir'] = getValue(mount.findall("sharedir"), "/exports/").encode("UTF-8")\r
75                                         data['sharename'] = getValue(mount.findall("sharename"), "MEDIA").encode("UTF-8")\r
76                                         data['options'] = getValue(mount.findall("options"), "rw,nolock").encode("UTF-8")\r
77                                         data['username'] = getValue(mount.findall("username"), "guest").encode("UTF-8")\r
78                                         data['password'] = getValue(mount.findall("password"), "").encode("UTF-8")\r
79                                         print "CIFSMOUNT",data\r
80                                         self.automounts[data['sharename']] = data\r
81                                 except Exception, e:\r
82                                         print "[MountManager] Error reading Mounts:", e\r
83 \r
84                 print "[AutoMount.py] -getAutoMountPoints:self.automounts -->",self.automounts\r
85                 if len(self.automounts) == 0:\r
86                         print "[AutoMount.py] self.automounts without mounts",self.automounts\r
87                         if callback is not None:\r
88                                 callback(True)\r
89                 else:\r
90                         for sharename, sharedata in self.automounts.items():\r
91                                 self.CheckMountPoint(sharedata, callback)\r
92 \r
93         def CheckMountPoint(self, data, callback):\r
94                 print "[AutoMount.py] CheckMountPoint"\r
95                 print "[AutoMount.py] activeMounts:--->",self.activeMountsCounter\r
96                 if not self.MountConsole:\r
97                         self.MountConsole = Console()\r
98 \r
99                 self.command = None\r
100                 if self.activeMountsCounter == 0:\r
101                         print "self.automounts without active mounts",self.automounts\r
102                         if data['active'] == 'False' or data['active'] is False:\r
103                                 path = '/media/net/'+ data['sharename']\r
104                                 umountcmd = 'umount -f '+ path\r
105                                 print "[AutoMount.py] UMOUNT-CMD--->",umountcmd\r
106                                 self.MountConsole.ePopen(umountcmd, self.CheckMountPointFinished, [data, callback])\r
107                 else:\r
108                         if data['active'] == 'False' or data['active'] is False:\r
109                                 path = '/media/net/'+ data['sharename']\r
110                                 self.command = 'umount -f '+ path\r
111 \r
112                         if data['active'] == 'True' or data['active'] is True:\r
113                                 path = '/media/net/'+ data['sharename']\r
114                                 if os_path.exists(path) is False:\r
115                                         mkdir(path)\r
116                                 tmpsharedir = data['sharedir'].replace(" ", "\\ ")\r
117                                 if tmpsharedir[-1:] == "$":\r
118                                         tmpdir = tmpsharedir.replace("$", "\\$")\r
119                                         tmpsharedir = tmpdir\r
120 \r
121                                 if data['mounttype'] == 'nfs':\r
122                                         if not os_path.ismount(path):\r
123                                                 tmpcmd = 'mount -t nfs -o tcp,'+ data['options'] +',rsize=8192,wsize=8192 ' + data['ip'] + ':' + tmpsharedir + ' ' + path\r
124                                                 self.command = tmpcmd.encode("UTF-8")\r
125 \r
126                                 if data['mounttype'] == 'cifs':\r
127                                         if not os_path.ismount(path):\r
128                                                 tmpusername = data['username'].replace(" ", "\\ ")\r
129                                                 tmpcmd = 'mount -t cifs -o '+ data['options'] +',iocharset=utf8,rsize=8192,wsize=8192,username='+ tmpusername + ',password='+ data['password'] + ' //' + data['ip'] + '/' + tmpsharedir + ' ' + path\r
130                                                 self.command = tmpcmd.encode("UTF-8")\r
131 \r
132                         if self.command is not None:\r
133                                 print "[AutoMount.py] U/MOUNTCMD--->",self.command\r
134                                 self.MountConsole.ePopen(self.command, self.CheckMountPointFinished, [data, callback])\r
135                         else:\r
136                                 self.CheckMountPointFinished(None,None, [data, callback])\r
137 \r
138         def CheckMountPointFinished(self, result, retval, extra_args):\r
139                 print "[AutoMount.py] CheckMountPointFinished"\r
140                 print "[AutoMount.py] result",result\r
141                 print "[AutoMount.py] retval",retval\r
142                 (data, callback ) = extra_args\r
143                 print "LEN",len(self.MountConsole.appContainers)\r
144                 path = '/media/net/'+ data['sharename']\r
145                 print "PATH im CheckMountPointFinished",path\r
146                 if os_path.exists(path):\r
147                         if os_path.ismount(path):\r
148                                 if self.automounts.has_key(data['sharename']):\r
149                                         self.automounts[data['sharename']]['isMounted'] = True\r
150                                         desc = data['sharename']\r
151                                         harddiskmanager.addMountedPartition(path, desc)\r
152                         else:\r
153                                 if self.automounts.has_key(data['sharename']):\r
154                                         self.automounts[data['sharename']]['isMounted'] = False\r
155                                 if os_path.exists(path):\r
156                                         if not os_path.ismount(path):\r
157                                                 rmdir(path)\r
158                                                 harddiskmanager.removeMountedPartition(path)\r
159 \r
160                 if self.MountConsole:\r
161                         if len(self.MountConsole.appContainers) == 0:\r
162                                 if callback is not None:\r
163                                         self.callback = callback\r
164                                         self.timer.startLongTimer(10)\r
165 \r
166         def mountTimeout(self):\r
167                 self.timer.stop()\r
168                 if self.MountConsole:\r
169                         if len(self.MountConsole.appContainers) == 0:\r
170                                 print "self.automounts after mounting",self.automounts\r
171                                 if self.callback is not None:\r
172                                         self.callback(True)\r
173 \r
174         def getMountsList(self):\r
175                 return self.automounts\r
176 \r
177         def getMountsAttribute(self, mountpoint, attribute):\r
178                 if self.automounts.has_key(mountpoint):\r
179                         if self.automounts[mountpoint].has_key(attribute):\r
180                                 return self.automounts[mountpoint][attribute]\r
181                 return None\r
182 \r
183         def setMountsAttribute(self, mountpoint, attribute, value):\r
184                 print "setting for mountpoint", mountpoint, "attribute", attribute, " to value", value\r
185                 if self.automounts.has_key(mountpoint):\r
186                         self.automounts[mountpoint][attribute] = value\r
187 \r
188         def writeMountsConfig(self):\r
189                 # Generate List in RAM\r
190                 list = ['<?xml version="1.0" ?>\n<mountmanager>\n']\r
191 \r
192                 for sharename, sharedata in self.automounts.items():\r
193                         if sharedata['mounttype'] == 'nfs':\r
194                                 list.append('<nfs>\n')\r
195                                 list.append(' <mount>\n')\r
196                                 list.append(''.join(["  <active>", str(sharedata['active']), "</active>\n"]))\r
197                                 list.append(''.join(["  <ip>", sharedata['ip'], "</ip>\n"]))\r
198                                 list.append(''.join(["  <sharename>", sharedata['sharename'], "</sharename>\n"]))\r
199                                 list.append(''.join(["  <sharedir>", sharedata['sharedir'], "</sharedir>\n"]))\r
200                                 list.append(''.join(["  <options>", sharedata['options'], "</options>\n"]))\r
201                                 list.append(' </mount>\n')\r
202                                 list.append('</nfs>\n')\r
203 \r
204                         if sharedata['mounttype'] == 'cifs':\r
205                                 list.append('<cifs>\n')\r
206                                 list.append(' <mount>\n')\r
207                                 list.append(''.join(["  <active>", str(sharedata['active']), "</active>\n"]))\r
208                                 list.append(''.join(["  <ip>", sharedata['ip'], "</ip>\n"]))\r
209                                 list.append(''.join(["  <sharename>", sharedata['sharename'], "</sharename>\n"]))\r
210                                 list.append(''.join(["  <sharedir>", sharedata['sharedir'], "</sharedir>\n"]))\r
211                                 list.append(''.join(["  <options>", sharedata['options'], "</options>\n"]))\r
212                                 list.append(''.join(["  <username>", sharedata['username'], "</username>\n"]))\r
213                                 list.append(''.join(["  <password>", sharedata['password'], "</password>\n"]))\r
214                                 list.append(' </mount>\n')\r
215                                 list.append('</cifs>\n')\r
216 \r
217                 # Close Mountmanager Tag\r
218                 list.append('</mountmanager>\n')\r
219 \r
220                 # Try Saving to Flash\r
221                 file = None\r
222                 try:\r
223                         file = open(XML_FSTAB, "w")\r
224                         file.writelines(list)\r
225                 except Exception, e:\r
226                         print "[AutoMount.py] Error Saving Mounts List:", e\r
227                 finally:\r
228                         if file is not None:\r
229                                 file.close()\r
230 \r
231         def stopMountConsole(self):\r
232                 if self.MountConsole is not None:\r
233                         self.MountConsole = None\r
234 \r
235         def removeMount(self, mountpoint, callback = None):\r
236                 print "[AutoMount.py] removing mount: ",mountpoint\r
237                 self.newautomounts = {}\r
238                 for sharename, sharedata in self.automounts.items():\r
239                         if sharename is not mountpoint.strip():\r
240                                 self.newautomounts[sharename] = sharedata\r
241                 self.automounts.clear()\r
242                 self.automounts = self.newautomounts\r
243                 if not self.removeConsole:\r
244                         self.removeConsole = Console()\r
245                 path = '/media/net/'+ mountpoint\r
246                 umountcmd = 'umount -f '+ path\r
247                 print "[AutoMount.py] UMOUNT-CMD--->",umountcmd\r
248                 self.removeConsole.ePopen(umountcmd, self.removeMountPointFinished, [path, callback])\r
249 \r
250         def removeMountPointFinished(self, result, retval, extra_args):\r
251                 print "[AutoMount.py] removeMountPointFinished"\r
252                 print "[AutoMount.py] result",result\r
253                 print "[AutoMount.py] retval",retval\r
254                 (path, callback ) = extra_args\r
255                 if os_path.exists(path):\r
256                         if not os_path.ismount(path):\r
257                                 rmdir(path)\r
258                                 harddiskmanager.removeMountedPartition(path)\r
259 \r
260                 if self.removeConsole:\r
261                         if len(self.removeConsole.appContainers) == 0:\r
262                                 if callback is not None:\r
263                                         self.callback = callback\r
264                                         self.timer.startLongTimer(10)\r
265 \r
266 \r
267 # currently unused autofs support stuff\r
268 """\r
269 class AutoMount_Unused:\r
270         def __init__(self):\r
271                 self.automounts = {}\r
272                 self.restartConsole = Console()\r
273                 self.MountConsole = Console()\r
274                 self.activeMountsCounter = 0\r
275                 self.getAutoMountPoints()\r
276 \r
277         # helper function\r
278         def regExpMatch(self, pattern, string):\r
279                 if string is None:\r
280                         return None\r
281                 try:\r
282                         return pattern.search(string).group()\r
283                 except AttributeError:\r
284                         None\r
285 \r
286         # helper function to convert ips from a sring to a list of ints\r
287         def convertIP(self, ip):\r
288                 strIP = ip.split('.')\r
289                 ip = []\r
290                 for x in strIP:\r
291                         ip.append(int(x))\r
292                 return ip\r
293 \r
294 \r
295         def getAutoMountPoints(self, callback = None):\r
296                 print "[AutoMount.py] getAutoMountPoints"\r
297                 automounts = []\r
298                 self.automounts = {}\r
299                 self.activeMountsCounter = 0\r
300                 fp = None\r
301                 try:\r
302                         fp = file('/etc/auto.network', 'r')\r
303                         automounts = fp.readlines()\r
304                         fp.close()\r
305                 except:\r
306                         print "[AutoMount.py] /etc/auto.network - opening failed"\r
307 \r
308                 ipRegexp = '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'\r
309                 cifsIpLinePattern = re_compile('://' + ipRegexp + '/')\r
310                 nfsIpLinePattern = re_compile(ipRegexp + ':/')\r
311                 ipPattern = re_compile(ipRegexp)\r
312                 for line in automounts:\r
313                         print "[AutoMount.py] Line:",line\r
314                         split = line.strip().split('\t',2)\r
315                         if split[0] == '*':\r
316                                 continue\r
317                         if len(split) == 2 and split[0][0] == '*':\r
318                                 continue\r
319                         if len(split) == 3:\r
320                                 data = { 'isMounted': False, 'active': False, 'ip': False, 'sharename': False, 'sharedir': False, 'username': False, 'password': False, 'mounttype' : False, 'options' : False }\r
321                                 currshare = ""\r
322                                 if split[0][0] == '#':\r
323                                         data['active'] = False\r
324                                         currshare = split[0][1:]\r
325                                         data['sharename'] = currshare\r
326                                 else:\r
327                                         data['active'] = True\r
328                                         self.activeMountsCounter +=1\r
329                                         currshare = split[0]\r
330                                         data['sharename'] = currshare\r
331                                 if '-fstype=cifs' in split[1]:\r
332                                         data['mounttype'] = 'cifs'\r
333                                         options = split[1][split[1].index('-fstype=cifs')+13 : split[1].index(',user=')]\r
334                                         if options is not None:\r
335                                                 data['options'] = options\r
336                                         if 'user=' in split[1]:\r
337                                                 username = split[1][split[1].index(',user=')+6 : split[1].index(',pass=')]\r
338                                                 if username is not None:\r
339                                                         data['username'] = username\r
340                                         if 'pass=' in split[1]:\r
341                                                 password = split[1][split[1].index(',pass=')+6 : ]\r
342                                                 if password is not None:\r
343                                                         data['password'] = password\r
344                                         ip = self.regExpMatch(ipPattern, self.regExpMatch(cifsIpLinePattern, split[2]))\r
345                                         if ip is not None:\r
346                                                 data['ip'] = ip\r
347                                         sharedir = split[2][split[2].index(ip)+len(ip)+1 : ]\r
348                                         if sharedir is not None:\r
349                                                 tmpsharedir = sharedir.replace("\\ ", " ")\r
350                                                 if tmpsharedir[-2:] == "\$":\r
351                                                         tmpdir = tmpsharedir.replace("\$", "$")\r
352                                                         tmpsharedir = tmpdir\r
353                                                 data['sharedir'] = tmpsharedir\r
354 \r
355                                 if '-fstype=nfs' in split[1]:\r
356                                         data['mounttype'] = 'nfs'\r
357                                         options = split[1][split[1].index('-fstype=nfs')+12 : ]\r
358                                         if options is not None:\r
359                                                 data['options'] = options\r
360                                         ip = self.regExpMatch(ipPattern, self.regExpMatch(nfsIpLinePattern, split[2]))\r
361                                         if ip is not None:\r
362                                                 data['ip'] = ip\r
363                                         sharedir = split[2][split[2].index(ip)+len(ip)+1 : ]\r
364                                         if sharedir is not None:\r
365                                                 tmpsharedir = sharedir.replace("\\ ", " ")\r
366                                                 if tmpsharedir[-2:] == "\$":\r
367                                                         tmpdir = tmpsharedir.replace("\$", "$")\r
368                                                         tmpsharedir = tmpdir\r
369                                                 data['sharedir'] = tmpsharedir\r
370 \r
371                                 self.automounts[currshare] = data\r
372                 if len(self.automounts) == 0:\r
373                         print "[AutoMount.py] self.automounts without mounts",self.automounts\r
374                         if callback is not None:\r
375                                 callback(True)\r
376                 else:\r
377                         #print "automounts",self.automounts\r
378                         for sharename, sharedata in self.automounts.items():\r
379                                 self.CheckMountPoint(sharedata, callback)\r
380 \r
381         def CheckMountPoint(self, data, callback):\r
382                 print "[AutoMount.py] CheckMountPoint"\r
383                 if not self.MountConsole:\r
384                         self.MountConsole = Console()\r
385                 print "[AutoMount.py] activeMounts--->",self.activeMountsCounter\r
386                 if self.activeMountsCounter == 0:\r
387                 #if data['active'] is False:\r
388                         if self.MountConsole:\r
389                                 if len(self.MountConsole.appContainers) == 0:\r
390                                         print "self.automounts without active mounts",self.automounts\r
391                                         if callback is not None:\r
392                                                 callback(True)\r
393                 else:\r
394                         if data['mounttype'] == 'nfs' and data['active'] is True:\r
395                                 path = '/tmp/'+ data['sharename']\r
396                                 if os_path.exists(path) is False:\r
397                                         mkdir(path)\r
398                                 tmpsharedir = data['sharedir'].replace(" ", "\\ ")\r
399                                 if tmpsharedir[-1:] == "$":\r
400                                         tmpdir = tmpsharedir.replace("$", "\\$")\r
401                                         tmpsharedir = tmpdir\r
402                                 nfscmd = 'mount -o nolock -t nfs ' + data['ip'] + ':' + tmpsharedir + ' ' + path\r
403                                 print "[AutoMount.py] nfsscmd--->",nfscmd\r
404                                 self.MountConsole.ePopen(nfscmd, self.CheckMountPointFinished, [data, callback])\r
405                         if data['mounttype'] == 'cifs' and data['active'] is True:\r
406                                 self.activeMountsCounter +=1\r
407                                 path = '/tmp/'+ data['sharename']\r
408                                 if os_path.exists(path) is False:\r
409                                         mkdir(path)\r
410                                 tmpsharedir = data['sharedir'].replace(" ", "\\ ")\r
411                                 if tmpsharedir[-1:] == "$":\r
412                                         tmpdir = tmpsharedir.replace("$", "\\$")\r
413                                         tmpsharedir = tmpdir\r
414                                 cifscmd = 'mount -t cifs -o rw,username='+ data['username'] + ',password='+ data['password'] + ' //' + data['ip'] + '/' + tmpsharedir + ' ' + path\r
415                                 print "[AutoMount.py] cifscmd--->",cifscmd\r
416                                 self.MountConsole.ePopen(cifscmd, self.CheckMountPointFinished, [data, callback])\r
417 \r
418         def CheckMountPointFinished(self, result, retval, extra_args):\r
419                 print "[AutoMount.py] CheckMountPointFinished"\r
420                 (data, callback ) = extra_args\r
421                 path = '/tmp/'+ data['sharename']\r
422                 if not self.MountConsole:\r
423                         self.MountConsole = Console()\r
424                 if os_path.ismount(path):\r
425                         if self.automounts.has_key(data['sharename']):\r
426                                 self.automounts[data['sharename']]['isMounted'] = True\r
427                 else:\r
428                         if self.automounts.has_key(data['sharename']):\r
429                                 self.automounts[data['sharename']]['isMounted'] = False\r
430                 umountcmd = 'umount /tmp/'+ data['sharename']\r
431                 self.MountConsole.ePopen(umountcmd, self.CleanMountPointFinished, [data, callback])\r
432 \r
433         def CleanMountPointFinished(self, result, retval, extra_args):\r
434                 print "[AutoMount.py] CleanMountPointFinished"\r
435                 (data, callback ) = extra_args\r
436                 path = '/tmp/'+ data['sharename']\r
437                 if os_path.exists(path):\r
438                         rmdir(path)\r
439                 if self.MountConsole:\r
440                         if len(self.MountConsole.appContainers) == 0:\r
441                                 print "self.automounts after mountcheck",self.automounts\r
442                                 if callback is not None:\r
443                                         callback(True)\r
444 \r
445         def getMountsList(self):\r
446                 return self.automounts\r
447 \r
448         def getMountsAttribute(self, mountpoint, attribute):\r
449                 if self.automounts.has_key(mountpoint):\r
450                         if self.automounts[mountpoint].has_key(attribute):\r
451                                 return self.automounts[mountpoint][attribute]\r
452                 return None\r
453 \r
454         def setMountsAttribute(self, mountpoint, attribute, value):\r
455                 print "setting for mountpoint", mountpoint, "attribute", attribute, " to value", value\r
456                 if self.automounts.has_key(mountpoint):\r
457                         self.automounts[mountpoint][attribute] = value\r
458 \r
459         def removeMount(self, mountpoint):\r
460                 self.newautomounts = {}\r
461                 #self.automounts[currshare] = data\r
462                 print "[AutoMount.py] removing mount: ",mountpoint\r
463                 for sharename, sharedata in self.automounts.items():\r
464                         if sharename is not mountpoint.strip():\r
465                                 self.newautomounts[sharename] = sharedata\r
466                 self.automounts.clear()\r
467                 self.automounts = self.newautomounts\r
468 \r
469         def writeMountsConfig(self):\r
470                 fp = file('/etc/auto.network', 'w')\r
471                 fp.write("# automatically generated by enigma 2\n# do NOT change manually!\n\n")\r
472                 for sharename, sharedata in self.automounts.items():\r
473                         if sharedata['mounttype'] == 'nfs':\r
474                                 if sharedata['active'] is False:\r
475                                         fp.write("#" + sharedata['sharename'] + "\t")\r
476                                 else:\r
477                                         fp.write( sharedata['sharename'] + "\t")\r
478                                 fp.write( "-fstype=nfs," + sharedata['options'] + "\t")\r
479                                 fp.write(sharedata['ip'] + ":")\r
480                                 tmpsharedir = sharedata['sharedir'].replace(" ", "\\ ")\r
481                                 if tmpsharedir[-1:] == "$":\r
482                                         tmpdir = tmpsharedir.replace("$", "\\$")\r
483                                         tmpsharedir = tmpdir\r
484                                 fp.write( tmpsharedir + "\n")\r
485                         if sharedata['mounttype'] == 'cifs':\r
486                                 if sharedata['active'] is False:\r
487                                         fp.write("#" + sharedata['sharename'] + "\t")\r
488                                 else:\r
489                                         fp.write( sharedata['sharename'] + "\t")\r
490                                 fp.write( "-fstype=cifs," + sharedata['options'] + ",")\r
491                                 fp.write( "user=" + sharedata['username'] + ",")\r
492                                 fp.write( "pass=" + sharedata['password'] + "\t://")\r
493                                 fp.write(sharedata['ip'] + "/")\r
494                                 tmpsharedir = sharedata['sharedir'].replace(" ", "\\ ")\r
495                                 if tmpsharedir[-1:] == "$":\r
496                                         tmpdir = tmpsharedir.replace("$", "\\$")\r
497                                         tmpsharedir = tmpdir\r
498                                 fp.write( tmpsharedir + "\n")\r
499                 fp.write("\n")\r
500                 fp.close()\r
501 \r
502         def restartAutoFS(self,callback = None):\r
503                 print "[AutoMount.py] restartAutoFS "\r
504                 self.restartConsole = Console()\r
505                 self.commands = []\r
506                 self.commands.append("/etc/init.d/autofs stop")\r
507                 self.commands.append("killall -9 automount")\r
508                 self.commands.append("rm -rf /var/run/autofs")\r
509                 self.commands.append("/etc/init.d/autofs start")\r
510                 self.restartConsole.eBatch(self.commands, self.restartAutoFSFinished, callback, debug=True)\r
511 \r
512         def restartAutoFSFinished(self,extra_args):\r
513                 print "[AutoMount.py] restartAutoFSFinished "\r
514                 ( callback ) = extra_args\r
515                 if callback is not None:\r
516                         callback(True)\r
517 \r
518         def stopMountConsole(self):\r
519                 if self.MountConsole is not None:\r
520                         self.MountConsole = None """\r
521 \r
522 iAutoMount = AutoMount()\r
523 \r