Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mount a network directory using python?

I need to mount a directory "dir" on a network machine "data" using python on a linux machine

I know that I can send the command via command line:

mkdir ~/mnt/data_dir
mount -t data:/dir/ ~/mnt/data_dir

but how would I send those commands from a python script?

like image 397
llaskin Avatar asked Feb 09 '10 20:02

llaskin


1 Answers

I'd recommend you use subprocess.checkcall.

from subprocess import *

#most simply
check_call( 'mkdir ~/mnt/data_dir', shell=True )
check_call( 'mount -t whatever data:/dir/ ~/mnt/data_dir', shell=True )


#more securely
from os.path import expanduser
check_call( [ 'mkdir', expanduser( '~/mnt/data_dir' ) ] )
check_call( [ 'mount', '-t', 'whatever', 'data:/dir/', expanduser( '~/mnt/data_dir' ) ] )
like image 149
deft_code Avatar answered Oct 26 '22 19:10

deft_code