make capacity fault-proof
[enigma2.git] / lib / python / Components / Harddisk.py
1
2
3 def tryOpen(filename):
4         try:
5                 procFile = open(filename)
6         except IOError:
7                 return ""
8         return procFile
9
10 class Harddisk:
11         def __init__(self, index):
12                 self.index = index
13                 #perhaps this is easier?
14                 self.prochdx = "/proc/ide/hd" + ("a","b","c","d","e","f","g","h")[index] + "/"
15                 
16         def capacity(self):
17                 procfile = tryOpen(self.prochdx + "capacity")
18                 
19                 if procfile == "":
20                         return -1
21
22                 line = procfile.readline()
23                 procfile.close()
24                 
25                 try:
26                         cap = int(line)
27                 except:
28                         return -1
29                 
30                 return cap      
31                                                 
32         def model(self):
33                 procfile = tryOpen(self.prochdx + "model")
34                 
35                 if procfile == "":
36                         return ""
37
38                 line = procfile.readline()
39                 procfile.close()
40
41                 return line
42
43         def free(self):
44                 pass
45                 
46