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