Рефакторинг

* импорт целого модуля device, вместо его полей
master-3.5
parent d9e1f446a1
commit fa3b455d1f

@ -39,8 +39,9 @@ from calculate.lib.utils.files import (removeDir,
MAGIC_CONTINUE, makeDirectory, MAGIC_CONTINUE, makeDirectory,
isEmpty, check_rw, calculate_exclude, isEmpty, check_rw, calculate_exclude,
PercentProgress, getProgPath, xztaropen) PercentProgress, getProgPath, xztaropen)
import calculate.lib.utils.device as device
from calculate.lib.utils.device import (detectDeviceForPartition, from calculate.lib.utils.device import (detectDeviceForPartition,
udev, countPartitions) countPartitions)
from calculate.lib.utils.tools import classproperty, Signal, traverse from calculate.lib.utils.tools import classproperty, Signal, traverse
from calculate.lib.utils.text import _u8 from calculate.lib.utils.text import _u8
from calculate.lib.variables.linux import LinuxDataVars, Linux from calculate.lib.variables.linux import LinuxDataVars, Linux
@ -1180,9 +1181,9 @@ class PartitionDistributive(Distributive):
elif deviceName == "": elif deviceName == "":
return True return True
fdiskProg, gdiskProg = checkUtils('/sbin/fdisk', '/usr/sbin/gdisk') fdiskProg, gdiskProg = checkUtils('/sbin/fdisk', '/usr/sbin/gdisk')
partitionNumber = \ info = device.udev.get_device_info(name=dev)
udev.get_device_info(name=dev).get('ID_PART_ENTRY_NUMBER', '') or \ partitionNumber = (info.get('ID_PART_ENTRY_NUMBER','') or
udev.get_device_info(name=dev).get('UDISKS_PARTITION_NUMBER', '') info.get('UDISKS_PARTITION_NUMBER', ''))
devicePartitionCount = countPartitions(deviceName) devicePartitionCount = countPartitions(deviceName)
if deviceName and not partitionNumber: if deviceName and not partitionNumber:
raise DistributiveError( raise DistributiveError(

@ -31,8 +31,9 @@ from calculate.lib.utils.files import (pathJoin,
process, listDirectory, process, listDirectory,
checkUtils, readFile, find, copyWithPath, checkUtils, readFile, find, copyWithPath,
readLinesFile, getProgPath) readLinesFile, getProgPath)
from calculate.lib.utils.device import (detectDeviceForPartition, sysfs, import calculate.lib.utils.device as device
udev, lvm, countPartitions) from calculate.lib.utils.device import (detectDeviceForPartition,
countPartitions)
from datavars import DataVarsInstall from datavars import DataVarsInstall
from calculate.install.variables.autopartition import AutoPartition from calculate.install.variables.autopartition import AutoPartition
@ -59,9 +60,9 @@ class Install(MethodsInterface):
def __init__(self): def __init__(self):
self.clVars = None self.clVars = None
# refresh information about LVM # refresh information about LVM
lvm.refresh() device.lvm.refresh()
# refresh information about device in udevadm info # refresh information about device in udevadm info
udev.refresh() device.udev.refresh()
def initVars(self, datavars=None): def initVars(self, datavars=None):
"""Primary initialization of variables""" """Primary initialization of variables"""
@ -113,10 +114,10 @@ class Install(MethodsInterface):
partition_table = self.clVars.Select('os_device_table', partition_table = self.clVars.Select('os_device_table',
where='os_device_dev', where='os_device_dev',
eq=disk, limit=1) eq=disk, limit=1)
info = device.udev.get_device_info(name=partition)
partition_number = ( partition_number = (
udev.get_device_info(name=partition).get('ID_PART_ENTRY_NUMBER', '') or info.get('ID_PART_ENTRY_NUMBER', '') or
udev.get_device_info(name=partition).get('UDISKS_PARTITION_NUMBER', '') info.get('UDISKS_PARTITION_NUMBER', ''))
)
device_partition_count = countPartitions(device_name) device_partition_count = countPartitions(device_name)
if device_name and not partition_number: if device_name and not partition_number:
@ -288,7 +289,7 @@ class Install(MethodsInterface):
where="os_install_disk_mount", where="os_install_disk_mount",
eq="/boot/efi", limit=1) eq="/boot/efi", limit=1)
if efi_disk: if efi_disk:
efi_uuid = udev.get_device_info( efi_uuid = device.udev.get_device_info(
name=efi_disk).get("ID_PART_ENTRY_UUID", "") name=efi_disk).get("ID_PART_ENTRY_UUID", "")
if efi_uuid: if efi_uuid:
p_efibootmgr = process(efi_boot_mgr, "-v") p_efibootmgr = process(efi_boot_mgr, "-v")
@ -420,9 +421,10 @@ class Install(MethodsInterface):
where='os_disk_mount', where='os_disk_mount',
eq='/', limit=1) eq='/', limit=1)
try: try:
sysname = udev.get_syspath(name=root_dev) sysname = device.udev.get_syspath(name=root_dev)
if sysfs.exists(sysname, sysfs.Path.BlockScheduler): if device.sysfs.exists(sysname, device.sysfs.Path.BlockScheduler):
sysfs.write(sysname, sysfs.Path.BlockScheduler, scheduler) device.sysfs.write(
sysname, device.sysfs.Path.BlockScheduler, scheduler)
except Exception: except Exception:
raise InstallError(_("Unable to change the I/O scheduler")) raise InstallError(_("Unable to change the I/O scheduler"))
return True return True

