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 if dev_real_path.find("f0b00500.ehci_v2/usb2/2-1") != -1:
75 mountPoint = "/media/hdd"
77 if (mountPoint == None) or (os.path.ismount(mountPoint)):
78 label = getLabelFromDevName(dev_kernel)
80 mountPoint = "/media/" + label
81 if dev_index and dev_index != '1':
82 mountPoint += "_%s" % dev_index
84 if (mountPoint == None) or (os.path.ismount(mountPoint)):
85 model = getModel(dev_base)
87 mountPoint = "/media/" + model
88 if dev_index and dev_index != '1':
89 mountPoint += "_%s" % dev_index
91 if (mountPoint == None) or (os.path.ismount(mountPoint)):
92 mountPoint = "/media/" + kernel
94 if not os.access(mountPoint, os.F_OK):
96 if not os.access(mountPoint, os.F_OK):
99 fs = checkFilesystem(dev_kernel)
101 cmd = "mount.ntfs-3g %s %s" % (dev_kernel, mountPoint)
103 cmd = "mount -t auto -o noatime %s %s" % (dev_kernel, mountPoint)
110 if mountPoint == "/media/hdd":
111 defaultMoviePath = "/media/hdd/movie"
112 if not os.access(defaultMoviePath, os.F_OK):
113 os.mkdir(defaultMoviePath)
115 if __name__=="__main__":