|
|
|
@ -35,7 +35,7 @@ import operator
|
|
|
|
|
from calculate.lib.cl_lang import setLocalTranslate
|
|
|
|
|
setLocalTranslate('cl_install3',sys.modules[__name__])
|
|
|
|
|
|
|
|
|
|
class Sizes:
|
|
|
|
|
class Sizes(object):
|
|
|
|
|
kB = kilobyte = 1000
|
|
|
|
|
K = kibibyte = 1024
|
|
|
|
|
M = mibibyte = K * 1024
|
|
|
|
@ -44,7 +44,7 @@ class Sizes:
|
|
|
|
|
Gb = gigabyte = Mb * 1000
|
|
|
|
|
T = tibibyte = G * 1024
|
|
|
|
|
Tb = terabyte = Gb * 1000
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __getattr__(self,name):
|
|
|
|
|
if name.startswith('from_'):
|
|
|
|
|
return lambda x:x*getattr(Sizes,name[5:])
|
|
|
|
@ -65,13 +65,13 @@ class AutoPartition:
|
|
|
|
|
"""
|
|
|
|
|
Autopartition maker
|
|
|
|
|
"""
|
|
|
|
|
def recreatePartitionTable(self,table,device,scheme,memory,rootsize):
|
|
|
|
|
def recreatePartitionTable(self,table,device,data):
|
|
|
|
|
"""
|
|
|
|
|
"""
|
|
|
|
|
mapDispatch = {'dos':self.recreatePartitionTableDos,
|
|
|
|
|
'gpt':self.recreatePartitionTableGpt}
|
|
|
|
|
if table in mapDispatch:
|
|
|
|
|
mapDispatch[table](device,scheme,memory,rootsize)
|
|
|
|
|
mapDispatch[table](device,data)
|
|
|
|
|
else:
|
|
|
|
|
raise AutoPartitionError(
|
|
|
|
|
_('Autopartitioning for %s is not supported')%table)
|
|
|
|
@ -88,15 +88,16 @@ class AutoPartition:
|
|
|
|
|
WRITE_AND_QUIT = "w\nq\n"
|
|
|
|
|
|
|
|
|
|
fdiskProg = getProgPath('/sbin/fdisk')
|
|
|
|
|
fdisk = process(fdiskProg,device)
|
|
|
|
|
fdisk = process(fdiskProg,device[0])
|
|
|
|
|
fdisk.write(NEW_PARTITION_TABLE)
|
|
|
|
|
num = 1
|
|
|
|
|
for size in map(lambda x:Sizes.to_K(x) if x.isdigit() else x,
|
|
|
|
|
map(itemgetter(3),data)):
|
|
|
|
|
for size in map(lambda x:str(Sizes().to_K(int(x))) \
|
|
|
|
|
if x.isdigit() else x,
|
|
|
|
|
map(operator.itemgetter(3),data)):
|
|
|
|
|
if num == 4:
|
|
|
|
|
fdisk.write(NEW_EXTENDED_PARTITION+MAX_SIZE)
|
|
|
|
|
num += 1
|
|
|
|
|
size = MAX_SIZE if size == "allsize" else "+%sK\n"%size
|
|
|
|
|
size = MAX_SIZE if size == "allfree" else "+%sK\n"%size
|
|
|
|
|
if num < 4:
|
|
|
|
|
fdisk.write(NEW_PRIMARY_PARTITION+size)
|
|
|
|
|
else:
|
|
|
|
@ -106,7 +107,7 @@ class AutoPartition:
|
|
|
|
|
|
|
|
|
|
fdisk.success()
|
|
|
|
|
for waittime in (0.1,0.2,0.5,1,2,4):
|
|
|
|
|
if path.exists(device+str(num-1)):
|
|
|
|
|
if path.exists(device[0]+str(num-1)):
|
|
|
|
|
return True
|
|
|
|
|
else:
|
|
|
|
|
sleep(waittime)
|
|
|
|
@ -114,7 +115,7 @@ class AutoPartition:
|
|
|
|
|
_("Failed to found partition %s after creating partition table")
|
|
|
|
|
%dev)
|
|
|
|
|
|
|
|
|
|
def recreatePartitionTableGpt(self,device,sizes):
|
|
|
|
|
def recreatePartitionTableGpt(self,device,data):
|
|
|
|
|
"""
|
|
|
|
|
Create GPT partition table by /sbin/gdisk
|
|
|
|
|
"""
|
|
|
|
@ -125,17 +126,18 @@ class AutoPartition:
|
|
|
|
|
WRITE_AND_QUIT = "w\ny\n"
|
|
|
|
|
|
|
|
|
|
fdiskProg = getProgPath('/usr/sbin/gdisk')
|
|
|
|
|
fdisk = process(fdiskProg,device)
|
|
|
|
|
fdisk = process(fdiskProg,device[0])
|
|
|
|
|
fdisk.write(NEW_PARTITION_TABLE)
|
|
|
|
|
num = 1
|
|
|
|
|
biosBootCreated = False
|
|
|
|
|
for size in map(lambda x:Sizes.to_K(x) if x.isdigit() else x,
|
|
|
|
|
map(itemgetter(3),data)):
|
|
|
|
|
for size in map(lambda x:str(Sizes().to_K(int(x))) \
|
|
|
|
|
if x.isdigit() else x,
|
|
|
|
|
map(operator.itemgetter(3),data)):
|
|
|
|
|
if num == 4:
|
|
|
|
|
fdisk.write(NEW_BIOSBOOT_PARTITION%"+2M")
|
|
|
|
|
biosBootCreated = True
|
|
|
|
|
num += 1
|
|
|
|
|
if size == "allsize":
|
|
|
|
|
if size == "allfree":
|
|
|
|
|
if biosBootCreated:
|
|
|
|
|
size = MAX_SIZE
|
|
|
|
|
else:
|
|
|
|
@ -149,7 +151,7 @@ class AutoPartition:
|
|
|
|
|
fdisk.write(WRITE_AND_QUIT)
|
|
|
|
|
fdisk.success()
|
|
|
|
|
for waittime in (0.1,0.2,0.5,1,2,4):
|
|
|
|
|
if path.exists(device+str(num-1)):
|
|
|
|
|
if path.exists(device[0]+str(num-1)):
|
|
|
|
|
return True
|
|
|
|
|
else:
|
|
|
|
|
sleep(waittime)
|
|
|
|
@ -291,8 +293,8 @@ class VariableClAutopartitionRootSize(Variable):
|
|
|
|
|
else:
|
|
|
|
|
size = 1024*10 # in M
|
|
|
|
|
deviceSize = self.Get('cl_autopartition_device_size')
|
|
|
|
|
if Sizes.from_M(size) >= deviceSize:
|
|
|
|
|
size = max(Sizes.to_M(deviceSize),Sizes.to_M(MINROOTSIZE))
|
|
|
|
|
if Sizes().from_M(size) >= deviceSize:
|
|
|
|
|
size = max(Sizes().to_M(deviceSize),Sizes().to_M(MINROOTSIZE))
|
|
|
|
|
return str(size)
|
|
|
|
|
|
|
|
|
|
def set(self,value):
|
|
|
|
@ -318,7 +320,7 @@ class VariableClAutopartitionRootSize(Variable):
|
|
|
|
|
def check(self,value):
|
|
|
|
|
if self.Get('cl_autopartition_device') and \
|
|
|
|
|
self.Get('cl_autopartition_set') == "auto":
|
|
|
|
|
if int(value) < Sizes.to_M(MINROOTSIZE):
|
|
|
|
|
if int(value) < Sizes().to_M(MINROOTSIZE):
|
|
|
|
|
raise VariableError(
|
|
|
|
|
_("Root partition size should not be less {size}").format(
|
|
|
|
|
size="7 Gb"))
|
|
|
|
@ -571,7 +573,7 @@ class VariableClAutopartitionDeviceSize(ReadonlyVariable):
|
|
|
|
|
where='os_device_dev',
|
|
|
|
|
_in=devices))
|
|
|
|
|
# TODO: remove set 10G
|
|
|
|
|
return str(1024*1024*1024*10)
|
|
|
|
|
#return str(1024*1024*1024*10)
|
|
|
|
|
return str(reduce(operator.add,sizeDevice))
|
|
|
|
|
|
|
|
|
|
class VariableClAutopartitionFreeSize(ReadonlyVariable):
|
|
|
|
|