comparison python/mountusb.py @ 672:0eff3f3658ed

STUB: python/mountusb.py
author Jeff Hammel <k0scist@gmail.com>
date Mon, 05 May 2014 01:47:27 -0700
parents 0e15d5aa78a2
children 8806a699ff94
comparison
equal deleted inserted replaced
671:eeb38dfa17d0 672:0eff3f3658ed
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 3
4 """ 4 """
5 mount inserted usb disk
6
5 [ 33.854905] usb-storage 1-1.2:1.0: USB Mass Storage device detected 7 [ 33.854905] usb-storage 1-1.2:1.0: USB Mass Storage device detected
6 [ 33.854946] scsi6 : usb-storage 1-1.2:1.0 8 [ 33.854946] scsi6 : usb-storage 1-1.2:1.0
7 [ 33.855002] usbcore: registered new interface driver usb-storage 9 [ 33.855002] usbcore: registered new interface driver usb-storage
8 [ 34.855894] scsi 6:0:0:0: Direct-Access PNY USB 2.0 FD 8.07 PQ: 0 ANSI: 4 10 [ 34.855894] scsi 6:0:0:0: Direct-Access PNY USB 2.0 FD 8.07 PQ: 0 ANSI: 4
9 [ 34.856108] sd 6:0:0:0: Attached scsi generic sg2 type 0 11 [ 34.856108] sd 6:0:0:0: Attached scsi generic sg2 type 0
24 string = (str, unicode) 26 string = (str, unicode)
25 27
26 def main(args=sys.argv[1:]): 28 def main(args=sys.argv[1:]):
27 29
28 parser = argparse.ArgumentParser(description=__doc__) 30 parser = argparse.ArgumentParser(description=__doc__)
31 parser.add_argument('-m', '--mount', dest='mount_point',
32 default='/mnt/media',
33 help="mount point")
29 options = parser.parse_args(args) 34 options = parser.parse_args(args)
30 35
31 dmesg = subprocess.check_output(['dmesg']).splitlines() 36 dmesg = subprocess.check_output(['dmesg']).splitlines()
32 string = 'usbcore: registered new interface driver usb-storage' 37 string = 'usbcore: registered new interface driver usb-storage'
33 for index in reversed(range(len(dmesg))): 38 for index in reversed(range(len(dmesg))):
45 except ValueError: 50 except ValueError:
46 continue 51 continue
47 disk = disk.strip() 52 disk = disk.strip()
48 partition = partition.strip() 53 partition = partition.strip()
49 if partition.startswith(disk): 54 if partition.startswith(disk):
50 print (partition) 55 print ("partition: {}".format(partition))
51 sys.exit(0) 56 break
57 else:
58 parser.error("No partition found")
59
60 device = os.path.join('/dev', partition)
61 assert os.path.exists(device)
62 print "Device: {}".format(device)
63
64 command = ['sudo', 'mount', device, options.mount_point]
65 print (' '.join(command))
52 66
53 if __name__ == '__main__': 67 if __name__ == '__main__':
54 main() 68 main()