1
0
mirror of https://github.com/gryf/pygtktalog.git synced 2025-12-17 11:30:19 +01:00

* Check for mount point in fstab in every method.

* Changed return values in volmount method.
This commit is contained in:
2006-11-26 10:59:57 +00:00
parent 1b77a49958
commit 518e4658a7

View File

@@ -1,28 +1,69 @@
#!/usr/bin/python # This Python file uses the following encoding: utf-8
# -*- coding: utf-8 -*-
""" """
device (cd, dvd) helper device (cd, dvd) helper
""" """
import string import string
import os import os
import popen2
def volname(dev): from config import Config
c = Config()
def volname(mntp):
"""read volume name from cd/dvd""" """read volume name from cd/dvd"""
try: dev = mountpoint_to_dev(mntp)
a = open(dev,"rb") if dev != None:
a.seek(32808) try:
b = a.read(32).strip() a = open(dev,"rb")
a.close() a.seek(32808)
except: b = a.read(32).strip()
return None a.close()
return b except:
return None
return b
return None
def volmount(dev): def volmount(mntp):
"""mount device, return True/False""" """mount device, return True/False"""
stout,stin,sterr = popen3("mount %s" % dev) dev = mountpoint_to_dev(mntp)
error = sterr.readline() if dev != None:
stout.close() _in,_out,_err = popen2.popen3("mount %s" % dev)
stin.close() inf = _err.readlines()
sterr.close() for i in inf:
return len(error) == 0 i.strip()
if check_mount(dev):
return 'ok'
else:
return i.strip()
return "Mount point does'nt exist in fstab"
def check_mount(dev):
"""Refresh the entries from fstab or mount."""
mounts = os.popen('mount')
for line in mounts.readlines():
parts = line.split()
device, txt1, mount_point, txt2, filesystem, options = parts
if device == dev:
return True
return False
def mountpoint_to_dev(mntp):
"""guess mountpoint from fstab"""
fstab = open("/etc/fstab")
for line in fstab.readlines():
a = line.split()
try:
if a[1] == mntp and a[0][0] != '#':
fstab.close()
return a[0]
except:
pass
fstab.close()
return None
def eject_cd():
if len(c.confd['eject']) > 0:
os.popen("%s %s" %(c.confd['eject'],c.confd['cd']))