@ -23,7 +23,7 @@ import glob
from calculate.lib.datavars import Variable, VariableError, ReadonlyVariable from calculate.lib.datavars import Variable, VariableError, ReadonlyVariable
from calculate.lib.utils.portage import isPkgInstalled from calculate.lib.utils.portage import isPkgInstalled
from calculate.lib.utils.files import readFile from calculate.lib.utils.files import readFile
from calculate.lib.utils.device import sysfs import calculate.lib.utils.device as device
from calculate.lib.utils.common import (getVideoFromXorgLog, from calculate.lib.utils.common import (getVideoFromXorgLog,
getVideoFromXorgConf, getVideoFromXorgConf,
getVideoFromCmdLine, getVideoFromCmdLine,
@ -226,7 +226,8 @@ class VariableOsInstallX11VideoDrv(VideoVariable):
return self.default_video return self.default_video
else: else:
for drv in map(lambda x: x[0], self.choice()): for drv in map(lambda x: x[0], self.choice()):
refcnt = sysfs.read(sysfs.Path.Module, drv, "refcnt").strip() refcnt = device.sysfs.read(
device.sysfs.Path.Module, drv, "refcnt").strip()
if refcnt.isdigit() and int(refcnt) > 0: if refcnt.isdigit() and int(refcnt) > 0:
return {'i915': 'intel'}.get(drv, drv) return {'i915': 'intel'}.get(drv, drv)
else: else:

@ -21,7 +21,8 @@ from time import sleep
from calculate.lib.datavars import (Variable, VariableError, from calculate.lib.datavars import (Variable, VariableError,
VariableInterface, VariableInterface,
ReadonlyVariable, ReadonlyTableVariable) ReadonlyVariable, ReadonlyTableVariable)
from calculate.lib.utils.device import (humanreadableSize, udev) import calculate.lib.utils.device as device
from calculate.lib.utils.device import humanreadableSize
from calculate.lib.utils.files import (readLinesFile, process, getProgPath) from calculate.lib.utils.files import (readLinesFile, process, getProgPath)
from calculate.install.fs_manager import FileSystemManager from calculate.install.fs_manager import FileSystemManager
from calculate.lib.utils.tools import Sizes from calculate.lib.utils.tools import Sizes
@ -98,7 +99,7 @@ class AutoPartition(object):
Autopartition maker Autopartition maker
""" """
def recreateSpace(self, table, device, data, lvm, vgname, bios_grub, def recreateSpace(self, table, dev, data, lvm, vgname, bios_grub,
bios_grub_size): bios_grub_size):
""" """
Recreate disk space by table device data lvm flag and vgname Recreate disk space by table device data lvm flag and vgname
@ -111,26 +112,26 @@ class AutoPartition(object):
vgname lvm Volume Group Name vgname lvm Volume Group Name
""" """
if lvm: if lvm:
self.recreateLvm(table, device, data, vgname, bios_grub, self.recreateLvm(table, dev, data, vgname, bios_grub,
bios_grub_size) bios_grub_size)
else: else:
self.recreatePartitionTable(table, device, data, bios_grub, self.recreatePartitionTable(table, dev, data, bios_grub,
bios_grub_size) bios_grub_size)
udev.refresh() device.udev.refresh()
def recreatePartitionTable(self, table, device, data, bios_grub, def recreatePartitionTable(self, table, dev, data, bios_grub,
bios_grub_size): bios_grub_size):
""" """
""" """
mapDispatch = {'dos': self.recreatePartitionTableDos, mapDispatch = {'dos': self.recreatePartitionTableDos,
'gpt': self.recreatePartitionTableGpt} 'gpt': self.recreatePartitionTableGpt}
if table in mapDispatch: if table in mapDispatch:
mapDispatch[table](device, data, bios_grub, bios_grub_size) mapDispatch[table](dev, data, bios_grub, bios_grub_size)
else: else:
raise AutopartitionError( raise AutopartitionError(
_('Autopartitioning for %s is not supported') % table) _('Autopartitioning for %s is not supported') % table)
def recreatePartitionTableDos(self, device, data, bios_grub, def recreatePartitionTableDos(self, dev, data, bios_grub,
bios_grub_size): bios_grub_size):
""" """
Create DOS partition table by /sbin/fdisk Create DOS partition table by /sbin/fdisk
@ -143,7 +144,7 @@ class AutoPartition(object):
WRITE_AND_QUIT = "w\nq\n" WRITE_AND_QUIT = "w\nq\n"
fdiskProg = getProgPath('/sbin/fdisk') fdiskProg = getProgPath('/sbin/fdisk')
fdisk = process(fdiskProg, device[0]) fdisk = process(fdiskProg, dev[0])
fdisk.write(NEW_PARTITION_TABLE) fdisk.write(NEW_PARTITION_TABLE)
num = 1 num = 1
for size in map(lambda x: str(Sizes().to_K(int(x))) \ for size in map(lambda x: str(Sizes().to_K(int(x))) \
@ -161,11 +162,11 @@ class AutoPartition(object):
fdisk.write(WRITE_AND_QUIT) fdisk.write(WRITE_AND_QUIT)
fdisk.success() fdisk.success()
# ожидаение появления устройств ({device}{partnum} или {device}p{partnum}) # ожидаение появления устройств ({dev}{partnum} или {dev}p{partnum})
self._waitDevice("%s%s"%(device[0],str(num - 1)), self._waitDevice("%s%s"%(dev[0],str(num - 1)),
"%sp%s"%(device[0],str(num - 1))) "%sp%s"%(dev[0],str(num - 1)))
def recreatePartitionTableGpt(self, device, data, bios_grub=True, def recreatePartitionTableGpt(self, dev, data, bios_grub=True,
bios_grub_size=0): bios_grub_size=0):
""" """
Create GPT partition table by /sbin/gdisk Create GPT partition table by /sbin/gdisk
@ -180,7 +181,7 @@ class AutoPartition(object):
BIOS_BOOT_PART_SIZE = "%dM" % (int(bios_grub_size) / Sizes.M) BIOS_BOOT_PART_SIZE = "%dM" % (int(bios_grub_size) / Sizes.M)
fdiskProg = getProgPath('/usr/sbin/gdisk') fdiskProg = getProgPath('/usr/sbin/gdisk')
fdisk = process(fdiskProg, device[0]) fdisk = process(fdiskProg, dev[0])
fdisk.write(NEW_PARTITION_TABLE) fdisk.write(NEW_PARTITION_TABLE)
num = 1 num = 1
biosBootCreated = not bios_grub biosBootCreated = not bios_grub
@ -205,9 +206,9 @@ class AutoPartition(object):
fdisk.write(NEW_BIOSBOOT_PARTITION % "") fdisk.write(NEW_BIOSBOOT_PARTITION % "")
fdisk.write(WRITE_AND_QUIT) fdisk.write(WRITE_AND_QUIT)
fdisk.success() fdisk.success()
# ожидаение появления устройств ({device}{partnum} или {device}p{partnum}) # ожидаение появления устройств ({dev}{partnum} или {dev}p{partnum})
self._waitDevice("%s%s"%(device[0],str(num - 1)), self._waitDevice("%s%s"%(dev[0],str(num - 1)),
"%sp%s"%(device[0],str(num - 1))) "%sp%s"%(dev[0],str(num - 1)))
def _waitDevice(self, *devices): def _waitDevice(self, *devices):
""" """

@ -29,10 +29,11 @@ from calculate.lib.datavars import (TableVariable, Variable, VariableError,
ReadonlyVariable, ReadonlyTableVariable, ReadonlyVariable, ReadonlyTableVariable,
SourceReadonlyVariable, VariableInterface, SourceReadonlyVariable, VariableInterface,
HumanReadable) HumanReadable)
import calculate.lib.utils.device as device
from calculate.lib.utils.device import (getDeviceType, from calculate.lib.utils.device import (getDeviceType,
getPartitionType, getPartitionDevice, getPartitionType, getPartitionDevice,
raid, lvm, getPartitionSize, getPartitionSize,
humanreadableSize, udev, sysfs, humanreadableSize,
getUUIDDict, getCommonDeviceName) getUUIDDict, getCommonDeviceName)
from calculate.install.variables.autopartition import Sizes from calculate.install.variables.autopartition import Sizes
from calculate.lib.utils.files import (listDirectory, pathJoin, readFile, from calculate.lib.utils.files import (listDirectory, pathJoin, readFile,
@ -53,27 +54,27 @@ class DeviceHelper(VariableInterface):
def getBlockDevices(self): def getBlockDevices(self):
"""Get interest devices from sys block path""" """Get interest devices from sys block path"""
return filter(self.rePassDevice.search, return filter(self.rePassDevice.search,
udev.get_block_devices()) device.udev.get_block_devices())
def separateDevice(self, device): def separateDevice(self, dev):
""" """
Separate device word and number on tuple Separate device word and number on tuple
Using for sort. (Example: sda2 ("sda",2), md5p1 ("md",5,"p",1) Using for sort. (Example: sda2 ("sda",2), md5p1 ("md",5,"p",1)
""" """
return map(lambda x: int(x) if x.isdigit() else x, return map(lambda x: int(x) if x.isdigit() else x,
re.findall('\d+|\D+', device)) re.findall('\d+|\D+', dev))
def mapUdevProperty(self, var, prop, default): def mapUdevProperty(self, var, prop, default):
"""Get each element from var through udev [prop]""" """Get each element from var through udev [prop]"""
return map(lambda x: udev.get_device_info(name=x).get(prop, default), return [device.udev.get_device_info(name=x).get(prop, default)
self.Get(var)) for x in self.Get(var)]
def getPerfectName(self, device, defaultValue=None): def getPerfectName(self, dev, defaultValue=None):
""" """
Get dev name or human-readable lvm name Get dev name or human-readable lvm name
""" """
info = udev.get_device_info(name=device) info = device.udev.get_device_info(name=dev)
if 'DM_VG_NAME' in info and 'DM_LV_NAME' in info: if 'DM_VG_NAME' in info and 'DM_LV_NAME' in info:
lvmDeviceName = '/dev/{vg}/{lv}'.format(vg=info['DM_VG_NAME'], lvmDeviceName = '/dev/{vg}/{lv}'.format(vg=info['DM_VG_NAME'],
lv=info['DM_LV_NAME']) lv=info['DM_LV_NAME'])
@ -84,11 +85,11 @@ class DeviceHelper(VariableInterface):
else: else:
return defaultValue return defaultValue
def getLvmName(self, device): def getLvmName(self, dev):
""" """
Get lvm name Get lvm name
""" """
return self.getPerfectName(device, defaultValue="") return self.getPerfectName(dev, defaultValue="")
####################################################### #######################################################
@ -137,8 +138,9 @@ class VariableOsDeviceDev(DeviceHelper, ReadonlyVariable):
# get devices from block sys directories(discard mem,sr,loop and other) # get devices from block sys directories(discard mem,sr,loop and other)
devices = (x for x in self.getBlockDevices() if x.count('/') == 2) devices = (x for x in self.getBlockDevices() if x.count('/') == 2)
devnames = udev.syspath_to_devname( devnames = device.udev.syspath_to_devname(
x for x in devices if udev.is_device(udev.get_device_info(x))) x for x in devices
if device.udev.is_device(device.udev.get_device_info(x)))
return list(sorted((x for x in devnames), return list(sorted((x for x in devnames),
key=self.separateDevice)) key=self.separateDevice))
@ -161,7 +163,7 @@ class VariableOsDeviceDev(DeviceHelper, ReadonlyVariable):
self.parent.Invalidate(self.name) self.parent.Invalidate(self.name)
self.parent.Invalidate('os_install_disk_uuid') self.parent.Invalidate('os_install_disk_uuid')
self.parent.Invalidate('os_disk_dev') self.parent.Invalidate('os_disk_dev')
udev.clear_cache() device.udev.clear_cache()
except OSError as e: except OSError as e:
pass pass
@ -172,11 +174,11 @@ class VariableOsDeviceType(ReadonlyVariable):
""" """
type = "list" type = "list"
def getType(self, device): def getType(self, dev):
device_name = path.basename(device) device_name = path.basename(dev)
if device_name in self.usbdevices: if device_name in self.usbdevices:
if sysfs.read(sysfs.Path.Block,device_name, if device.sysfs.read(device.sysfs.Path.Block,device_name,
"removable").strip() == 1: "removable").strip() == 1:
return "flash" return "flash"
else: else:
return "usb-hdd" return "usb-hdd"
@ -247,10 +249,10 @@ class VariableOsDeviceSsdSet(ReadonlyVariable):
def get(self): def get(self):
"""Get device partition table""" """Get device partition table"""
def isSsd(device, name): def isSsd(dev, name):
prop = udev.get_device_info(name=device) prop = device.udev.get_device_info(name=dev)
rpm = prop.get(self.udev_property, None) rpm = prop.get(self.udev_property, None)
if (any(x in device for x in self.devnames) if (any(x in dev for x in self.devnames)
or rpm == "0" or any(x in name for x in self.ssd_names)): or rpm == "0" or any(x in name for x in self.ssd_names)):
return "on" return "on"
else: else:
@ -271,8 +273,8 @@ class VariableOsDeviceSyspath(ReadonlyVariable):
def get(self): def get(self):
"""Get device partition table""" """Get device partition table"""
def getSysPath(device): def getSysPath(dev):
prop = udev.get_device_info(name=device) prop = device.udev.get_device_info(name=dev)
syspath = prop.get(self.udev_property, "") syspath = prop.get(self.udev_property, "")
return syspath return syspath
@ -310,12 +312,12 @@ class VariableOsDeviceTable(ReadonlyVariable):
""" """
type = "list" type = "list"
def getTableByChild(self, device): def getTableByChild(self, dev):
"""Get table by child partitions""" """Get table by child partitions"""
syspath = udev.get_syspath(name=device) syspath = device.udev.get_syspath(name=dev)
shortname = path.basename(device) shortname = path.basename(dev)
for child in sysfs.glob(syspath, "%s*" % shortname): for child in device.sysfs.glob(syspath, "%s*" % shortname):
udevinfo = udev.get_device_info(path=child) udevinfo = device.udev.get_device_info(path=child)
map_names = {'mbr': 'dos', map_names = {'mbr': 'dos',
'msdos': 'dos'} 'msdos': 'dos'}
table = (udevinfo.get('ID_PART_ENTRY_SCHEME', '') or table = (udevinfo.get('ID_PART_ENTRY_SCHEME', '') or
@ -328,16 +330,16 @@ class VariableOsDeviceTable(ReadonlyVariable):
autopartition = self.Get('cl_autopartition_set') == 'on' autopartition = self.Get('cl_autopartition_set') == 'on'
autoDevice = self.Get('cl_autopartition_device') autoDevice = self.Get('cl_autopartition_device')
def getTable(device): def getTable(dev):
prop = udev.get_device_info(name=device) prop = device.udev.get_device_info(name=dev)
return prop.get('ID_PART_TABLE_TYPE', return prop.get('ID_PART_TABLE_TYPE',
self.getTableByChild(device)) self.getTableByChild(dev))
def getByAutopartition(device): def getByAutopartition(dev):
if autopartition and autoDevice == device: if autopartition and autoDevice == dev:
return self.Get('cl_autopartition_table') return self.Get('cl_autopartition_table')
else: else:
return getTable(device) return getTable(dev)
return map(getByAutopartition, return map(getByAutopartition,
self.Get('os_device_dev')) self.Get('os_device_dev'))
@ -353,11 +355,11 @@ class VariableOsDeviceName(ReadonlyVariable):
'mmcblk': 'Multimedia Card' 'mmcblk': 'Multimedia Card'
} }
def getName(self, device): def getName(self, dev):
devicepath = udev.get_syspath(name=device) devicepath = device.udev.get_syspath(name=dev)
if devicepath: if devicepath:
vendor = sysfs.read(devicepath, "device/vendor").strip() vendor = device.sysfs.read(devicepath, "device/vendor").strip()
model = sysfs.read(devicepath, "device/model").strip() model = device.sysfs.read(devicepath, "device/model").strip()
if vendor or model: if vendor or model:
return ("%s %s" % return ("%s %s" %
(vendor, model)).strip() (vendor, model)).strip()
@ -424,7 +426,7 @@ class VariableOsDiskDev(DeviceHelper, ReadonlyVariable):
disks = self.getBlockDevices() disks = self.getBlockDevices()
parents = {re_parent.search(x).group() parents = {re_parent.search(x).group()
for x in disks if x.count("/") > 2} for x in disks if x.count("/") > 2}
dev_names = udev.syspath_to_devname( dev_names = device.udev.syspath_to_devname(
(x for x in disks if x not in parents), (x for x in disks if x not in parents),
dropempty=False) dropempty=False)
return list(sorted((x for x in dev_names), key=self.separateDevice)) return list(sorted((x for x in dev_names), key=self.separateDevice))
@ -472,10 +474,10 @@ class VariableOsDiskFormat(ReadonlyVariable):
"""Get current disk filesystem""" """Get current disk filesystem"""
fstab = FStab('/etc/fstab', devs=self.Get('os_disk_dev')) fstab = FStab('/etc/fstab', devs=self.Get('os_disk_dev'))
def getFormat(device): def getFormat(dev):
prop = udev.get_device_info(name=device) prop = device.udev.get_device_info(name=dev)
return prop.get('FSTAB_TYPE') or \ return prop.get('FSTAB_TYPE') or \
fstab.getBy(what=fstab.TYPE, eq=device) or \ fstab.getBy(what=fstab.TYPE, eq=dev) or \
prop.get('ID_FS_TYPE', '') prop.get('ID_FS_TYPE', '')
return map(getFormat, return map(getFormat,
@ -506,18 +508,18 @@ class VariableOsDiskType(ReadonlyVariable):
lvmUsedDisks[diskName])) lvmUsedDisks[diskName]))
return diskName, diskType return diskName, diskType
for device, diskType in types: for dev, diskType in types:
prop = udev.get_device_info(name=device) prop = device.udev.get_device_info(name=dev)
if "raid" in diskType: if "raid" in diskType:
for x in raid.devices(prop.get('DEVPATH', '')): for x in device.raid.devices(prop.get('DEVPATH', '')):
raidUsedDisks[x] = device raidUsedDisks[x] = dev
if diskType.endswith("lvm"): if diskType.endswith("lvm"):
for x in lvm.used_partitions(prop.get('DM_VG_NAME', ''), for x in device.lvm.used_partitions(prop.get('DM_VG_NAME', ''),
prop.get('DM_LV_NAME', '')): prop.get('DM_LV_NAME', '')):
if x in lvmUsedDisks: if x in lvmUsedDisks:
lvmUsedDisks[x].append(device) lvmUsedDisks[x].append(dev)
else: else:
lvmUsedDisks[x] = [device] lvmUsedDisks[x] = [dev]
return map(lambda x: x[1], return map(lambda x: x[1],
map(forMember, map(forMember,
types)) types))
@ -571,9 +573,9 @@ class VariableOsDiskParent(ReadonlyVariable):
def get(self): def get(self):
"""Get disk parent""" """Get disk parent"""
return map(getPartitionDevice, return [getPartitionDevice(x)
map(lambda x: udev.get_device_info(name=x).get('DEVPATH', ''), for x in (device.udev.get_device_info(name=y).get('DEVPATH', '')
self.Get('os_disk_dev'))) for y in self.Get("os_disk_dev"))]
class VariableOsDiskId(DeviceHelper, ReadonlyVariable): class VariableOsDiskId(DeviceHelper, ReadonlyVariable):
@ -608,8 +610,8 @@ class VariableOsDiskGrub(ReadonlyVariable):
self.Get('os_device_map'))) self.Get('os_device_map')))
def getGrubMap(devParent): def getGrubMap(devParent):
device, parent = devParent dev, parent = devParent
prop = udev.get_device_info(name=device) prop = device.udev.get_device_info(name=dev)
partnum = int(prop.get('ID_PART_ENTRY_NUMBER', 0)) partnum = int(prop.get('ID_PART_ENTRY_NUMBER', 0))
if parent in devicesMap.keys() and partnum: if parent in devicesMap.keys() and partnum:
return "%s,%d" % (devicesMap[parent], partnum - 1) return "%s,%d" % (devicesMap[parent], partnum - 1)
@ -633,7 +635,8 @@ class VariableOsDiskPart(ReadonlyVariable):
return \ return \
map(lambda x: x[0] if x[1] else "", map(lambda x: x[0] if x[1] else "",
map(lambda x: ( map(lambda x: (
getPartitionType(udev.get_device_info(name=x[0])), x[1]), getPartitionType(
device.udev.get_device_info(name=x[0])), x[1]),
self.ZipVars('os_disk_dev', 'os_disk_parent'))) self.ZipVars('os_disk_dev', 'os_disk_parent')))
@ -673,8 +676,8 @@ class VariableOsDiskOptions(ReadonlyVariable):
def get(self): def get(self):
fstab = FStab('/etc/fstab', devs=self.Get('os_disk_dev')) fstab = FStab('/etc/fstab', devs=self.Get('os_disk_dev'))
def getFormat(device): def getFormat(dev):
return fstab.getBy(what=fstab.OPTS, eq=device) return fstab.getBy(what=fstab.OPTS, eq=dev)
return map(getFormat, return map(getFormat,
self.Get('os_disk_dev')) self.Get('os_disk_dev'))
@ -885,9 +888,9 @@ class VariableOsLocationSource(LocationHelper, DeviceHelper, Variable):
########################### ###########################
disks = filter(lambda x: x.startswith('/dev/'), value) disks = filter(lambda x: x.startswith('/dev/'), value)
# get original /dev names # get original /dev names
cnDisks = map(lambda x: udev.get_device_info(name=x).get('DEVNAME', x), cnDisks = (device.udev.get_device_info(name=x).get('DEVNAME', x)
disks) for x in disks)
wrongDevices = list(set(cnDisks) - \ wrongDevices = list(set(cnDisks) -
set(self.fixOsDiskDev())) set(self.fixOsDiskDev()))
if wrongDevices: if wrongDevices:
raise VariableError(_("Wrong device '%s'") % wrongDevices[0]) raise VariableError(_("Wrong device '%s'") % wrongDevices[0])
@ -2036,10 +2039,10 @@ class VariableOsInstallRootType(LocationHelper, Variable):
return "flash" return "flash"
else: else:
rootdev = self.Get('os_install_root_dev') rootdev = self.Get('os_install_root_dev')
device = getPartitionDevice( dev = getPartitionDevice(
udev.get_device_info(name=rootdev).get('DEVPATH', '')) device.udev.get_device_info(name=rootdev).get('DEVPATH', ''))
device_type = self.Select( device_type = self.Select(
'os_device_type', where='os_device_dev', eq=device, limit=1) 'os_device_type', where='os_device_dev', eq=dev, limit=1)
if device_type in ("usb-hdd", "flash"): if device_type in ("usb-hdd", "flash"):
return "usb-hdd" return "usb-hdd"
return "hdd" return "hdd"

@ -29,7 +29,8 @@ from calculate.lib.utils.ip import (getInterfaces, getIp, getMask, getMac,
cidrToMask, maskToCidr, getIpNet, isDhcpIp, cidrToMask, maskToCidr, getIpNet, isDhcpIp,
checkIp, checkMask, isSlaveInterface, checkIp, checkMask, isSlaveInterface,
getOperState, getPlugged) getOperState, getPlugged)
from calculate.lib.utils.device import lspci, sysfs import calculate.lib.utils.device as device
from calculate.lib.utils.device import lspci
from calculate.lib.utils.files import (listDirectory, readLinesFile) from calculate.lib.utils.files import (listDirectory, readLinesFile)
from calculate.lib.utils import ip from calculate.lib.utils import ip
from calculate.lib.utils.portage import isPkgInstalled from calculate.lib.utils.portage import isPkgInstalled
@ -234,7 +235,7 @@ class VariableOsInstallNetName(NetHelper, ReadonlyVariable):
def getPci(interface): def getPci(interface):
pathname = path.realpath( pathname = path.realpath(
sysfs.syspath(sysfs.Path.ClassNet, interface)) device.sysfs.syspath(device.sysfs.Path.ClassNet, interface))
pci = rePci.search(pathname) pci = rePci.search(pathname)
if pci: if pci:

