2016-09-13 4 views
-1

장치를 지정된 위치에 마운트하는 프로그램을 작성하려고 시도했지만 모든 것이 사용자 입력에 의해 완료됩니다.어떻게 파이썬을 사용하여 USB 장치 또는 하드 드라이브 파티션을 마운트합니까?

ctypes입니다. 내가 붙어있어 장소는이 부분

def mount(source, target, fs, options=''): 
    ret = ctypes.CDLL('libc.so.6', use_errno=True).mount(source, target, fs, 0, options) 
    if ret < 0: 
    errno = ctypes.get_errno() 
    raise RuntimeError("Error mounting {} ({}) on {} : {}". 
    format(source, fs, target, os.strerror(errno))) 

내가 '잘못된 인수'을 없다는 오류 메시지가 표시됨에있다 그리고 그것은 내 전체 코드는 다음

mount(a, b, 'ntfs', ' -w')

에있다 :

import os 
import ctypes 

print "Usb device management" 

def mount(source, target, fs, options=''): 
ret = ctypes.CDLL('libc.so.6', use_errno=True).mount(source, target, fs, 0, options) 
if ret < 0: 
errno = ctypes.get_errno() 
raise RuntimeError("Error mounting {} ({}) on {} : {}". 
    format(source, fs, target, os.strerror(errno))) 

def umount(source): 
retu = ctypes.CDLL('libc.so.6', use_errno = True).umount(source) 
    if retu < 0: 
    errno1 = ctypes.get_errno1() 
    raise RuntimeError("error unmounting {} ". 
     format(source)) 


while True : 
print "\n 1. Mount \n 2. Unmount \n 3. Write to file \n 4. Read File \n 5. Copy \n 6. Exit" 
choice = int(raw_input('Enter the choice : ')) 

if choice == 1: 
    a = raw_input('Enter device name ') 
    b = raw_input('Enter mount location ') 
    mount(a, b, 'ntfs', ' -w') 
    print "USB mounted" 

elif choice == 2: 
    print "Unmounting USB device" 
    c=raw_input('Enter USB device location ') 
    umount (c) 
    print "USB device unmounted" 
elif choice == 3: 
    string = raw_input('Give input to write to file') 
    fd = open("%s/file.txt"%(b), 'w') 
    fd.write('string') 
    print "file Write successfull" 
    fd.close() 
elif choice == 4: 
    print "Reading file" 
    fd = open("%s/file.txt"%(b),'r') 
    print "File read successfull " 
    fd.close() 
elif choice == 5: 
    copy_location = raw_input('Enter location to where it has to be copied') 
    print "Copying file " 
    os.system("cp %s/file.txt %s"%(b, copy_location)) 
    print "%s %s"%(b, copy_location) 
    print("File copied to location $s "%(copylocation)) 
if choice == 6: 
    print "Exit bye" 
    break; 

그리고 내 시스템은 우분투 15.10입니다.

답변

0

난 그냥 명령 줄 마운트를 사용합니다. 당신이 man 2 mount 보면

import os 
os.system("mount /dev/sd(x) /mountpoint") 
+0

나는 이것을 알고있다. 그러나 이것에 관해서 배웠는데, 나는이 유형을 배웠고 지금도이 방법을 배우기를 원한다. –

0

, 당신은 마운트 플래그가 숫자가 아닌 문자열하는 것을 볼 수 있습니다. 이것은 명백한 오류입니다. 네가 가진 모든 오류가 있든, 나는 말할 수 없다.

관련 문제