-
Notifications
You must be signed in to change notification settings - Fork 2
/
storage.py
36 lines (24 loc) · 879 Bytes
/
storage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#! /usr/bin/env python
import subprocess
import shlex
def mount_device(device_name, media_label='images'):
command = "pmount -w {device_name} {media_label}".format(device_name=r'"%s"' % device_name,
media_label=r'"%s"' % media_label)
execute_process(command=command)
return '/media/' + media_label
def umount_device(device_name):
command = "pumount {device_name}".format(device_name=r'"%s"' % device_name)
execute_process(command=command)
def execute_process(command):
"""
Execute the command
:param command: full command string
"""
cmd = shlex.split(command)
p = subprocess.Popen(cmd, shell=False, stderr=subprocess.STDOUT)
p.wait()
if __name__ == '__main__':
dev = '/dev/sda1'
umount_device(dev)
directory = mount_device(dev)
print(directory)