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)
43 for x in glob.glob("/sys/bus/usb/devices/usb*"):
44 if phyPath.find(os.path.realpath(x)) != -1:
50 dev_kernel = os.path.join("/dev/", kernel)
51 dev_index = os.path.basename(kernel)[-1]
52 dev_base = os.path.basename(kernel)[:-1]
53 removable=readFile("/sys/block/%s/removable" % dev_base).strip() == "1"
54 dev_real_path = os.path.realpath("/sys/block/%s/device" % dev_base)
56 if isMountedByDevName(dev_kernel):
61 if dev_real_path.find("f0b00500.ehci_v2/usb2/2-1") != -1:
62 mountPoint = "/media/hdd"
64 if (mountPoint == None) or (os.path.ismount(mountPoint)):
65 label = getLabelFromDevName(dev_kernel)
67 mountPoint = "/media/" + label
68 if dev_index and dev_index != '1':
69 mountPoint += "_%s" % dev_index
71 if (mountPoint == None) or (os.path.ismount(mountPoint)):
72 model = getModel(dev_base)
74 mountPoint = "/media/" + model
75 if dev_index and dev_index != '1':
76 mountPoint += "_%s" % dev_index
78 if (mountPoint == None) or (os.path.ismount(mountPoint)):
79 mountPoint = "/media/" + kernel
81 if not os.access(mountPoint, os.F_OK):
83 if not os.access(mountPoint, os.F_OK):
86 if os.system("mount -t auto -o noatime %s %s" % (dev_kernel, mountPoint)):
89 if mountPoint == "/media/hdd":
90 defaultMoviePath = "/media/hdd/movie"
91 if not os.access(defaultMoviePath, os.F_OK):
92 os.mkdir(defaultMoviePath)
94 if __name__=="__main__":