Bonjour,
je reposte une version tenant compte de quelques modifications (pas toutes, hein). pour les Debian User qui trainent sur le forum Ubuntu, cela fonctionne.
Notes:
- Vérifiez l'emplacement de fusermount
- Non testé sous Ubuntu (le comble, je sais)
#! /usr/bin/env python
# coding: utf-8
#
# fusauto
# auto mount directory with fuse by reading a config file
#
# Copyright (C) Nicolas Albert <nicolas_albert_85@yahoo.fr>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Revisions
# Version 0.0.2 (by MrJK, mrjkDOT78ATgmailDOTcom):
# - Modified: French support (instead english support)
# - Fixed: Must work under Debian (not tested under Ubuntu)
# - Fixed: bug when trying to unmount folder
# - Added: Information on what you are doing
#
# Version 0.0.1:
# - Initial version
import sys, os
def runconf(conf, path):
file = open(conf, "r")
act = {}
for line in file.readlines():
if not line.startswith('#'):
part = line[:-1].partition('=')
act[part[0]] = part[2]
file.close()
if 'bin' in act:
if not 'from' in act: act['from']='none'
if not 'opt' in act: act['opt']=''
os.system("%s %s %s -o nonempty %s"%(act['bin'], act['from'], path, act['opt']))
def getfuses():
mtab = open("/etc/mtab", "r")
fuses =[ line for line in mtab.readlines() if line.split()[2].find("fuse.") != -1 ]
mtab.close()
return fuses
def alreadymount(path):
for fuse in getfuses():
fd = fuse.split()[1] + '/'
if fd == path or fd == os.getcwd()+'/'+path:
return True
return False
def umount(path):
os.system("/usr/bin/fusermount -u "+path)
if __name__ == "__main__":
if len(sys.argv) == 2 and os.path.isdir(sys.argv[1]):
if alreadymount(sys.argv[1]):
print "Démontage du système de fichier en cours ..."
umount(sys.argv[1])
else:
conf = sys.argv[1]+'/fusauto.conf'
if os.path.isfile(conf):
print "Montage du système en cours ..."
runconf(conf, sys.argv[1])
else:
print conf,"est manquant!"
else:
print "Un répertoire doit être spécifié!"