7 return open(fn, "r").read()
9 def getLabelFromDevName(dev_kernel):
12 data = os.popen("e2label %s" % dev_kernel).read().strip()
20 def getModel(dev_base):
22 modelpath = "/sys/block/%s/device/model" % dev_base
23 if os.access(modelpath, os.F_OK):
24 model = open(modelpath, "r").read().strip().replace(' ','-')
27 def isMountedByDevName(devName):
29 mounts = file('/proc/mounts').read().split('\n')
31 if not x.startswith('/'):
34 devpath, mountpoint = x.split()[:2]
35 if devpath == devName:
41 def isUsbDevice(dev_base):
42 phyPath = os.path.realpath('/sys/block/' + dev_base + '/device')
43 for x in glob.glob("/sys/bus/usb/devices/usb*"):
44 if phyPath.find(os.path.realpath(x)) != -1:
48 def checkFilesystem(device):
49 p = os.popen("blkid %s" % device)
54 for x in data.split():
55 if x.startswith('TYPE') and x.find('=') != -1:
56 fs = x.split('=')[1].strip('"')
63 dev_kernel = os.path.join("/dev/", kernel)
64 dev_index = os.path.basename(kernel)[-1]
65 dev_base = os.path.basename(kernel)[:-1]
66 removable=readFile("/sys/block/%s/removable" % dev_base).strip() == "1"
67 dev_real_path = os.path.realpath("/sys/block/%s/device" % dev_base)
69 if isMountedByDevName(dev_kernel):
74 usbDevice = removable or isUsbDevice(dev_base)
76 mountPoint = "/media/hdd"
78 if (mountPoint == None) or (os.path.ismount(mountPoint)):
79 label = getLabelFromDevName(dev_kernel)
81 mountPoint = "/media/" + label
82 if dev_index and dev_index != '1':
83 mountPoint += "_%s" % dev_index
85 if (mountPoint == None) or (os.path.ismount(mountPoint)):
86 model = getModel(dev_base)
88 mountPoint = "/media/" + model
89 if dev_index and dev_index != '1':
90 mountPoint += "_%s" % dev_index
92 if (mountPoint == None) or (os.path.ismount(mountPoint)):
93 mountPoint = "/media/" + kernel
95 if not os.access(mountPoint, os.F_OK):
97 if not os.access(mountPoint, os.F_OK):
100 fs = checkFilesystem(dev_kernel)
102 cmd = "mount.ntfs-3g %s %s" % (dev_kernel, mountPoint)
104 cmd = "mount -t auto -o noatime %s %s" % (dev_kernel, mountPoint)
111 if mountPoint == "/media/hdd":
112 defaultMoviePath = "/media/hdd/movie"
113 if not os.access(defaultMoviePath, os.F_OK):
114 os.mkdir(defaultMoviePath)
116 if __name__=="__main__":