]> gitweb.pimeys.fr Git - scripts-20-100.git/blob - mountdisk.py
doublon moins bien commenté
[scripts-20-100.git] / mountdisk.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 """ Pour monter le bon disque juste en précisant son nom
5
6 Doît être exécuté en root.
7
8 """
9
10 import subprocess
11 import sys
12 import traceback
13
14 DISKS = ["Bêta", "Epsilon", "Delta", "Zêta"]
15
16
17 def mount(dev, name):
18 """Monte le disque ``dev`` à l'emplacement ``name``"""
19 proc = subprocess.Popen(["mount", dev, name], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
20 out, err = proc.communicate()
21 if err:
22 raise RuntimeError(err)
23 print out
24
25
26 def mount_by_name(name):
27 """Rajoute les paths habituels"""
28 mount("/dev/disk/by-label/%s" % name, "/media/%s" % name)
29
30 if __name__ == "__main__":
31 param = sys.argv[1]
32 if param == "-l":
33 for i in DISKS:
34 print i
35 sys.exit(0)
36 elif param == "all":
37 print "Mounting all the disk : %s" % ", ".join(DISKS)
38 mountlist = DISKS
39 else:
40 mountlist = [param]
41 for disk in mountlist:
42 try:
43 mount_by_name(disk)
44 except RuntimeError:
45 print traceback.format_exc()