@ -29,7 +29,7 @@ from calculate.lib.utils.common import getPasswdUsers, getUserGroups, getGroups,
from calculate.lib.utils.common import getValueFromConfig, getValueFromCmdLine from calculate.lib.utils.common import getValueFromConfig, getValueFromCmdLine
from calculate.lib.utils.common import getUserPrimaryGroup from calculate.lib.utils.common import getUserPrimaryGroup
from calculate.lib.utils.portage import isPkgInstalled from calculate.lib.utils.portage import isPkgInstalled
from calculate.lib.utils.device import udev import calculate.lib.utils.device as device
from calculate.lib.encrypt import sha256_crypt from calculate.lib.encrypt import sha256_crypt
from calculate.core.server.admin import Admins from calculate.core.server.admin import Admins
from calculate.lib.variables.system import RootType from calculate.lib.variables.system import RootType
@ -650,7 +650,8 @@ class VariableClInstallDevFrom(Variable):
If device in calculate3.env dev_from not exists set '' If device in calculate3.env dev_from not exists set ''
""" """
if value: if value:
value = udev.get_device_info(name=value).get('DEVNAME', value) value = device.udev.get_device_info(
name=value).get('DEVNAME', value)
if value in self.Get('os_disk_dev'): if value in self.Get('os_disk_dev'):
return value return value
else: else:

Loading…
Cancel
Save