from os import system, listdir, statvfs, popen, makedirs, stat, major, minor, path, access
-from Tools.Directories import SCOPE_HDD, resolveFilename
+
+from Tools.Directories import SCOPE_HDD, resolveFilename, fileExists
+
from Tools.CList import CList
from SystemInfo import SystemInfo
import time
return ret
def diskSize(self):
- line = readFile(self.sysfsPath('size'))
+ try:
+ line = readFile(self.sysfsPath('size'))
+ except:
+ harddiskmanager.removeHotplugPartition(self.device)
+ print "error remove",self.device
+ return -1
try:
cap = int(line)
except:
return "%d.%03d GB" % (cap/1000, cap%1000)
def model(self):
- if self.device[:2] == "hd":
- return readFile('/proc/ide/' + self.device + '/model')
- elif self.device[:2] == "sd":
- vendor = readFile(self.sysfsPath('device/vendor'))
- model = readFile(self.sysfsPath('device/model'))
- return vendor + '(' + model + ')'
- else:
- assert False, "no hdX or sdX"
+ try:
+ if self.device[:2] == "hd":
+ return readFile('/proc/ide/' + self.device + '/model')
+ elif self.device[:2] == "sd":
+ vendor = readFile(self.sysfsPath('device/vendor'))
+ model = readFile(self.sysfsPath('device/model'))
+ return vendor + '(' + model + ')'
+ else:
+ assert False, "no hdX or sdX"
+ except:
+ harddiskmanager.removeHotplugPartition(self.device)
+ print "error remove",self.device
+ return -1
def free(self):
try:
res = system(cmd)
return (res >> 8)
+ def checkPartionPath(self, path):
+ import time, os
+ for i in range(1,10):
+ if os.path.exists(path):
+ return True
+ time.sleep(1)
+ return False
+
def createPartition(self):
- cmd = 'printf "8,\n;0,0\n;0,0\n;0,0\ny\n" | sfdisk -f -uS ' + self.disk_path
+ def CheckPartedVer():
+ cmd = 'parted --version'
+ lines = popen(cmd).readlines()
+ for l in lines:
+ if l.find("parted (GNU parted)") != -1:
+ ver = l.split()[3].strip()
+ break
+ try:
+ ver = float(ver)
+ except:
+ print "[CheckPartedVer] check parted version Failed!"
+ return 0
+ return ver
+
+ disk_size = self.diskSize()
+
+ if disk_size > 2.2 * 1000 * 1000: # if 2.2 TB
+ setAlign = ""
+ partedVer = CheckPartedVer()
+ if partedVer >= 2.1: # align option is supported in version 2.1 or later
+ setAlign = "--align optimal"
+ cmd = 'parted %s %s --script mklabel gpt mkpart disk ext2 0%% 100%%' % ( setAlign, self.disk_path )
+
+ else:
+ cmd = 'printf "8,\n;0,0\n;0,0\n;0,0\ny\n" | sfdisk -f -uS ' + self.disk_path
+
res = system(cmd)
+ if not self.checkPartionPath(self.partitionPath("1")):
+ print "no exist : ", self.partitionPath("1")
+ return 1
return (res >> 8)
def mkfs(self):
def createMovieFolder(self):
try:
+ if not fileExists("/hdd", 0):
+ print "not found /hdd"
+ system("ln -s /media/hdd /hdd")
+
makedirs(resolveFilename(SCOPE_HDD))
except OSError:
return -1
idle_time = t - self.last_access
stats = self.readStats()
+
+ if stats == -1:
+ self.setIdleTime(0)
+ return
print "nr_read", stats[0], "nr_write", stats[1]
l = sum(stats)
print "sum", l, "prev_sum", self.last_stat
def getAutofsMountpoint(self, device):
return "/autofs/%s/" % (device)
+
def is_hard_mounted(self, device):
mounts = file('/proc/mounts').read().split('\n')
for x in mounts:
def HDDList(self):
list = [ ]
for hd in self.hdd:
+ if hd.model() == -1:
+ continue
hdd = hd.model() + " - " + hd.bus()
cap = hd.capacity()
if cap != "":