]> gitweb.pimeys.fr Git - scripts-20-100.git/blob - mountdisk.py
Installer aussi tree et curl
[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", "Zêta", "Êta"]
15
16 # "Delta" a été viré
17
18 def mount(dev, name):
19 """Monte le disque ``dev`` à l'emplacement ``name``"""
20 proc = subprocess.Popen(["mount", dev, name], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
21 out, err = proc.communicate()
22 if err:
23 raise RuntimeError(err)
24 print out
25
26
27 def mount_by_name(name):
28 """Rajoute les paths habituels"""
29 mount("/dev/disk/by-label/%s" % name, "/media/%s" % name)
30
31 if __name__ == "__main__":
32 param = sys.argv[1]
33 if param == "-l":
34 for i in DISKS:
35 print i
36 sys.exit(0)
37 elif param == "all":
38 print "Mounting all the disk : %s" % ", ".join(DISKS)
39 mountlist = DISKS
40 else:
41 mountlist = [param]
42 for disk in mountlist:
43 try:
44 mount_by_name(disk)
45 except RuntimeError:
46 print traceback.format_exc()