Refactoring.

netsetup
Mike Hiretsky 13 years ago
parent 2872af8f69
commit 5ebb05df1f

@ -23,7 +23,7 @@ from cl_datavars import glob_attr
from os import path
from os import readlink,access,R_OK
from cl_utils import isMount,typeFile,getTupleVersion,pathJoin,isFstabMount,\
listDirectory, getAvailableX11Drivers
listDirectory, getAvailableX11Drivers, getUUIDDict
from cl_distr import DistributiveRepository,PartitionDistributive
from cl_fill import clLocale
from operator import itemgetter
@ -166,6 +166,15 @@ class fillVars(object, glob_attr):
return device_hash
def get_os_disk_hash(self):
# check command existing
for util in ("/sbin/fdisk","/usr/sbin/gdisk","/sbin/blkid",
"/usr/sbin/parted"):
utilPath = self.getProgPath(util)
if not utilPath:
cl_overriding.printERROR(_("Command not found '%s'")%
path.basename(util))
cl_overriding.exit(1)
reSdaPart = \
re.compile("^/dev/(sd[a-z])(\d+)|/dev/(cciss/c\dd\d+)p(\d+)$")
devicesHash = self.Get('os_device_hash')
@ -194,14 +203,9 @@ class fillVars(object, glob_attr):
int(match.groups()[3])-1)
curDevice = None
# getting id
execFdisk = self.getProgPath("/sbin/fdisk")
execGdisk = self.getProgPath("/usr/sbin/gdisk")
# check on error utils path
for utilPath,name in [(execFdisk,"fdisk"),(execGdisk,"gdisk")]:
if not utilPath:
cl_overriding.printERROR(_("Command not found '%s'")%name)
cl_overriding.exit(1)
# getting id
for device in devices:
if devicesHash[device]['table'] == 'msdos':
execStr = '%s -l %s'%(execFdisk,"/dev/%s"%device)
@ -239,9 +243,6 @@ class fillVars(object, glob_attr):
floppyData = self.removeFloppy()
execProg = self.getProgPath("/usr/sbin/parted")
execStr = '%s -l'%execProg
if not execProg:
cl_overriding.printERROR(_("Command not found '%s'")%"parted")
cl_overriding.exit(1)
res = self._runos(execStr,env={"LANG":"C"})
self.restoreFloppy(floppyData)
@ -278,9 +279,6 @@ class fillVars(object, glob_attr):
disk_hash[partition]['size'] = parts[3]
# fill format, name and uuid
execStr = self.getProgPath('/sbin/blkid')
if not execStr:
cl_overriding.printERROR(_("Command not found '%s'")%"blkid")
cl_overriding.exit(1)
res = self._runos(execStr)
if res is False:
cl_overriding.printERROR(_("Cann't execute '%s'")%execStr)
@ -300,17 +298,8 @@ class fillVars(object, glob_attr):
key = blkid_hash[key]
disk_hash[dev][key] = value[1:-1]
# discard comment and empty string
devuuid = '/dev/disk/by-uuid'
if path.exists(devuuid):
mapUuidDev = dict(
map(lambda x:("UUID=%s"%os.path.basename(x),
os.path.normpath(os.path.join(devuuid,os.readlink(x)))),
filter(os.path.islink,
map(lambda x:os.path.join(devuuid,x),
listDirectory(devuuid)))))
else:
mapUuidDev = {}
mapDevUuid = dict(map(lambda x:(x[1],x[0]),mapUuidDev.items()))
mapUuidDev = getUUIDDict()
mapDevUuid = dict(zip(mapUuidDev.values(),mapUuidDev.keys()))
mountOptionsList = \
filter(lambda x: x.strip() and not x.strip().startswith('#'),
open("/etc/fstab").readlines())
@ -1236,19 +1225,8 @@ class fillVars(object, glob_attr):
return self.Get('cl_autoupdate_set')
def get_cl_install_kernel_uid(self):
uuidpath = '/dev/disk/by-uuid'
if not os.access(uuidpath,os.R_OK):
return ""
uuidDevs = filter(os.path.islink,map(lambda x: os.path.join(uuidpath,x),
listDirectory(uuidpath)))
mapDevUuid = dict(map(lambda x:(os.path.normpath(os.path.join(uuidpath,
os.readlink(x))),
os.path.basename(x)),
uuidDevs))
if self.Get('os_install_root_dev') in mapDevUuid:
return mapDevUuid[self.Get('os_install_root_dev')][:8]
else:
return ""
mapDevUuid = getUUIDDict(revers=True)
return mapDevUuid.get(self.Get('os_install_root_dev'),"")[5:13]
def get_os_nvidia_mask(self):
nvidiaeclass = pathJoin(self.Get('cl_chroot_path'),

@ -1117,9 +1117,9 @@ class cl_install(color_print, SignalInterrupt):
# detect using extended partition
extendedPartitions = map(lambda x: x[1],
filter(lambda x: x[0]=="extended",
zip(self.clVars.Get('os_disk_part'),
self.clVars.Get('os_disk_dev'))))
filter(lambda x: x[0]=="extended",
zip(self.clVars.Get('os_disk_part'),
self.clVars.Get('os_disk_dev'))))
usingExtPart = list(set(usedDevices)&set(extendedPartitions))
if usingExtPart:
self.printERROR(_("Can not use extended partition %s")%
@ -1131,7 +1131,7 @@ class cl_install(color_print, SignalInterrupt):
wrongBind = filter(lambda x:x in destMountPoints,srcMountPoints)
if wrongBind:
incompBind = filter(lambda x:x[1]==wrongBind[0],
zip(srcMountPoints,destMountPoints))
zip(srcMountPoints,destMountPoints))
self.printERROR(_("Source directory %(src)s already use "\
"for bind '%(bindSrc)s' to '%(bindDst)s'")\
%{'src':wrongBind[0],
@ -1142,7 +1142,7 @@ class cl_install(color_print, SignalInterrupt):
wrongBind = filter(lambda x:not x[0].startswith("/") or
not x[1].startswith("/") and
x[1] != "none",
zip(srcMountPoints,destMountPoints))
zip(srcMountPoints,destMountPoints))
if wrongBind:
self.printERROR(_("Incorrect mount point (bind '%(bindSrc)s' to "\
"'%(bindDst)s')")\
@ -1425,6 +1425,7 @@ class cl_install(color_print, SignalInterrupt):
return ""
def setActivePartition(self,partition):
"""TODO: don't work with GPT"""
reActive = re.compile('^%s\s*[*]'%partition)
device = filter(lambda x:x in partition,
self.clVars.Get('os_device_dev'))

Loading…
Cancel
Save