Refactoring

master3.4 3.4.1.2
Mike Khiretskiy 9 years ago
parent 6f82626d8c
commit 5bdef0490b

@ -1,6 +1,6 @@
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# Copyright 2010-2013 Calculate Ltd. http://www.calculate-linux.org
# Copyright 2010-2015 Calculate Ltd. http://www.calculate-linux.org
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -17,12 +17,13 @@
__app__ = 'calculate-install'
__version__ = '3.1.8'
import os
import sys
from calculate.lib.datavars import DataVars
from calculate.lib.cl_lang import setLocalTranslate
setLocalTranslate('cl_install3',sys.modules[__name__])
setLocalTranslate('cl_install3', sys.modules[__name__])
class DataVarsInstall(DataVars):
"""Variable class for installation"""

File diff suppressed because it is too large Load Diff

@ -1,6 +1,6 @@
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# Copyright 2010-2013 Calculate Ltd. http://www.calculate-linux.org
# Copyright 2010-2015 Calculate Ltd. http://www.calculate-linux.org
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -14,158 +14,160 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import re
import sys
import time
import traceback
from os import path
from calculate.lib.cl_lang import setLocalTranslate
setLocalTranslate('cl_install3',sys.modules[__name__])
class FileSystemManager:
setLocalTranslate('cl_install3', sys.modules[__name__])
class FileSystemManager(object):
"""Convert dict install option"""
defaultOpt = ['noatime']
defaultBindOpts = ['bind']
supportFS = {
'ext2': {'defaultopt': defaultOpt,
'format': '/sbin/mkfs.ext2',
'formatparam': '{labelparam} {device}',
'gpt': '8300',
'label': '-L {labelname}',
'ssd':[],
'msdos': '83',
'type':['hdd','usb-hdd']},
'ext3': {'defaultopt': defaultOpt,
'format': '/sbin/mkfs.ext3',
'formatparam': '{labelparam} {device}',
'gpt': '8300',
'label': '-L {labelname}',
'ssd':[],
'msdos': '83',
'type':['hdd','usb-hdd']},
'ext4': {'defaultopt': defaultOpt,
'format': '/sbin/mkfs.ext4',
'formatparam': '{labelparam} {device}',
'format': '/sbin/mkfs.ext2',
'formatparam': '{labelparam} {device}',
'gpt': '8300',
'label': '-L {labelname}',
'ssd': [],
'msdos': '83',
'type': ['hdd', 'usb-hdd']},
'ext3': {'defaultopt': defaultOpt,
'format': '/sbin/mkfs.ext3',
'formatparam': '{labelparam} {device}',
'gpt': '8300',
'label': '-L {labelname}',
'ssd': [],
'msdos': '83',
'type': ['hdd', 'usb-hdd']},
'ext4': {'defaultopt': defaultOpt,
'format': '/sbin/mkfs.ext4',
'formatparam': '{labelparam} {device}',
'gpt': '8300',
'label': '-L {labelname}',
'ssd': ['discard'],
'msdos': '83',
'type': ['hdd', 'usb-hdd']},
'reiserfs': {'defaultopt': defaultOpt,
'format': '/sbin/mkfs.reiserfs',
'formatparam': '{labelparam} -f {device}',
'gpt': '8300',
'label': '-l {labelname}',
'msdos': '83',
'ssd': [],
'type': ['hdd', 'usb-hdd']},
'btrfs': {'defaultopt': defaultOpt,
'format': '/sbin/mkfs.btrfs',
'formatparam': '{labelparam} -f {device}',
'gpt': '8300',
'label': '-L {labelname}',
'ssd':['discard'],
'msdos': '83',
'type':['hdd','usb-hdd']},
'reiserfs': {'defaultopt': defaultOpt,
'format': '/sbin/mkfs.reiserfs',
'formatparam': '{labelparam} -f {device}',
'gpt': '8300',
'label': '-l {labelname}',
'msdos': '83',
'ssd':[],
'type':['hdd','usb-hdd']},
'btrfs': {'defaultopt': defaultOpt,
'format':'/sbin/mkfs.btrfs',
'formatparam': '{labelparam} -f {device}',
'ssd': ['ssd', 'discard', 'space_cache'],
'type': ['hdd', 'usb-hdd']},
'jfs': {'defaultopt': defaultOpt,
'format': '/sbin/mkfs.jfs',
'formatparam': '{labelparam} -f {device}',
'gpt': '8300',
'label': '-L {labelname}',
'msdos': '83',
'ssd': ['discard'],
'type': ['hdd', 'usb-hdd']},
'xfs': {'defaultopt': defaultOpt,
'format': '/sbin/mkfs.xfs',
'formatparam': '{labelparam} -f {device}',
'gpt': '8300',
'label': '-L {labelname}',
'msdos': '83',
'ssd': ['discard'],
'type': ['hdd', 'usb-hdd']},
'nilfs2': {'defaultopt': defaultOpt,
'format': '/sbin/mkfs.nilfs2',
'formatparam': '{labelparam} {device}',
'gpt': '8300',
'label': '-L {labelname}',
'msdos': '83',
'ssd':['ssd','discard','space_cache'],
'type':['hdd','usb-hdd']},
'jfs': {'defaultopt': defaultOpt,
'format': '/sbin/mkfs.jfs',
'formatparam': '{labelparam} -f {device}',
'ssd': [],
'type': ['hdd', 'usb-hdd']},
'swap': {'defaultopt': ['sw'],
'format': '/sbin/mkswap',
'formatparam': '{device}',
'gpt': '8200',
'label': '',
'ssd': [],
'msdos': '82'},
'uefi': {'defaultopt': defaultOpt,
'format': '/usr/sbin/mkfs.vfat',
'formatparam': '{labelparam} -F 32 {device}',
'gpt': 'EF00',
'label': '-n {labelname}',
'msdos': '0b',
'ssd': [],
'type': ['hdd']},
'vfat': {'defaultopt': defaultOpt,
'format': '/usr/sbin/mkfs.vfat',
'formatparam': '{labelparam} -F 32 {device}',
'gpt': '0700',
'label': '-n {labelname}',
'msdos': '0b',
'ssd': ['discard'],
'type': ['flash']},
'ntfs': {'defaultopt': defaultOpt,
'format': '/usr/sbin/mkfs.ntfs',
'formatparam': '{labelparam} -FQ {device}',
'gpt': '8300',
'label': '-L {labelname}',
'msdos': '83',
'ssd':['discard'],
'type':['hdd','usb-hdd']},
'xfs': {'defaultopt': defaultOpt,
'format': '/sbin/mkfs.xfs',
'formatparam': '{labelparam} -f {device}',
'gpt': '8300',
'label': '-L {labelname}',
'msdos': '83',
'ssd':['discard'],
'type':['hdd','usb-hdd']},
'nilfs2': {'defaultopt': defaultOpt,
'format': '/sbin/mkfs.nilfs2',
'formatparam': '{labelparam} {device}',
'msdos': '7',
'ssd': [],
'compatible': ['ntfs-3g']},
'ntfs-3g': {'defaultopt': defaultOpt,
'format': '/usr/sbin/mkfs.ntfs',
'formatparam': '{labelparam} -FQ {device}',
'gpt': '8300',
'label': '-L {labelname}',
'msdos': '83',
'ssd':[],
'type':['hdd','usb-hdd']},
'swap': {'defaultopt': ['sw'],
'format': '/sbin/mkswap',
'formatparam': '{device}',
'gpt': '8200',
'label': '',
'ssd':[],
'msdos': '82'},
'uefi': {'defaultopt': defaultOpt,
'format': '/usr/sbin/mkfs.vfat',
'formatparam': '{labelparam} -F 32 {device}',
'gpt': 'EF00',
'label': '-n {labelname}',
'msdos': '0b',
'ssd':[],
'type':['hdd']},
'vfat': {'defaultopt': defaultOpt,
'format': '/usr/sbin/mkfs.vfat',
'formatparam': '{labelparam} -F 32 {device}',
'gpt': '0700',
'label': '-n {labelname}',
'msdos': '0b',
'ssd':['discard'],
'type':['flash']},
'ntfs': {'defaultopt': defaultOpt,
'format': '/usr/sbin/mkfs.ntfs',
'formatparam': '{labelparam} -FQ {device}',
'gpt': '8300',
'label': '-L {labelname}',
'msdos': '7',
'ssd':[],
'compatible':['ntfs-3g']},
'ntfs-3g': {'defaultopt': defaultOpt,
'format': '/usr/sbin/mkfs.ntfs',
'formatparam': '{labelparam} -FQ {device}',
'gpt': '8300',
'label': '-L {labelname}',
'ssd':[],
'msdos': '7',
'compatible':['ntfs']}}
'ssd': [],
'msdos': '7',
'compatible': ['ntfs']}}
default_param = {'defaultopt': defaultOpt,
'ssd': []}
default_param = {'defaultopt':defaultOpt,
'ssd':[]}
@classmethod
def firstAvailable(cls,listFS):
def firstAvailable(cls, listFS):
for fs in listFS:
if path.exists(cls.supportFS['format']):
return fs
else:
return ""
defaultFS = {'hdd':"ext4" \
if path.exists(supportFS['ext4']['format']) else \
"reiserfs" \
if path.exists(supportFS['reiserfs']['format']) else \
"ext3",
'flash':"vfat",
'usb-hdd': "ext4" \
if path.exists(supportFS['ext4']['format']) else \
"reiserfs" \
if path.exists(supportFS['reiserfs']['format']) else \
"ext3"}
defaultFS = {
'hdd': ("ext4"
if path.exists(supportFS['ext4']['format']) else
"reiserfs"
if path.exists(supportFS['reiserfs']['format']) else
"ext3"),
'flash': "vfat",
'usb-hdd': ("ext4"
if path.exists(supportFS['ext4']['format']) else
"reiserfs"
if path.exists(supportFS['reiserfs']['format']) else
"ext3")
}
@classmethod
def getDefaultOpt(cls,fs, ssd=False):
return ",".join(cls.supportFS.get(fs,cls.default_param)['defaultopt']+
(cls.supportFS.get(fs,cls.default_param)['ssd'] if ssd else []))
def getDefaultOpt(cls, fs, ssd=False):
return ",".join(cls.supportFS.get(fs, cls.default_param)['defaultopt'] +
(cls.supportFS.get(fs, cls.default_param)['ssd']
if ssd else []))
@classmethod
def checkFSForTypeMount(cls,fs,roottype,mp):
def checkFSForTypeMount(cls, fs, roottype, mp):
if mp == '/boot/efi':
if not fs in ('uefi','vfat'):
if fs not in ('uefi', 'vfat'):
return False
else:
return True
return roottype in cls.supportFS.get(fs,{}).get('type',[])
return roottype in cls.supportFS.get(fs, {}).get('type', [])

@ -1,6 +1,6 @@
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# Copyright 2010-2013 Calculate Ltd. http://www.calculate-linux.org
# Copyright 2010-2015 Calculate Ltd. http://www.calculate-linux.org
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -19,57 +19,39 @@ import re
import sys
import time
from os import path
from StringIO import StringIO
from random import choice
import string
from time import sleep
from subprocess import PIPE,STDOUT
from shutil import copy2
from calculate.lib.utils.files import (runOsCommand,pathJoin,
isMount,process,listDirectory,STDOUT,
checkUtils,readFile,find,copyWithPath,
readLinesFile)
from calculate.lib.utils.common import (appendProgramToEnvFile,
removeProgramToEnvFile, getTupleVersion,
cmpVersion,getUserPassword,
getSupportArch, getInstalledVideo )
from calculate.core.server.func import MethodsInterface
from calculate.lib.utils.files import (pathJoin,
isMount, process, listDirectory,
checkUtils, readFile, find, copyWithPath,
readLinesFile, getProgPath)
from calculate.lib.utils.device import (detectDeviceForPartition,
getUdevDeviceInfo, getLvmPartitions, refreshLVM,
refreshUdev,countPartitions)
from calculate.lib.cl_vars_share import varsShare
from calculate.lib import cl_overriding
from calculate.lib.utils import ip
from calculate.lib.datavars import VariableError
from datavars import DataVarsInstall, __version__,__app__
from calculate.install.variables.autopartition import (AutopartitionError,
AutoPartition)
from calculate.install.fs_manager import FileSystemManager
from calculate.lib.variables.locale import Locale
from calculate.lib.cl_template import Template,TemplatesError,ProgressTemplate
from calculate.lib.datavars import DataVars
from distr import (PartitionDistributive,
DistributiveError, ScratchPartitionDistributive,
MultiPartitions, FlashDistributive,
Distributive)
from calculate.lib.utils.text import tableReport
from calculate.lib.server.utils import dialogYesNo
from subprocess import Popen,PIPE,STDOUT
getUdevDeviceInfo, refreshLVM,
refreshUdev, countPartitions)
from datavars import DataVarsInstall
from calculate.install.variables.autopartition import AutoPartition
from distr import DistributiveError
from subprocess import Popen, PIPE, STDOUT
from itertools import *
class InstallError(Exception):
"""Installation Error"""
from migrate_users import migrate, currentUsers, MigrationError
from calculate.lib.encrypt import encrypt
from calculate.lib.cl_lang import setLocalTranslate,getLazyLocalTranslate
setLocalTranslate('cl_install3',sys.modules[__name__])
from migrate_users import migrate
from calculate.lib.cl_lang import setLocalTranslate, getLazyLocalTranslate, _
setLocalTranslate('cl_install3', sys.modules[__name__])
__ = getLazyLocalTranslate(_)
class Install:
"""Primary class for templates appling and system installation"""
class Install(MethodsInterface):
"""Primary class for templates applying and system installation"""
def __init__(self):
self.clVars = None
@ -78,7 +60,7 @@ class Install:
# refresh information about device in udevadm info
refreshUdev()
def initVars(self,datavars=None):
def initVars(self, datavars=None):
"""Primary initialization of variables"""
if not datavars:
self.clVars = DataVarsInstall()
@ -87,275 +69,309 @@ class Install:
else:
self.clVars = datavars
def canInstallGrub2(self,target):
def canInstallGrub2(self, target):
"""Check that system has grub2 in current and installed system"""
if self.clVars.Get('os_grub2_path'):
return bool(
filter(lambda x:x.startswith('grub-1.99') or \
x.startswith('grub-2'),
listDirectory('/var/db/pkg/sys-boot')))
filter(lambda x: (x.startswith('grub-1.99') or
x.startswith('grub-2')),
listDirectory('/var/db/pkg/sys-boot')))
return False
def prepareBoot(self,targetDistr):
def prepareBoot(self, target_distr):
"""Prepare system for boot"""
if self.clVars.Get('os_install_root_type') == "flash":
self.installSyslinuxBootloader(targetDistr)
self.installSyslinuxBootloader(target_distr)
else:
if self.canInstallGrub2(targetDistr):
self.installGrub2Bootloader(targetDistr)
if self.canInstallGrub2(target_distr):
self.installGrub2Bootloader(target_distr)
else:
self.installLegacyGrubBootloader(targetDistr)
self.installLegacyGrubBootloader(target_distr)
return True
def setActivePartition(self,partition):
def setActivePartition(self, partition):
"""
Установка активного раздела для dos и gpt таблицы разделов
"""
deviceName = detectDeviceForPartition(partition)
if deviceName is None:
device_name = detectDeviceForPartition(partition)
if device_name is None:
raise DistributiveError(
_("Failed to determine the parent device for %s")%partition)
_("Failed to determine the parent device for %s") % partition)
# device hasn't any partition
elif deviceName == "":
elif device_name == "":
return True
fdiskProg, gdiskProg, partedProg = checkUtils('/sbin/fdisk',
'/usr/sbin/gdisk','/usr/sbin/parted')
fdisk_cmd, gdisk_cmd, parted_cmd = checkUtils('/sbin/fdisk',
'/usr/sbin/gdisk',
'/usr/sbin/parted')
disk = self.clVars.Select('os_install_disk_parent',
where='os_install_disk_dev',eq=partition,
where='os_install_disk_dev', eq=partition,
limit=1)
parttable = self.clVars.Select('os_device_table',where='os_device_dev',
eq=disk,limit=1)
partitionNumber = \
getUdevDeviceInfo(name=partition).get('ID_PART_ENTRY_NUMBER','') or \
getUdevDeviceInfo(name=partition).get('UDISKS_PARTITION_NUMBER','')
devicePartitionCount = countPartitions(deviceName)
if deviceName and not partitionNumber:
partition_table = self.clVars.Select('os_device_table',
where='os_device_dev',
eq=disk, limit=1)
partition_number = (
getUdevDeviceInfo(name=partition).get('ID_PART_ENTRY_NUMBER', '') or
getUdevDeviceInfo(name=partition).get('UDISKS_PARTITION_NUMBER', '')
)
device_partition_count = countPartitions(device_name)
if device_name and not partition_number:
raise DistributiveError(
_("Failed to determine the partition number for %s")%partition)
bootFlag = "boot" if parttable == "dos" else "legacy_boot"
if parttable == "dos":
fdisk = process(fdiskProg, "-l",deviceName)
DEVICENUM,AFLAG = 0,1
changeActive = \
map(lambda x:x[DEVICENUM],
filter(lambda x:x[DEVICENUM] != partitionNumber and \
x[AFLAG] == "*" or \
x[DEVICENUM] == partitionNumber and \
not x[AFLAG] == "*",
list(map(lambda x:[str(x[0]),x[1][1].strip()],
# enumerate partitions
enumerate(filter(None,
map(lambda x:x.split()[:2],
# drop string before information about partitions
dropwhile(lambda x:not x.lstrip().startswith("Device"),
fdisk.readlines()))))))[1:]))
_("Failed to determine the partition number for %s")
% partition)
boot_flag = "boot" if partition_table == "dos" else "legacy_boot"
if partition_table == "dos":
fdisk = process(fdisk_cmd, "-l", device_name)
DEVICENUM, AFLAG = 0, 1
change_active = map(
lambda x: x[DEVICENUM],
filter(
lambda x: (x[DEVICENUM] != partition_number and
x[AFLAG] == "*" or
x[DEVICENUM] == partition_number and
not x[AFLAG] == "*"),
list(map(
lambda x: [str(x[0]), x[1][1].strip()],
# enumerate partitions
enumerate(filter(None, map(
lambda x: x.split()[:2],
# drop string before information about partitions
dropwhile(
lambda x: not x.lstrip().startswith(
"Device"),
fdisk.readlines()))))))[1:]))
else:
parted = process(partedProg, "-m",deviceName,"print")
DEVICENUM,FLAGS = 0,6
changeActive = \
map(lambda x:x[DEVICENUM],
filter(lambda x:x[DEVICENUM] != partitionNumber and \
bootFlag in x[FLAGS].strip(';').split(', ') or \
x[DEVICENUM] == partitionNumber and \
not bootFlag in x[FLAGS].strip(';').split(', '),
filter(lambda x:len(x)>=7,
map(lambda x:x.split(':'),
parted.readlines()[2:]))))
if not changeActive:
parted = process(parted_cmd, "-m", device_name, "print")
DEVICENUM, FLAGS = 0, 6
change_active = map(
lambda x: x[DEVICENUM], filter(
lambda x: (x[DEVICENUM] != partition_number and
boot_flag in x[FLAGS].strip(';').split(', ') or
x[DEVICENUM] == partition_number and
boot_flag not in
x[FLAGS].strip(';').split(', ')),
filter(lambda x: len(x) >= 7,
map(lambda x: x.split(':'),
parted.readlines()[2:]))))
if not change_active:
return True
if parttable == "dos":
pipe = Popen([fdiskProg,deviceName],
stdin=PIPE, stdout=PIPE,stderr=PIPE)
for partnum in changeActive:
pipe.stdin.write("a\n%s\n"%partnum)
if partition_table == "dos":
pipe = Popen([fdisk_cmd, device_name],
stdin=PIPE, stdout=PIPE, stderr=PIPE)
for part_num in change_active:
pipe.stdin.write("a\n%s\n" % part_num)
pipe.stdin.write("w\n")
pipe.stdin.close()
pipe.wait()
elif parttable == "gpt":
pipe = Popen([gdiskProg,deviceName],
stdin=PIPE, stdout=PIPE,stderr=PIPE)
if devicePartitionCount > 1:
elif partition_table == "gpt":
pipe = Popen([gdisk_cmd, device_name],
stdin=PIPE, stdout=PIPE, stderr=PIPE)
if device_partition_count > 1:
pipe.stdin.write("x\n")
for partnum in changeActive:
pipe.stdin.write("a\n%s\n2\n\n"%partnum)
for part_num in change_active:
pipe.stdin.write("a\n%s\n2\n\n" % part_num)
pipe.stdin.write("w\nY\n")
else:
pipe.stdin.write("x\na\n2\n\nw\nY\n")
pipe.stdin.close()
pipe.wait()
for waittime in (0.1,0.2,0.5,1,2,4):
for wait_time in (0.1, 0.2, 0.5, 1, 2, 4):
if path.exists(partition):
return True
else:
sleep(waittime)
sleep(wait_time)
raise InstallError(
_("Failed to find partition %s after changing the activity")%
partition)
_("Failed to find partition %s after changing the activity") %
partition)
def installSyslinuxBootloader(self,target):
def installSyslinuxBootloader(self, target):
"""
Установить syslinux загрузчик (используется для flash)
"""
if not self.clVars.Get('os_install_mbr'):
return
# прописать MBR
ddProcess = process("/bin/dd","if=/usr/share/syslinux/mbr.bin",
"of=%s"%self.clVars.Get('os_install_mbr')[0],
stderr=STDOUT)
if ddProcess.failed():
dd_process = process("/bin/dd", "if=/usr/share/syslinux/mbr.bin",
"of=%s" % self.clVars.Get('os_install_mbr')[0],
stderr=STDOUT)
if dd_process.failed():
raise DistributiveError(
_("Failed to write the master boot record\n%s")%
ddProcess.read())
_("Failed to write the master boot record\n%s") %
dd_process.read())
target.close()
# выполнить установку syslinux загрузчика
installRootDev = self.clVars.Get('os_install_root_dev')
syslinuxProcess = process("/usr/bin/syslinux",
installRootDev, stderr=STDOUT)
if syslinuxProcess.failed():
raise DistributiveError(_("Failed to install syslinux\n%s")%
syslinuxProcess.read())
install_root_dev = self.clVars.Get('os_install_root_dev')
syslinux_process = process("/usr/bin/syslinux",
install_root_dev, stderr=STDOUT)
if syslinux_process.failed():
raise DistributiveError(_("Failed to install syslinux\n%s") %
syslinux_process.read())
# установить загрузочный раздел активным
return self.setActivePartition(self.clVars.Get('os_install_root_dev'))
def installGrub2Bootloader(self,target):
def installGrub2Bootloader(self, target):
"""
Установка GRUB2 загрузчика
"""
# проверить наличие grub2
cmdGrubInstall = self.clVars.Get('os_grub2_path')
if not cmdGrubInstall:
cmd_grub_install = self.clVars.Get('os_grub2_path')
if not cmd_grub_install:
raise DistributiveError(_("Failed to install the bootloader"))
process("sync").success()
# если установка GRUB2 производится на текущую систему
# загруженную в builder режиме
if self.clVars.Get('os_install_scratch') == "on" and \
self.clVars.Get('cl_action') != "system":
prefixBoot = "/mnt/scratch"
if (self.clVars.Get('os_install_scratch') == "on" and
self.clVars.Get('cl_action') != "system"):
prefix_boot = "/mnt/scratch"
else:
prefixBoot = "/"
prefix_boot = "/"
# установка UEFI
if self.clVars.GetBool('os_install_uefi_set'):
grubParams = ["--boot-directory=%s"%pathJoin(prefixBoot,
target.getBootDirectory()),
"--target=x86_64-efi",
"--efi-directory=%s"%
target.getEfiDirectory(),
"--force"]
# в случае установки на usb-hdd EFI загрузчик не прописывается
# в efivars
if self.clVars.Get('os_install_root_type') == 'usb-hdd':
grubParams.append("--removable")
if self.clVars.Get('cl_action') != "system" and \
not isMount('/boot/efi'):
raise DistributiveError(_("Failed to install the bootloader. "
"/boot/efi is not mounted."))
grubProcess = process(cmdGrubInstall,
*grubParams, stderr=STDOUT,envdict=os.environ)
if grubProcess.failed():
raise DistributiveError(_("Failed to install the bootloader"))
# проверяем успешность создания загрузочной записи
# если среди загрузочных записей отсутствует запись
# calculate и dmesg содержит сообщение об ошибке efivars -
# запись создать не удалось
efiBootMgr = varsShare().getProgPath('/usr/sbin/efibootmgr')
dmesg = varsShare().getProgPath('/bin/dmesg')
if efiBootMgr and dmesg:
if not re.search('Boot.*calculate',
process(efiBootMgr).read(),re.M) and \
re.search('efivars.*set_variable.*failed',
process(dmesg).read(),re.M):
raise DistributiveError(
_("Failed to create the UEFI boot record"))
self.install_grub_uefi(cmd_grub_install, prefix_boot, target)
# не UEFI установка
else:
# получить загрузочный раздел (если есть /boot, то
# он является загрузочным иначе корень)
for bootPath in ("/boot","/"):
bootDisk = self.clVars.Select("os_install_disk_dev",
where="os_install_disk_mount",eq=bootPath,limit=1)
if bootDisk:
self.setActivePartition(bootDisk)
break
# если GRUB2 версии 2.00 и выше, обычная установка требует
# параметра --target=i386-pc, иначе GRUB2 может попытаться
# прописать себя как UEFI
if filter(lambda x:"2." in x,
process(cmdGrubInstall,'--version')):
platform = ["--target=i386-pc"]
else:
platform = []
# прописать GRUB2 на все указанные диски
for mbrDisk in self.clVars.Get('os_install_mbr'):
grubProcess = process(cmdGrubInstall,
"--boot-directory=%s"%pathJoin(prefixBoot,
target.getBootDirectory()),
mbrDisk, "--force", *platform,
stderr=STDOUT,envdict=os.environ)
if grubProcess.failed():
raise DistributiveError(_("Failed to install the bootloader"))
def installLegacyGrubBootloader(self,target):
self.install_grub_biosboot(cmd_grub_install, prefix_boot, target)
def install_grub_biosboot(self, cmd_grub_install, prefix_boot, target):
"""
Установить GRUB, загрузчик MBR (GPT)
"""
# получить загрузочный раздел (если есть /boot, то
# он является загрузочным иначе корень)
for boot_path in ("/boot", "/"):
boot_disk = self.clVars.Select("os_install_disk_dev",
where="os_install_disk_mount",
eq=boot_path, limit=1)
if boot_disk:
self.setActivePartition(boot_disk)
break
# если GRUB2 версии 2.00 и выше, обычная установка требует
# параметра --target=i386-pc, иначе GRUB2 может попытаться
# прописать себя как UEFI
if filter(lambda x: "2." in x,
process(cmd_grub_install, '--version')):
platform = ["--target=i386-pc"]
else:
platform = []
# прописать GRUB2 на все указанные диски
for mbr_disk in self.clVars.Get('os_install_mbr'):
grub_process = process(cmd_grub_install,
"--boot-directory=%s" % pathJoin(
prefix_boot,
target.getBootDirectory()),
mbr_disk, "--force", *platform,
stderr=STDOUT, envdict=os.environ)
if grub_process.failed():
raise DistributiveError(
_("Failed to install the bootloader"))
def install_grub_uefi(self, cmd_grub_install, prefix_boot, target):
"""
Установить grub с UEFI загрузчиком
"""
grub_params = [
"--boot-directory=%s" % pathJoin(
prefix_boot,
target.getBootDirectory()),
"--target=x86_64-efi",
"--efi-directory=%s" %
target.getEfiDirectory(),
"--force"]
# в случае установки на usb-hdd EFI загрузчик не прописывается
# в efivars
if self.clVars.Get('os_install_root_type') == 'usb-hdd':
grub_params.append("--removable")
if self.clVars.Get('cl_action') != "system" and \
not isMount('/boot/efi'):
raise DistributiveError(_("Failed to install the bootloader. "
"/boot/efi is not mounted."))
grub_process = process(cmd_grub_install,
*grub_params, stderr=STDOUT,
envdict=os.environ)
if grub_process.failed():
raise DistributiveError(_("Failed to install the bootloader"))
# проверяем успешность создания загрузочной записи
# если среди загрузочных записей отсутствует запись
# calculate и dmesg содержит сообщение об ошибке efivars -
# запись создать не удалось
efi_boot_mgr = getProgPath('/usr/sbin/efibootmgr')
dmesg = getProgPath('/bin/dmesg')
if efi_boot_mgr and dmesg:
if not re.search('Boot.*calculate',
process(efi_boot_mgr).read(), re.M) and \
re.search('efivars.*set_variable.*failed',
process(dmesg).read(), re.M):
raise DistributiveError(
_("Failed to create the UEFI boot record"))
def installLegacyGrubBootloader(self, target):
"""
Install legecy grub boot loader
Perform grub installation to disk, which has root partition
"""
cmdGrub = varsShare().getProgPath('/sbin/grub')
if not cmdGrub:
cmd_grub = getProgPath('/sbin/grub')
if not cmd_grub:
raise DistributiveError(_("Failed to install the bootloader"))
grubProcess = process(cmdGrub,
"--device-map=%s/boot/grub/device.map"%target.getDirectory(),
"--batch",stderr=STDOUT)
bootDisk = self.Select('os_install_disk_grub',
where='os_install_disk_mount',
_in=('/','/boot'),
sort='DESC',limit=1)
if not bootDisk:
grub_process = process(
cmd_grub,
"--device-map=%s/boot/grub/device.map" % target.getDirectory(),
"--batch", stderr=STDOUT)
boot_disk = self.clVars.Select('os_install_disk_grub',
where='os_install_disk_mount',
_in=('/', '/boot'),
sort='DESC', limit=1)
if not boot_disk:
raise DistributiveError(_("Failed to determine the boot disk"))
self.setActivePartition(bootDisk)
for mbrDisk in self.clVars.Get('os_install_mbr'):
mbrDiskNum = self.Select("os_device_map",
where="os_device_dev",
eq=mbrDisk)
if not mbrDiskNum and mbrDiskNum != 0:
self.setActivePartition(boot_disk)
for mbr_disk in self.clVars.Get('os_install_mbr'):
mbr_disk_num = self.clVars.Select("os_device_map",
where="os_device_dev",
eq=mbr_disk)
if not mbr_disk_num and mbr_disk_num != 0:
raise DistributiveError(_("Failed to determine mbr"))
for line in ("root (hd%s)"%bootDisk,
"setup (hd%d)"%mbrDiskNum,
for line in ("root (hd%s)" % boot_disk,
"setup (hd%d)" % mbr_disk_num,
"quit"):
grubProcess.write("%s\n"%line)
if grubProcess.failed():
grub_process.write("%s\n" % line)
if grub_process.failed():
raise DistributiveError(_("Failed to install the bootloader"))
def setupOpenGL(self):
"""
Выполнить выбор opengl для текущего видеодрайвера
"""
defaultGL = "xorg-x11"
pathGlModules = path.join(self.clVars.Get('cl_chroot_path'),
'usr/lib/opengl')
openGLenv = path.join(self.clVars.Get('cl_chroot_path'),
'etc/env.d/03opengl')
openGlMods = filter(lambda x:x != "global",
listDirectory(pathGlModules))
mapGL_drivers = {'fglrx':"ati" if "ati" in openGlMods
else defaultGL,
'nvidia':"nvidia" if "nvidia" in openGlMods
else defaultGL}
default_gl = "xorg-x11"
path_gl_modules = path.join(self.clVars.Get('cl_chroot_path'),
'usr/lib/opengl')
open_gl_env = path.join(self.clVars.Get('cl_chroot_path'),
'etc/env.d/03opengl')
open_gl_mods = filter(lambda x: x != "global",
listDirectory(path_gl_modules))
map_gl_drivers = {'fglrx': ("ati" if "ati" in open_gl_mods
else default_gl),
'nvidia': "nvidia" if "nvidia" in open_gl_mods
else default_gl}
x11_driver = self.clVars.Get('os_install_x11_video_drv')
if x11_driver in mapGL_drivers:
newModuleName = mapGL_drivers[x11_driver]
if x11_driver in map_gl_drivers:
new_module_name = map_gl_drivers[x11_driver]
else:
new_module_name = default_gl
current_module_name = map(
lambda x: x.strip().rpartition('=')[-1].strip('"\''),
filter(lambda x: x.startswith("OPENGL_PROFILE="),
readLinesFile(open_gl_env)))
if current_module_name:
current_module_name = current_module_name[-1]
else:
newModuleName = defaultGL
curModuleName = map(lambda x:x.strip().rpartition('=')[-1].strip('"\''),
filter(lambda x: x.startswith("OPENGL_PROFILE="),
readLinesFile(openGLenv)))
curModuleName = curModuleName[-1] if curModuleName else ""
if curModuleName == newModuleName:
current_module_name = ""
if current_module_name == new_module_name:
return True
return process('/usr/bin/eselect','opengl','set',newModuleName).success()
return process('/usr/bin/eselect', 'opengl', 'set',
new_module_name).success()
def checkVideoDriver(self):
"""
@ -364,37 +380,38 @@ class Install:
"""
if self.clVars.Get('hr_video') != 'nvidia':
return True
maskFile = '/etc/portage/package.mask'
nvidiaMaskFile = path.join(maskFile,'nvidia')
mask_file = '/etc/portage/package.mask'
nvidia_mask_file = path.join(mask_file, 'nvidia')
# если package.mask является файлом - делаем его директорией
if path.isfile(maskFile):
os.rename(maskFile,maskFile+"2")
os.mkdir(maskFile,mode=0755)
os.rename(maskFile+"2",path.join(maskFile,"default"))
curNvidiaMask = readFile(nvidiaMaskFile).strip()
maskNvidia = self.clVars.Get('os_nvidia_mask')
if maskNvidia == curNvidiaMask:
if path.isfile(mask_file):
os.rename(mask_file, mask_file + "2")
os.mkdir(mask_file, mode=0755)
os.rename(mask_file + "2", path.join(mask_file, "default"))
current_nvidia_mask = readFile(nvidia_mask_file).strip()
new_nvidia_mask = self.clVars.Get('os_nvidia_mask')
if new_nvidia_mask == current_nvidia_mask:
return True
open(nvidiaMaskFile,'w').write(maskNvidia)
open(nvidia_mask_file, 'w').write(new_nvidia_mask)
return True
def changeScheduler(self,scheduler):
def changeScheduler(self, scheduler):
"""
Изменить текущий IO планировщик
"""
root_dev = self.clVars.Select('os_disk_parent',
where='os_disk_mount',
eq='/',limit=1)
where='os_disk_mount',
eq='/', limit=1)
try:
schedpath = ("/sys%s/queue/scheduler"%
(getUdevDeviceInfo(name=root_dev).get('DEVPATH','')))
if path.exists(schedpath):
open(schedpath,'w').write(scheduler)
except:
raise InstallError(("Unable to change the I/O scheduler"))
scheduler_path = (
"/sys%s/queue/scheduler" %
(getUdevDeviceInfo(name=root_dev).get('DEVPATH', '')))
if path.exists(scheduler_path):
open(scheduler_path, 'w').write(scheduler)
except Exception:
raise InstallError(_("Unable to change the I/O scheduler"))
return True
def autopartition(self,table,devices,data,lvm,lvm_vgname,bios_grub,
def autopartition(self, table, devices, data, lvm, lvm_vgname, bios_grub,
bios_grub_size):
"""
Авторазметка диска с таблицей разделов 'table', диски указываются
@ -403,76 +420,77 @@ class Install:
bios_grub раздел, bios_grub_size - раздел bios grub раздела в байтах
"""
ap = AutoPartition()
ap.clearLvm(devices,self.clVars)
ap.clearRaid(devices,self.clVars)
ap.recreateSpace(table,devices,data,lvm,
lvm_vgname,bios_grub,bios_grub_size)
ap.clearLvm(devices, self.clVars)
ap.clearRaid(devices, self.clVars)
ap.recreateSpace(table, devices, data, lvm,
lvm_vgname, bios_grub, bios_grub_size)
return True
def format(self,target):
def format(self, target):
"""
Форматировать разделы для 'target' дистрибутива
"""
target.performFormat()
return True
def unpack(self,source,target,filesnum):
def unpack(self, source, target, files_num):
"""
Распаковать 'source' в 'target', 'filesnum' количество копируемых файлов
"""
self.addProgress()
if filesnum.isdigit():
filesnum = int(filesnum)
if files_num.isdigit():
files_num = int(files_num)
else:
filesnum = 0
files_num = 0
target.installFrom(source, callbackProgress=self.setProgress,
filesnum=filesnum)
filesnum=files_num)
return True
def copyClt(self,source,target,cltpath):
def copyClt(self, source, target, cltpath):
"""
Скопировать clt шаблоны из 'cltpath' в 'target' дистрибутив из
'source' дистрибутива
"""
targetdir = target.getDirectory()
sourcedir = source.getDirectory()
for f in filter(lambda x:x.endswith('.clt'),
chain(*map(lambda x:find(pathJoin(sourcedir,x),filetype="f"),
cltpath))):
copyWithPath(f,targetdir,prefix=sourcedir)
target_dir = target.getDirectory()
source_dir = source.getDirectory()
for f in filter(lambda x: x.endswith('.clt'),
chain(*map(lambda x: find(pathJoin(source_dir, x),
filetype="f"),
cltpath))):
copyWithPath(f, target_dir, prefix=source_dir)
return True
def copyOther(self,source,target):
def copyOther(self, source, target):
"""
Скопировать прочие настройки из текущей системы в новую
"""
fileMask = re.compile("(/etc/ssh/ssh_host_.*|"
file_mask = re.compile("(/etc/ssh/ssh_host_.*|"
"/root/.ssh/(id_.*|known_hosts))")
targetdir = target.getDirectory()
sourcedir = source.getDirectory()
for f in filter(fileMask.search,
chain(*map(lambda x:find(pathJoin(sourcedir,x),filetype="f"),
["/etc","/root/.ssh"]))):
copyWithPath(f,targetdir,prefix=sourcedir)
target_dir = target.getDirectory()
source_dir = source.getDirectory()
for f in filter(file_mask.search,
chain(*map(lambda x: find(pathJoin(source_dir, x),
filetype="f"),
["/etc", "/root/.ssh"]))):
copyWithPath(f, target_dir, prefix=source_dir)
return True
def rndString(self):
"""
Получить произвольную строку из 8 символов
"""
"""Get random string with len 8 char"""
return "".join([choice(string.ascii_letters+string.digits)
for i in xrange(0,8)])
return "".join([choice(string.ascii_letters + string.digits)
for i in xrange(0, 8)])
def _getFreeDirectory(self,directory):
def _getFreeDirectory(self, directory):
"""
Получить название директории
"""
newDirectoryName = directory
while path.exists(newDirectoryName):
newDirectoryName = "%s.%s"%(directory,self.rndString())
return newDirectoryName
new_dir_name = directory
while path.exists(new_dir_name):
new_dir_name = "%s.%s" % (directory, self.rndString())
return new_dir_name
def remountNTFS(self):
"""
@ -480,50 +498,48 @@ class Install:
"""
res = True
for disk in self.clVars.Select('os_disk_dev',
where='os_disk_format',like='ntfs'):
mountDir = self._getFreeDirectory('/var/lib/calculate/mount.ntfs')
where='os_disk_format', like='ntfs'):
mount_dir = self._getFreeDirectory('/var/lib/calculate/mount.ntfs')
try:
os.mkdir(mountDir)
except:
os.mkdir(mount_dir)
except (OSError, IOError):
continue
if process('/bin/mount',disk,mountDir).success():
for i in (0.2,0.5,1,2,4,5):
if process('/bin/umount',mountDir).success():
if process('/bin/mount', disk, mount_dir).success():
for i in (0.2, 0.5, 1, 2, 4, 5):
if process('/bin/umount', mount_dir).success():
break
time.sleep(i)
else:
self.printWARNING(_("Unable to umount %s")%mountDir)
self.printWARNING(_("Unable to umount %s") % mount_dir)
res = False
try:
os.rmdir(mountDir)
except:
self.printWARNING(_("Unable to remove directory %s")%mountDir)
os.rmdir(mount_dir)
except (OSError, IOError):
self.printWARNING(
_("Unable to remove directory %s") % mount_dir)
return False
return res
def mountBind(self,target):
def mountBind(self, target):
"""
Подключить bind точки монтирования у дистрибутива
"""
target.postinstallMountBind()
return True
def userMigrate(self,target,migrate_data,root_pwd):
def userMigrate(self, target, migrate_data, root_pwd):
"""
Перенос текущих пользователей в новую систему,
установка пароля пользователя root
"""
objMigrate = migrate(target.getDirectory())
if not objMigrate.migrate(migrate_data,root_pwd,[],[],):
migrator = migrate(target.getDirectory())
if not migrator.migrate(migrate_data, root_pwd, [], [], ):
raise InstallError(_("Failed to migrate users onto the new system"))
return True
def umount(self,distr):
def umount(self, distr):
"""
Отключить дистрибутив
"""
distr.close()
return True
def mytest(self):
return False

@ -1,6 +1,6 @@
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# Copyright 2010-2013 Calculate Ltd. http://www.calculate-linux.org
# Copyright 2010-2015 Calculate Ltd. http://www.calculate-linux.org
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -19,21 +19,25 @@ from calculate.lib.encrypt import encrypt
from os import path
from calculate.lib.utils.files import pathJoin
from calculate.lib.cl_lang import setLocalTranslate
setLocalTranslate('cl_install3',sys.modules[__name__])
from calculate.lib.cl_lang import setLocalTranslate, _
setLocalTranslate('cl_install3', sys.modules[__name__])
class MigrationError(Exception):
pass
class _shareData:
class _shareData(object):
"""Share class"""
_reNumb = re.compile("^\d+$")
def getDataInFile(self, fileName='', lenData=7):
"""Get data list from file"""
return filter(lambda x: len(x)==lenData,
return filter(lambda x: len(x) == lenData,
map(lambda x: x.rstrip().split(":"), open(fileName)))
class migrateGroups(_shareData):
"""Migrate group to new system"""
@ -51,29 +55,31 @@ class migrateGroups(_shareData):
def getThisData(self):
"""Get data migrate groups in this system"""
return filter(lambda x:\
self._reNumb.match(x[2]) and self.minGid<=int(x[2])<=self.maxGid,
return filter(lambda x: \
self._reNumb.match(x[2]) and self.minGid <= int(
x[2]) <= self.maxGid,
self.getData())
def getNewData(self):
"""Get data migrate groups in new system"""
fileName = pathJoin(self.prefixNewSystem, self.fileGroups)
return filter(lambda x:\
self._reNumb.match(x[2]) and self.minGid<=int(x[2])<=self.maxGid,
return filter(lambda x: \
self._reNumb.match(x[2]) and self.minGid <= int(
x[2]) <= self.maxGid,
self.getData(fileName=fileName))
def getNewDataSystemGroups(self):
"""Get data system groups in new system"""
fileName = pathJoin(self.prefixNewSystem, self.fileGroups)
return filter(lambda x:\
self._reNumb.match(x[2]) and\
(int(x[2])>self.maxGid or int(x[2])<self.minGid),
self.getData(fileName=fileName))
return filter(lambda x: \
self._reNumb.match(x[2]) and \
(int(x[2]) > self.maxGid or int(x[2]) < self.minGid),
self.getData(fileName=fileName))
def getNewProcessedData(self):
"""Get processed data migrate groups in new system"""
# data this Group no users
dataThisGroupsNoUsers = map(lambda x: x[:3]+[""], self.getThisData())
dataThisGroupsNoUsers = map(lambda x: x[:3] + [""], self.getThisData())
dataNewGroups = self.getNewData()
namesNewGroups = map(lambda x: x[0], dataNewGroups)
gidsNewGroups = map(lambda x: x[2], dataNewGroups)
@ -81,16 +87,18 @@ class migrateGroups(_shareData):
nameGroup = data[0]
gid = data[2]
if nameGroup in namesNewGroups:
dataNewGroups = filter(lambda x: x[0]!=nameGroup,dataNewGroups)
dataNewGroups = filter(lambda x: x[0] != nameGroup,
dataNewGroups)
namesNewGroups = map(lambda x: x[0], dataNewGroups)
gidsNewGroups = map(lambda x: x[2], dataNewGroups)
if gid in gidsNewGroups:
dataNewGroups = filter(lambda x: x[2]!=gid, dataNewGroups)
dataNewGroups = filter(lambda x: x[2] != gid, dataNewGroups)
namesNewGroups = map(lambda x: x[0], dataNewGroups)
gidsNewGroups = map(lambda x: x[2], dataNewGroups)
systemGroupsNewData = self.getNewDataSystemGroups()
return systemGroupsNewData, dataNewGroups, dataThisGroupsNoUsers
class migrateUsers(_shareData):
"""Migrate users to new system"""
@ -108,34 +116,36 @@ class migrateUsers(_shareData):
def getThisData(self):
"""Get data migrate users in this system"""
return filter(lambda x:\
self._reNumb.match(x[2]) and self.minId<=int(x[2])<=self.maxId,
return filter(lambda x: \
self._reNumb.match(x[2]) and self.minId <= int(
x[2]) <= self.maxId,
self.getData())
def getNewData(self):
"""Get data migrate users in new system"""
fileName = pathJoin(self.prefixNewSystem, self.filePasswd)
return filter(lambda x:\
self._reNumb.match(x[2]) and self.minId<=int(x[2])<=self.maxId,
return filter(lambda x: \
self._reNumb.match(x[2]) and self.minId <= int(
x[2]) <= self.maxId,
self.getData(fileName=fileName))
def getNewDataSystemUsers(self):
"""Get data system users in new system"""
fileName = pathJoin(self.prefixNewSystem, self.filePasswd)
return filter(lambda x:\
self._reNumb.match(x[2]) and\
(int(x[2]>self.maxId) or int(x[2])<self.minId),
return filter(lambda x: \
self._reNumb.match(x[2]) and \
(int(x[2] > self.maxId) or int(x[2]) < self.minId),
self.getData(fileName=fileName))
def getThisDataSystemUsers(self):
"""Get data system users in this system"""
fileName = self.filePasswd
return filter(lambda x:\
self._reNumb.match(x[2]) and\
(int(x[2]>self.maxId) or int(x[2])<self.minId),
return filter(lambda x: \
self._reNumb.match(x[2]) and \
(int(x[2] > self.maxId) or int(x[2]) < self.minId),
self.getData(fileName=fileName))
def getNewProcessedData(self, migrateUsers=[]):
def getNewProcessedData(self, migrateUsers=()):
"""Get processed data migrate users in new system"""
dataThisUsers = self.getThisData()
if migrateUsers:
@ -148,11 +158,11 @@ class migrateUsers(_shareData):
nameUser = data[0]
uid = data[2]
if nameUser in namesNewUsers:
dataNewUsers = filter(lambda x: x[0]!=nameUser, dataNewUsers)
dataNewUsers = filter(lambda x: x[0] != nameUser, dataNewUsers)
namesNewUsers = map(lambda x: x[0], dataNewUsers)
uidsNewUsers = map(lambda x: x[2], dataNewUsers)
if uid in uidsNewUsers:
dataNewUsers = filter(lambda x: x[2]!=uid, dataNewUsers)
dataNewUsers = filter(lambda x: x[2] != uid, dataNewUsers)
namesNewUsers = map(lambda x: x[0], dataNewUsers)
uidsNewUsers = map(lambda x: x[2], dataNewUsers)
systemUsersNewData = self.getNewDataSystemUsers()
@ -161,21 +171,21 @@ class migrateUsers(_shareData):
systemUsersThisData = []
if migrateUsers:
# this users < minId
systemUsersThisData = filter(lambda x: int(x[2])<self.minId and\
x[0] in migrateUsers,
systemUsersThisData = filter(lambda x: int(x[2]) < self.minId and \
x[0] in migrateUsers,
self.getThisDataSystemUsers())
for data in systemUsersThisData:
nameUser = data[0]
uid = data[2]
if nameUser in systemUsersNewNames:
systemUsersNewData = filter(lambda x: x[0]!=nameUser,
systemUsersNewData = filter(lambda x: x[0] != nameUser,
systemUsersNewData)
systemUsersNewNames = map(lambda x: x[0],
systemUsersNewData)
systemUsersNewUids = map(lambda x: x[2],
systemUsersNewData)
if uid in systemUsersNewUids:
systemUsersNewData = filter(lambda x: x[2]!=uid,
systemUsersNewData = filter(lambda x: x[2] != uid,
systemUsersNewData)
systemUsersNewNames = map(lambda x: x[0],
systemUsersNewData)
@ -184,6 +194,7 @@ class migrateUsers(_shareData):
return (systemUsersThisData, systemUsersNewData,
dataNewUsers, dataThisUsers)
class migrateShadow(_shareData):
"""Migrate users to new system"""
@ -210,16 +221,17 @@ class migrateShadow(_shareData):
def getNewData(self):
"""Get data migrate users in new system"""
return filter(lambda x: x[0] in self.newMigrateUsers,
self.getData(fileName=self.newFileName))
self.getData(fileName=self.newFileName))
def getNewDataSystemShadow(self):
"""Get data system users in new system"""
return filter(lambda x: x[0] in self.sysNewMigrateUsers,
self.getData(fileName=self.newFileName))
self.getData(fileName=self.newFileName))
def getThisDataSystemShadow(self):
"""Get data system users in this system"""
return filter(lambda x: x[0] in self.sysThisMigrateUsers,self.getData())
return filter(lambda x: x[0] in self.sysThisMigrateUsers,
self.getData())
def getNewProcessedData(self):
"""Get processed data migrate shadow in new system"""
@ -229,7 +241,8 @@ class migrateShadow(_shareData):
for data in dataThisShadow:
nameUser = data[0]
if nameUser in namesNewShadow:
dataNewShadow = filter(lambda x: x[0]!=nameUser, dataNewShadow)
dataNewShadow = filter(lambda x: x[0] != nameUser,
dataNewShadow)
namesNewShadow = map(lambda x: x[0], dataNewShadow)
systemShadowNewData = self.getNewDataSystemShadow()
systemShadowThisData = self.getThisDataSystemShadow()
@ -237,17 +250,18 @@ class migrateShadow(_shareData):
for data in systemShadowThisData:
nameUser = data[0]
if nameUser in systemShadowNewNames:
systemShadowNewData = filter(lambda x: x[0]!=nameUser,
systemShadowNewData = filter(lambda x: x[0] != nameUser,
systemShadowNewData)
systemShadowNewNames = map(lambda x: x[0], systemShadowNewData)
return (systemShadowThisData, systemShadowNewData, dataNewShadow,
dataThisShadow)
class migrate:
class migrate(object):
"""Migrate users ang groups to new system"""
templateShadow = "%(user)s:%(hash)s:%(days)s:0:%(maxDays)s:%(warnDays)s:::"
templateUser="%(user)s:x:%(id)s:%(gid)s::/home/%(user)s:/bin/bash"
templateGroup="%(group)s:x:%(gid)s:"
templateUser = "%(user)s:x:%(id)s:%(gid)s::/home/%(user)s:/bin/bash"
templateGroup = "%(group)s:x:%(gid)s:"
dataUsers = []
dataGroups = []
dataShadow = []
@ -268,21 +282,22 @@ class migrate:
def addThisUsersToGroups(self, users):
"""Add users to groups"""
thisGroupsData = self.objGroups.getData()
thisGroupsData = map(lambda x: (x[0],x[3].split(',')),
thisGroupsData = map(lambda x: (x[0], x[3].split(',')),
thisGroupsData)
dataGroups = []
for data in self.dataGroups:
groupName = data[0]
thisUsersInGroup = map(lambda x: x[1],
filter(lambda x: x[0]==groupName, thisGroupsData))
thisUsersInGroup = reduce(lambda x,y: x+y, thisUsersInGroup,[])
addUsers = list(set(thisUsersInGroup)&set(users))
filter(lambda x: x[0] == groupName,
thisGroupsData))
thisUsersInGroup = reduce(lambda x, y: x + y, thisUsersInGroup, [])
addUsers = list(set(thisUsersInGroup) & set(users))
if addUsers:
newUsersInGroup = data[3].split(',')
for user in addUsers:
if not user in newUsersInGroup:
newUsersInGroup.append(user)
data[3] = ','.join(filter(lambda x:x,newUsersInGroup))
data[3] = ','.join(filter(lambda x: x, newUsersInGroup))
dataGroups.append(data)
self.dataGroups = dataGroups
return self.dataGroups
@ -290,27 +305,27 @@ class migrate:
def getNextUid(self):
"""get next uid"""
listUid = map(lambda x: int(x[2]),
filter(lambda x:\
self.objUsers._reNumb.match(x[2]) and\
self.minId<=int(x[2])<=self.maxId,
filter(lambda x: \
self.objUsers._reNumb.match(x[2]) and \
self.minId <= int(x[2]) <= self.maxId,
self.dataUsers))
if listUid:
return max(listUid)+1
return max(listUid) + 1
return self.minId
def getNextGid(self):
"""get next gid"""
listGid = map(lambda x: int(x[2]),
filter(lambda x:\
self.objGroups._reNumb.match(x[2]) and\
self.minGid<=int(x[2])<=self.maxGid,
filter(lambda x: \
self.objGroups._reNumb.match(x[2]) and \
self.minGid <= int(x[2]) <= self.maxGid,
self.dataGroups))
if listGid:
return max(listGid)+1
return max(listGid) + 1
return self.minGid
def isSystemUser(self, userName):
if filter(lambda x: x[0]==userName and int(x[2])<=self.minSysId,
if filter(lambda x: x[0] == userName and int(x[2]) <= self.minSysId,
self.dataUsers):
return True
return False
@ -325,34 +340,33 @@ class migrate:
usersInGroup = data[3].split(',')
if not userName in usersInGroup:
usersInGroup.append(userName)
data[3] = ','.join(filter(lambda x:x,usersInGroup))
data[3] = ','.join(filter(lambda x: x, usersInGroup))
dataGroups.append(data)
self.dataGroups = dataGroups
return self.dataGroups
def addUserToDefaultGroups(self, userName):
"""Add users to default groups"""
return self.addUserToGroups(userName,self.newUserGroups)
return self.addUserToGroups(userName, self.newUserGroups)
def changePassword(self, userName, pwdHash, maxDays="99999", warnDays="7"):
if not filter(lambda x: x[0]==userName, self.dataUsers):
raise MigrationError(_("User %s not found")%userName)
if not filter(lambda x: x[0] == userName, self.dataUsers):
raise MigrationError(_("User %s not found") % userName)
indexFoundUser = False
for i, data in enumerate(self.dataShadow):
if data[0]==userName:
if data[0] == userName:
indexFoundUser = i
break
if callable(pwdHash):
pwdHash = pwdHash(userName)
if pwdHash is False:
return False
shadowDict = {"user":userName,
"hash":pwdHash,
"days":str(int(time.time()/86400)),
"maxDays":maxDays,
"warnDays":warnDays}
shadowLine = self.templateShadow %shadowDict
shadowDict = {"user": userName,
"hash": pwdHash,
"days": str(int(time.time() / 86400)),
"maxDays": maxDays,
"warnDays": warnDays}
shadowLine = self.templateShadow % shadowDict
shadowList = shadowLine.split(":")
if indexFoundUser is False:
self.dataShadow.append(shadowList)
@ -363,80 +377,83 @@ class migrate:
def addUser(self, userName, userGroups, pwdHash):
"""Add user"""
# find user
if filter(lambda x: x[0]==userName, self.dataUsers):
if filter(lambda x: x[0] == userName, self.dataUsers):
return "EXISTS"
else:
strUid = str(self.getNextUid())
strGid = str(self.getNextGid())
groupName = userName
dataExistGroup = filter(lambda x: x[0]==groupName, self.dataGroups)
dataExistGroup = filter(lambda x: x[0] == groupName,
self.dataGroups)
if dataExistGroup:
strGid = dataExistGroup[0][2]
else:
# add group
groupDict = {"group":groupName,"gid":strGid}
groupLine = self.templateGroup %groupDict
groupDict = {"group": groupName, "gid": strGid}
groupLine = self.templateGroup % groupDict
groupList = groupLine.split(":")
self.dataGroups.append(groupList)
# add user
userDict = {"user":userName, "id":strUid, "gid":strGid}
userline = self.templateUser %userDict
userDict = {"user": userName, "id": strUid, "gid": strGid}
userline = self.templateUser % userDict
userList = userline.split(":")
self.dataUsers.append(userList)
# add shadow
if not self.changePassword(userName, pwdHash):
return False
# add user to default groups
self.addUserToGroups(userName,userGroups)
self.addUserToGroups(userName, userGroups)
return True
def checkPermFiles(self):
"""Check permission files"""
checkThisFiles = [migrateGroups.fileGroups, migrateUsers.filePasswd,
migrateShadow.fileShadow]
checkNewFiles = map(lambda x: pathJoin(self.prefixNewSystem,x),
checkNewFiles = map(lambda x: pathJoin(self.prefixNewSystem, x),
checkThisFiles)
parentDir = lambda x: "".join(os.path.split(x)[:-1])
notRead = lambda x: not os.access(x, os.R_OK)
notWrite = lambda x: not os.access(x, os.W_OK)
filesNotRead = filter(notRead,checkThisFiles)
filesNotRead = filter(notRead, checkThisFiles)
if filesNotRead:
raise MigrationError(_("Failed to read files") + _(": ") +
", ".join(filesNotRead))
filesNotWrite = filter(notWrite,checkNewFiles)
", ".join(filesNotRead))
filesNotWrite = filter(notWrite, checkNewFiles)
if filesNotWrite:
raise MigrationError(_("Failed to write to files") + _(": ") +
", ".join(filesNotWrite))
", ".join(filesNotWrite))
# Check permissions backup files
checkNewBackupFiles = map(lambda x:pathJoin(self.prefixNewSystem,x+"-"),
checkThisFiles)
checkNewBackupFiles = map(
lambda x: pathJoin(self.prefixNewSystem, x + "-"),
checkThisFiles)
notWriteBackup = lambda x: not os.access(x, os.W_OK) and \
(os.path.exists(x) or \
(os.path.exists(x) or
not os.access(os.path.dirname(x), os.W_OK))
filesNotWrite = filter(notWriteBackup, checkNewBackupFiles)
if filesNotWrite:
raise MigrationError(_("Failed to write to files") + _(": ") +
", ".join(filesNotWrite))
", ".join(filesNotWrite))
return True
def saveNewFiles(self):
"""Save /etc/passwd /etc/group /etc/shadow to new system"""
listFilesThisSystem = [migrateGroups.fileGroups,migrateUsers.filePasswd,
listFilesThisSystem = [migrateGroups.fileGroups,
migrateUsers.filePasswd,
migrateShadow.fileShadow]
listFiles = map(lambda x:(pathJoin(self.prefixNewSystem,x),
pathJoin(self.prefixNewSystem,x+"-")),
listFiles = map(lambda x: (pathJoin(self.prefixNewSystem, x),
pathJoin(self.prefixNewSystem, x + "-")),
listFilesThisSystem)
listData = [self.dataGroups, self.dataUsers, self.dataShadow]
allData = zip(listFiles,listData)
allData = zip(listFiles, listData)
for fileNames, data in allData:
buff = "\n".join(map(lambda x: ":".join(x), data)) + "\n"
for fileName in fileNames:
FD = open(fileName, "w+")
FD = open(fileName, "w+")
FD.write(buff)
FD.close()
def createUserGuest(self):
if filter(lambda x: int(x[2])>=self.minSysId, self.dataUsers):
if filter(lambda x: int(x[2]) >= self.minSysId, self.dataUsers):
return True
else:
# add user guest
@ -445,58 +462,67 @@ class migrate:
pwdHash = encryptObj.getHashPasswd(pwd, "shadow_ssha256")
if pwdHash is False:
return False
if not self.addUser("guest", pwdHash):
if not self.addUser("guest", "guest", pwdHash):
return False
return True
def createHomeDirs(self,addUsersList,existsMigrateUsers):
def createHomeDirs(self, addUsersList, existsMigrateUsers):
"""Create home directories for all migreate users"""
def createHome(userdata):
if not userdata[5].startswith('/dev/'):
homedir = pathJoin(self.prefixNewSystem,userdata[5])
homedir = pathJoin(self.prefixNewSystem, userdata[5])
if not path.exists(homedir):
os.mkdir(homedir)
os.chown(homedir,int(userdata[2]),int(userdata[3]))
os.chown(homedir, int(userdata[2]), int(userdata[3]))
users = list(set(map(lambda x:x[0],addUsersList)+existsMigrateUsers)-\
set(["root"]))
users = list(
set(map(lambda x: x[0],
addUsersList) + existsMigrateUsers) - {"root"})
try:
map(createHome,filter(lambda x:x[0] in users, self.dataUsers))
except Exception,e:
raise DistributiveError(
map(createHome, filter(lambda x: x[0] in users, self.dataUsers))
except Exception as e:
raise MigrationError(
_("Failed to create the user's home directory"))
def migrate(self, addUsersList=[], rootPwd="",
pwdUsersList=[], existsMigrateUsers=[]):
def migrate(self, addUsersList=None, rootPwd="",
pwdUsersList=None, existsMigrateUsers=None):
"""Migrate users ang groups to new system"""
if addUsersList is None:
addUsersList = []
elif not any(addUsersList):
addUsersList = []
if pwdUsersList is None:
pwdUsersList = []
if existsMigrateUsers is None:
existsMigrateUsers = []
if not self.checkPermFiles():
return False
if not any(addUsersList):
addUsersList = []
migrateUsers = ["root"]+\
map(lambda x: x[0], addUsersList + pwdUsersList)
migrateUsers = (["root"] +
map(lambda x: x[0], addUsersList + pwdUsersList))
for existMigrUser in existsMigrateUsers:
if not existMigrUser in migrateUsers:
if existMigrUser not in migrateUsers:
migrateUsers.append(existMigrUser)
# add root to migrate users
dataUsers = self.objUsers.getNewProcessedData(migrateUsers)
dataGroups = self.objGroups.getNewProcessedData()
thisSystemUsers, newSystemUsers, newUsers, thisUsers =\
map(lambda x: map(lambda y: y[0],x), dataUsers)
thisSystemUsers, newSystemUsers, newUsers, thisUsers = \
map(lambda x: map(lambda y: y[0], x), dataUsers)
objShadow = migrateShadow(thisSystemUsers, newSystemUsers, newUsers,
thisUsers, self.prefixNewSystem)
dataShadow = objShadow.getNewProcessedData()
self.dataGroups = reduce(lambda x,y: x+y, dataGroups, [])
self.dataUsers = reduce(lambda x,y: x+y, dataUsers, [])
self.dataShadow = reduce(lambda x,y: x+y, dataShadow, [])
self.dataGroups = reduce(lambda x, y: x + y, dataGroups, [])
self.dataUsers = reduce(lambda x, y: x + y, dataUsers, [])
self.dataShadow = reduce(lambda x, y: x + y, dataShadow, [])
self.addThisUsersToGroups(thisUsers)
for userName, pwdHash, maxDays, warnDays in pwdUsersList:
if not self.changePassword(userName, pwdHash,
maxDays=maxDays,
warnDays=warnDays):
return False
for userName, userGroups, pwdHash in [["root",[],rootPwd]]+addUsersList:
#if self.isSystemUser(userName):
for userName, userGroups, pwdHash in [
["root", [], rootPwd]] + addUsersList:
# if self.isSystemUser(userName):
# raise MigrationError(_("%s is a system user") %userName)
ret = self.addUser(userName, userGroups, pwdHash)
if not ret:
@ -509,17 +535,17 @@ class migrate:
if not self.createUserGuest():
return False
self.saveNewFiles()
self.createHomeDirs(addUsersList,existsMigrateUsers)
self.createHomeDirs(addUsersList, existsMigrateUsers)
return True
class currentUsers(migrate):
"""Current users"""
def __init__(self):
self.prefixNewSystem = '/'
self.objGroups = migrateGroups(self.prefixNewSystem)
self.objUsers = migrateUsers(self.prefixNewSystem)
super(currentUsers, self).__init__('/')
def addUsers(self,*users_passwd):
def addUsers(self, *users_passwd):
"""Added users and groups to current system"""
if not self.checkPermFiles():
return False
@ -533,17 +559,18 @@ class currentUsers(migrate):
getHash = encrypt().getHashPasswd
for userName, pwd in zip(users_passwd[0::2],
users_passwd[1::2]):
pwdHash = getHash(pwd,"shadow_ssha256")
if not self.addUser(userName, pwdHash):
pwdHash = getHash(pwd, "shadow_ssha256")
if not self.addUser(userName, userName, pwdHash):
return False
self.saveNewFiles()
return True
def hasUsers(self,*users):
def hasUsers(self, *users):
"""Is users in system"""
if not self.checkPermFiles():
return False
getDataInFile = _shareData().getDataInFile
self.dataUsers = map(lambda x:x[0],
getDataInFile(fileName=migrateUsers.filePasswd,lenData=7))
self.dataUsers = map(lambda x: x[0],
getDataInFile(fileName=migrateUsers.filePasswd,
lenData=7))
return set(self.dataUsers) >= set(users)

@ -1,4 +1,4 @@
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# Copyright 2010-2013 Calculate Ltd. http://www.calculate-linux.org
#
@ -15,142 +15,148 @@
# limitations under the License.
import sys
from calculate.core.server.func import Action,Tasks
from calculate.lib.cl_lang import setLocalTranslate,getLazyLocalTranslate
from calculate.core.server.func import Action, Tasks
from calculate.install.distr import DistributiveError
from calculate.install.migrate_users import MigrationError
from calculate.install.variables.autopartition import AutopartitionError
from calculate.lib.cl_lang import setLocalTranslate, getLazyLocalTranslate, _
from calculate.lib.cl_template import TemplatesError
from calculate.lib.utils.files import FilesError
from calculate.install.install import (MigrationError, TemplatesError,
InstallError,
AutopartitionError, DistributiveError)
from calculate.install.install import InstallError
setLocalTranslate('cl_install3',sys.modules[__name__])
setLocalTranslate('cl_install3', sys.modules[__name__])
__ = getLazyLocalTranslate(_)
class ClInstallAction(Action):
"""
Установка системы
"""
# ошибки, которые отображаются без подробностей
native_error = (FilesError,MigrationError, TemplatesError,
InstallError, AutopartitionError, DistributiveError)
native_error = (FilesError, MigrationError, TemplatesError,
InstallError, AutopartitionError, DistributiveError)
successMessage = None
failedMessage = None
interruptMessage = None
# список задач для действия
tasks = \
[# авторазметка диска
{'name':'autopartition',
'message':__("Creating a new partition table"),
'method':"Install.autopartition(cl_autopartition_table,"
"cl_autopartition_device,cl_autopartition_disk_data,"
"cl_autopartition_lvm_set,cl_autopartition_lvm_vgname,"
"cl_autopartition_bios_grub_set,"
"cl_autopartition_bios_grub_size)",
'condition':lambda dv:dv.Get('cl_autopartition_set') == 'on'},
# форматирование разделов на которые устанавливается дистрибутив
{'name':'format',
'message':__("Formatting the partitions"),
'method':'Install.format(cl_target)',
'condition':lambda dv:dv.Get('cl_target').needFormat},
# распаковка дистрибутива
{'name':'unpack',
'message':__("Unpacking the system image to the target"),
'method':'Install.unpack(cl_image,cl_target,os_install_linux_files)',
},
# отметка что установка идет на HDD
{'name':'hdd',
'condition':lambda dv:dv.Get('os_install_root_type') != 'flash' and \
dv.Get('os_install_pxe') == 'off'},
# копирование clt шаблонов
{'name':'hdd:copy_clt',
'message':__("Copying clt templates to the new system"),
'method':'Install.copyClt(cl_source,cl_target,cl_template_clt_path)'
tasks = [
# авторазметка диска
{'name': 'autopartition',
'message': __("Creating a new partition table"),
'method': "Install.autopartition(cl_autopartition_table,"
"cl_autopartition_device,cl_autopartition_disk_data,"
"cl_autopartition_lvm_set,cl_autopartition_lvm_vgname,"
"cl_autopartition_bios_grub_set,"
"cl_autopartition_bios_grub_size)",
'condition': lambda dv: dv.Get('cl_autopartition_set') == 'on'},
# форматирование разделов на которые устанавливается дистрибутив
{'name': 'format',
'message': __("Formatting the partitions"),
'method': 'Install.format(cl_target)',
'condition': lambda dv: dv.Get('cl_target').needFormat},
# распаковка дистрибутива
{'name': 'unpack',
'message': __("Unpacking the system image to the target"),
'method': 'Install.unpack(cl_image,cl_target,os_install_linux_files)',
},
# отметка что установка идет на HDD
{'name': 'hdd',
'condition': lambda dv: dv.Get(
'os_install_root_type') != 'flash' and
dv.Get('os_install_pxe') == 'off'},
# копирование clt шаблонов
{'name': 'hdd:copy_clt',
'message': __("Copying clt templates to the new system"),
'method': 'Install.copyClt(cl_source,cl_target,cl_template_clt_path)'
},
# копирование прочих файлов
{'name': 'hdd:copy_other',
'message': __("Copying other settings to the new system"),
'method': 'Install.copyOther(cl_source,cl_target)',
'condition': lambda dv: dv.Get('os_root_type') != "livecd",
},
# перемонтирование ntfs для определения windows
{'name': 'hdd:remount_ntfs',
'method': 'Install.remountNTFS()',
'essential': False,
},
# копирование прочих файлов
{'name':'hdd:copy_other',
'message':__("Copying other settings to the new system"),
'method':'Install.copyOther(cl_source,cl_target)',
'condition':lambda dv:dv.Get('os_root_type') != "livecd",
# наложение шаблонов при установке на жесткий диск
{'name': 'hdd:apply_templates',
'message': __("Updating the configuration"),
# наложить шаблоны в установленный дистрибутив, включая clt шаблоны
# без использования фильтров по clt шаблонам
'method': 'Install.applyTemplates(cl_target,True,False,None)',
},
# перемонтирование ntfs для определения windows
{'name':'hdd:remount_ntfs',
'method':'Install.remountNTFS()',
'essential':False,
# наложение шаблонов при PXE установке
{'name': 'apply_templates_pxe',
'message': __("Configuring PXE install"),
# наложить шаблоны в установленный дистрибутив, исключая clt
# без использования фильтров по clt шаблонам
'method': 'Install.applyTemplates(None,False,False,None)',
'condition': lambda dv: dv.Get('os_install_pxe') == 'on'
},
# наложение шаблонов при установке на жесткий диск
{'name':'hdd:apply_templates',
'message':__("Updating the configuration"),
# наложить шаблоны в установленный дистрибутив, включая clt шаблоны
# без использования фильтров по clt шаблонам
'method':'Install.applyTemplates(cl_target,True,False,None)',
# наложение шаблонов при установке на flash диск
{'name': 'apply_templates_flash',
'message': __("Configuring Flash install"),
# наложить шаблоны в установленный дистрибутив, исключая clt
# без использования фильтров по clt шаблонам
'method': 'Install.applyTemplates(None,False,False,cl_target)',
'condition': lambda dv: dv.Get('os_install_root_type') == "flash"
},
# наложение шаблонов при PXE установке
{'name':'apply_templates_pxe',
'message':__("Configuring PXE install"),
# наложить шаблоны в установленный дистрибутив, исключая clt
# без использования фильтров по clt шаблонам
'method':'Install.applyTemplates(None,False,False,None)',
'condition':lambda dv:dv.Get('os_install_pxe') == 'on'
},
# наложение шаблонов при установке на flash диск
{'name':'apply_templates_flash',
'message':__("Configuring Flash install"),
# наложить шаблоны в установленный дистрибутив, исключая clt
# без использования фильтров по clt шаблонам
'method':'Install.applyTemplates(None,False,False,cl_target)',
'condition':lambda dv:dv.Get('os_install_root_type') == "flash"
},
# подключить точки монтирования bind
{'name':'hdd:mount_bind',
'message':__("Post-install configuration"),
'method':"Install.mountBind(cl_target)",
# подключить точки монтирования bind
{'name': 'hdd:mount_bind',
'message': __("Post-install configuration"),
'method': "Install.mountBind(cl_target)",
},
# перенос пользователей
{'name':'hdd:user_migrate',
'message':__("Migrating users"),
'method':'Install.userMigrate(cl_target,cl_migrate_data,'
'cl_migrate_root_pwd)',
# перенос пользователей
{'name': 'hdd:user_migrate',
'message': __("Migrating users"),
'method': 'Install.userMigrate(cl_target,cl_migrate_data,'
'cl_migrate_root_pwd)',
},
# подготовка загрузчика
{'name':'prepare_boot',
'message':__("Preparing the system for reboot"),
'method':'Install.prepareBoot(cl_target)',
'condition':lambda dv:(dv.Get('os_install_mbr') or \
dv.Get('os_install_uefi_set') == 'on') and \
dv.Get('os_install_pxe') == 'off'},
# отключение исходного дистрибутива
{'name':'umount_source',
'message':__("Letting go the source distribution"),
'method':'Install.umount(cl_image)',
'condition':lambda dv:dv.Get('cl_image') and dv.Get('cl_image').childs,
'depend': Tasks.has("unpack")},
# отключение установленного дистрибутива
{'name':'umount_target',
'message':__("Unmounting the target system volume"),
'method':'Install.umount(cl_target)',
'condition':lambda dv:dv.Get('cl_target') and dv.Get('cl_target').childs,
'depend': Tasks.has("unpack")},
# вывести сообщение в случае успеха
{'name':'success',
'message':__("System successfully installed!")},
# вывести сообщение в случае ошибки
{'name':'failed',
'message':__("Failed to install the system!"),
'depend': (Tasks.failed() & Tasks.hasnot("interrupt"))},
# вывести сообщение о том, что установка прервана пользователем
{'name':'intmessage',
'message':__("Installation manually interrupted"),
'depend': Tasks.has("interrupt")},
# подтверждение на перезагрузку
{'name':'ask_reboot',
'message':__("Would you like to reboot your computer "
# подготовка загрузчика
{'name': 'prepare_boot',
'message': __("Preparing the system for reboot"),
'method': 'Install.prepareBoot(cl_target)',
'condition': lambda dv: (dv.Get('os_install_mbr') or
dv.Get('os_install_uefi_set') == 'on') and
dv.Get('os_install_pxe') == 'off'},
# отключение исходного дистрибутива
{'name': 'umount_source',
'message': __("Letting go the source distribution"),
'method': 'Install.umount(cl_image)',
'condition': lambda dv: dv.Get('cl_image') and dv.Get(
'cl_image').childs,
'depend': Tasks.has("unpack")},
# отключение установленного дистрибутива
{'name': 'umount_target',
'message': __("Unmounting the target system volume"),
'method': 'Install.umount(cl_target)',
'condition': lambda dv: dv.Get('cl_target') and dv.Get(
'cl_target').childs,
'depend': Tasks.has("unpack")},
# вывести сообщение в случае успеха
{'name': 'success',
'message': __("System successfully installed!")},
# вывести сообщение в случае ошибки
{'name': 'failed',
'message': __("Failed to install the system!"),
'depend': (Tasks.failed() & Tasks.hasnot("interrupt"))},
# вывести сообщение о том, что установка прервана пользователем
{'name': 'intmessage',
'message': __("Installation manually interrupted"),
'depend': Tasks.has("interrupt")},
# подтверждение на перезагрузку
{'name': 'ask_reboot',
'message': __("Would you like to reboot your computer "
"now to complete the installation?"),
'confirm':'no',
'condition':lambda dv:dv.Get('os_install_pxe') == 'off'},
# перезагрузить компьютер
{'name':'reboot',
'message':__("System reboot"),
'command':'/sbin/reboot',
'depend':Tasks.result("ask_reboot",eq='yes')
'confirm': 'no',
'condition': lambda dv: dv.Get('os_install_pxe') == 'off'},
# перезагрузить компьютер
{'name': 'reboot',
'message': __("System reboot"),
'command': '/sbin/reboot',
'depend': Tasks.result("ask_reboot", eq='yes')
}
]
]

@ -1,6 +1,6 @@
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# Copyright 2010-2013 Calculate Ltd. http://www.calculate-linux.org
# Copyright 2010-2015 Calculate Ltd. http://www.calculate-linux.org
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -15,24 +15,27 @@
# limitations under the License.
import sys
from calculate.core.server.func import Action,Tasks
from calculate.lib.cl_lang import setLocalTranslate,getLazyLocalTranslate
from calculate.core.server.func import Action
from calculate.install.distr import DistributiveError
from calculate.install.migrate_users import MigrationError
from calculate.lib.cl_lang import setLocalTranslate, getLazyLocalTranslate, _
from calculate.lib.cl_template import TemplatesError
from calculate.lib.utils.files import FilesError
from calculate.lib.utils.portage import isPkgInstalled
from calculate.install.install import (MigrationError, TemplatesError,
InstallError,
AutopartitionError, DistributiveError)
from calculate.install.install import InstallError
from calculate.install.variables.autopartition import AutopartitionError
setLocalTranslate('cl_install3',sys.modules[__name__])
setLocalTranslate('cl_install3', sys.modules[__name__])
__ = getLazyLocalTranslate(_)
class ClSetupVideoAction(Action):
"""
Действие для настройки параметров видео
"""
# ошибки, которые отображаются без подробностей
native_error = (FilesError,MigrationError, TemplatesError,
InstallError, AutopartitionError, DistributiveError)
native_error = (FilesError, MigrationError, TemplatesError,
InstallError, AutopartitionError, DistributiveError)
templateTaskMessage = __("Video settings are being configured")
successMessage = __("Video settings configured!")
@ -41,50 +44,51 @@ class ClSetupVideoAction(Action):
addon_tasks = [
# проверить и настроить параметры для nvidia драйвера
{'name':'check_video',
'message':__("Checking the video driver"),
'method':'Install.checkVideoDriver()',
'condition': lambda:isPkgInstalled('xorg-server')
},
{'name':'setup_opengl',
'message':__("Configuring OpenGL"),
'method':'Install.setupOpenGL()',
'condition': lambda:isPkgInstalled('xorg-server')
},
{'name':'setupvideo',
{'name': 'check_video',
'message': __("Checking the video driver"),
'method': 'Install.checkVideoDriver()',
'condition': lambda: isPkgInstalled('xorg-server')
},
{'name': 'setup_opengl',
'message': __("Configuring OpenGL"),
'method': 'Install.setupOpenGL()',
'condition': lambda: isPkgInstalled('xorg-server')
},
{'name': 'setupvideo',
'condition': lambda Get: Get('cl_setup') == 'video'
},
{'name':'setupvideo:reboot',
'warning':__("To apply the changes, reboot the system"),
'condition': lambda Get:((Get('os_x11_video_drv') != \
Get('os_install_x11_video_drv') and \
(Get('os_x11_video_drv') in Get('os_x11_kms_video_drv') \
or Get('os_install_x11_video_drv') \
in Get('os_x11_kms_video_drv')))
and Get('os_install_root_type') != 'livecd')
},
{'name':'setupvideo:restart',
'warning':__("To apply the changes, restart the X server"),
'condition': lambda Get:((Get('os_x11_video_drv') !=
Get('os_install_x11_video_drv') and
(not Get('os_x11_video_drv') in
Get('os_x11_kms_video_drv') and
not Get('os_install_x11_video_drv')
in Get('os_x11_kms_video_drv')))
and Get('os_install_root_type') != 'livecd')
}
]
},
{'name': 'setupvideo:reboot',
'warning': __("To apply the changes, reboot the system"),
'condition': lambda Get: ((Get('os_x11_video_drv') !=
Get('os_install_x11_video_drv') and
(Get('os_x11_video_drv') in Get(
'os_x11_kms_video_drv')
or Get('os_install_x11_video_drv')
in Get('os_x11_kms_video_drv')))
and Get('os_install_root_type') != 'livecd')
},
{'name': 'setupvideo:restart',
'warning': __("To apply the changes, restart the X server"),
'condition': lambda Get: ((Get('os_x11_video_drv') !=
Get('os_install_x11_video_drv') and
(not Get('os_x11_video_drv') in
Get('os_x11_kms_video_drv') and
not Get('os_install_x11_video_drv')
in Get('os_x11_kms_video_drv')))
and Get('os_install_root_type') != 'livecd')
}
]
def __init__(self):
# список задач для действия
self.tasks = [
{'name':'apply_templates',
'message':self.templateTaskMessage,
# наложить шаблоны на текущий дистрибутив, включая clt шаблоны
# без использования фильтров по clt шаблонам
'method':'Install.applyTemplates(cl_source,cl_template_clt_set,'\
'cl_merge_set,None)',
}]
{'name': 'apply_templates',
'message': self.templateTaskMessage,
# наложить шаблоны на текущий дистрибутив, включая clt шаблоны
# без использования фильтров по clt шаблонам
'method': 'Install.applyTemplates(cl_source,cl_template_clt_set,'
'cl_merge_set,None)',
}]
# выполнить дополнительные задачи
self.tasks.extend(self.addon_tasks)
Action.__init__(self)
@ -98,6 +102,7 @@ class ClSetupSystemAction(ClSetupVideoAction):
successMessage = __("System configured!")
failedMessage = __("Failed to configure the system!")
class ClSetupAudioAction(ClSetupSystemAction):
"""
Действие для настройки аудио параметров
@ -107,6 +112,7 @@ class ClSetupAudioAction(ClSetupSystemAction):
successMessage = __("Audio settings configured!")
failedMessage = __("Failed to configure the audio parameters!")
class ClSetupLocaleAction(ClSetupSystemAction):
"""
Действие для настройки языковых параметров
@ -117,6 +123,7 @@ class ClSetupLocaleAction(ClSetupSystemAction):
successMessage = __("System configured!")
failedMessage = __("Failed to configure the system!")
class ClSetupNetworkAction(ClSetupSystemAction):
"""
Действие для настройки аудио параметров
@ -126,6 +133,7 @@ class ClSetupNetworkAction(ClSetupSystemAction):
successMessage = __("Network settings configured!")
failedMessage = __("Failed to configure the network settings!")
class ClSetupSessionAction(ClSetupSystemAction):
"""
Действие для настройки пользовательских параметров
@ -135,6 +143,7 @@ class ClSetupSessionAction(ClSetupSystemAction):
successMessage = __("Session settings configured!")
failedMessage = __("Failed to configure the session settings!")
class ClSetupBootAction(ClSetupSystemAction):
"""
Действие для настройки параметров загрузки
@ -145,25 +154,25 @@ class ClSetupBootAction(ClSetupSystemAction):
addon_tasks = [
# установить загрузчик
{'name':'prepare_bootloader',
'message':_("Installing the bootloader"),
'method':'Install.prepareBoot(cl_image)',
'condition':(lambda Get:(Get('os_install_mbr') or
Get('os_install_uefi_set') == 'on') and
Get('os_root_type') != 'livecd' and
Get('os_install_scratch') == 'off')
},
{'name':'no_scratch',
'warning':_("The builder mode is no longer supported"),
'condition':lambda Get:Get('os_install_scratch') == 'on'
},
{'name': 'prepare_bootloader',
'message': _("Installing the bootloader"),
'method': 'Install.prepareBoot(cl_image)',
'condition': (lambda Get: (Get('os_install_mbr') or
Get('os_install_uefi_set') == 'on') and
Get('os_root_type') != 'livecd' and
Get('os_install_scratch') == 'off')
},
{'name': 'no_scratch',
'warning': _("The builder mode is no longer supported"),
'condition': lambda Get: Get('os_install_scratch') == 'on'
},
# изменить IO планировщик
{'name':'change_ioscheduler',
'message':_("Changing the I/O scheduler"),
'method':'Install.changeScheduler(os_install_kernel_scheduler)',
'condition':(lambda dv:dv.Get('os_root_type') != 'livecd' and
dv.Select('os_disk_parent',
where='os_disk_mount',
eq='/',limit=1))
},
]
{'name': 'change_ioscheduler',
'message': _("Changing the I/O scheduler"),
'method': 'Install.changeScheduler(os_install_kernel_scheduler)',
'condition': (lambda dv: dv.Get('os_root_type') != 'livecd' and
dv.Select('os_disk_parent',
where='os_disk_mount',
eq='/', limit=1))
},
]

@ -1,6 +1,6 @@
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# Copyright 2008-2013 Calculate Ltd. http://www.calculate-linux.org
# Copyright 2008-2015 Calculate Ltd. http://www.calculate-linux.org
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -20,18 +20,22 @@ import re
from os import path
from calculate.lib.datavars import Variable, VariableError, ReadonlyVariable
from calculate.lib.utils.portage import isPkgInstalled
from calculate.lib.utils.files import process, STDOUT, getProgPath, readFile
from calculate.lib.utils.files import readFile
from calculate.lib.utils.common import (getVideoFromXorgLog,
getVideoFromXorgConf, getVideoFromCmdLine,
getAvailableVideo, getValueFromCmdLine,
getCompositeFromXorgconf, getVideoFromModules,
getVideoFromVendor, getInstalledVideo)
getVideoFromXorgConf,
getVideoFromCmdLine,
getAvailableVideo, getValueFromCmdLine,
getCompositeFromXorgconf,
getVideoFromModules,
getVideoFromVendor, getInstalledVideo)
from calculate.install.distr import DistributiveError
import fcntl
import struct
from calculate.lib.cl_lang import setLocalTranslate
setLocalTranslate('cl_install3',sys.modules[__name__])
from calculate.lib.cl_lang import setLocalTranslate, _
setLocalTranslate('cl_install3', sys.modules[__name__])
class VideoVariable(Variable):
"""
@ -45,7 +49,7 @@ class VideoVariable(Variable):
'radeon': _("ATI open source video driver"),
'nouveau': _("NVidia open source video driver"),
'default': _("X.Org Server auto detection")
}
}
def uncompatible(self):
"""
@ -59,11 +63,13 @@ class VideoVariable(Variable):
_("This distribution does not provide a Xorg server")
return ""
class ResolutionVariable(VideoVariable):
"""
Abstract resolution variable
"""
fbres = False
def choice(self):
resolutions = ["640x480", "800x480", "800x600", "1024x576", "1024x600",
"1024x768", "1200x800", "1280x800", "1280x720",
@ -73,20 +79,21 @@ class ResolutionVariable(VideoVariable):
"1600x900", "1600x1200", "2048x1152", "2560x1440",
"2560x1600"]
if self.fbres:
return map(lambda x:"%s-32"%x,
resolutions)
return map(lambda x: "%s-32" % x,
resolutions)
else:
return resolutions
def check(self,value):
def check(self, value):
"""
Check resolution format 1234x567
"""
if not re.match('^\d+x\d+(-\d+(@\d+)?)?$',value):
if not re.match('^\d+x\d+(-\d+(@\d+)?)?$', value):
raise VariableError(
_("Wrong resolution {resolution} {example}").format(
resolution=value,
example="(%s:%s)"%(_("Example"),"1024x768")))
resolution=value,
example="(%s:%s)" % (_("Example"), "1024x768")))
class VariableOsInstallX11Resolution(ResolutionVariable):
"""
@ -106,11 +113,12 @@ class VariableOsInstallX11Resolution(ResolutionVariable):
def get(self):
# get resolution from xorg.log
res = self.Get('os_x11_resolution')
if res or self.Get('os_install_root_type') in ('livecd','usb-hdd'):
if res or self.Get('os_install_root_type') in ('livecd', 'usb-hdd'):
return res or self.fallback_resolution
else:
return self.fallback_resolution
class VariableOsInstallX11VideoAvailable(VideoVariable):
"""
Get available (already installed or installable drivers
@ -121,14 +129,15 @@ class VariableOsInstallX11VideoAvailable(VideoVariable):
def get(self):
image = self.Get('cl_image')
if image:
with image as distr:
with image:
try:
distrPath = image.getDirectory()
if isPkgInstalled('xorg-server',prefix=distrPath):
if isPkgInstalled('xorg-server', prefix=distrPath):
return (sorted(filter(self.supported.__contains__,
getAvailableVideo(prefix=distrPath))) +
getAvailableVideo(
prefix=distrPath))) +
[self.default_video])
except DistributiveError as e:
except DistributiveError:
pass
return []
@ -172,52 +181,55 @@ class VariableOsInstallX11VideoDrv(VideoVariable):
return self.default_video
# if type system is usb-hdd then get detect video driver
if self.Get('os_install_root_type') == 'usb-hdd':
methods = ((getVideoFromModules,()),
(getVideoFromCmdLine,()),
(getVideoFromVendor,(self.Get('hr_video'),list_video)))
methods = ((getVideoFromModules, ()),
(getVideoFromCmdLine, ()),
(getVideoFromVendor,
(self.Get('hr_video'), list_video)))
else:
# test current video driver for install system
methods = ((getVideoFromXorgLog,('/',list_video)),
(getVideoFromXorgConf,('/',)),
(getVideoFromModules,()),
(getVideoFromCmdLine,()),
(getVideoFromVendor,(self.Get('hr_video'),list_video)))
for func,args in methods:
methods = ((getVideoFromXorgLog, ('/', list_video)),
(getVideoFromXorgConf, ('/',)),
(getVideoFromModules, ()),
(getVideoFromCmdLine, ()),
(getVideoFromVendor,
(self.Get('hr_video'), list_video)))
for func, args in methods:
drv = func(*args)
if drv in list_video:
return drv
return self.default_video
else:
for drv in map(lambda x:x[0], self.choice()):
videoSysPath = path.join("/sys/module",drv,"refcnt")
for drv in map(lambda x: x[0], self.choice()):
videoSysPath = path.join("/sys/module", drv, "refcnt")
refcnt = readFile(videoSysPath).strip()
if refcnt.isdigit() and int(refcnt) > 0:
return {'i915':'intel'}.get(drv,drv)
return {'i915': 'intel'}.get(drv, drv)
else:
return self.default_video
pkgDrvMap = {'nvidia':('NVidia','x11-drivers/nvidia-drivers'),
'fglrx':('ATI','x11-drivers/ati-drivers'),
'vboxdrv':('VirtualBox','x11-drivers/xf86-video-virtualbox')}
pkgDrvMap = {'nvidia': ('NVidia', 'x11-drivers/nvidia-drivers'),
'fglrx': ('ATI', 'x11-drivers/ati-drivers'),
'vboxdrv': ('VirtualBox', 'x11-drivers/xf86-video-virtualbox')}
def check(self,value):
def check(self, value):
if self.Get('os_install_x11_server_set') == 'on':
if self.Get('cl_action') == 'system':
availDrvs = self.Get('os_install_x11_video_available')
if not value in availDrvs:
raise VariableError(_("Only %s drivers are available")%
",".join(availDrvs))
raise VariableError(_("Only %s drivers are available") %
",".join(availDrvs))
else:
if not value in getInstalledVideo(prefix="/") and \
not value in ("auto",self.default_video):
error =_("video driver %s is unavailable")%value
not value in ("auto", self.default_video):
error = _("video driver %s is unavailable") % value
if value in self.pkgDrvMap:
error += ". " + (_("Install driver %s with:")
%self.pkgDrvMap[value][0])
error += "\n" + ("emerge %s"%self.pkgDrvMap[value][1])
% self.pkgDrvMap[value][0])
error += "\n" + ("emerge %s" % self.pkgDrvMap[value][1])
raise VariableError(error)
else:
availDrivers = self.Get('os_x11_kms_video_drv') + [self.default_video]
availDrivers = self.Get('os_x11_kms_video_drv') + [
self.default_video]
if not value in availDrivers:
raise VariableError("Only %s drivers are available" %
",".join(availDrivers))
@ -231,6 +243,7 @@ class VariableOsInstallX11VideoDrv(VideoVariable):
_("Video configuration unavailable for Flash install")
return ""
class VariableHrVideoId(ReadonlyVariable):
"""
BusID of video card
@ -238,6 +251,7 @@ class VariableHrVideoId(ReadonlyVariable):
"""
value = ""
class VariableOsInstallX11Composite(VideoVariable):
"""
on/off composite
@ -251,15 +265,15 @@ class VariableOsInstallX11Composite(VideoVariable):
def get(self):
"""On/off composite"""
defaultCompositeOn = ("nvidia","intel","fglrx",
"nouveau","radeon", "default")
composite = getValueFromCmdLine("calculate",5)
videodrv = getValueFromCmdLine("calculate",4)
defaultCompositeOn = ("nvidia", "intel", "fglrx",
"nouveau", "radeon", "default")
composite = getValueFromCmdLine("calculate", 5)
videodrv = getValueFromCmdLine("calculate", 4)
if videodrv != "auto":
composite = {'nocomposite':'off',
'off':'off',
'on':'on',
'composite':'on'}.get(composite)
composite = {'nocomposite': 'off',
'off': 'off',
'on': 'on',
'composite': 'on'}.get(composite)
else:
composite = None
@ -275,6 +289,7 @@ class VariableOsInstallX11Composite(VideoVariable):
state = None
return composite or state or defaultComposite
class VariableOsInstallFbResolution(ResolutionVariable):
"""
Framebuffer resolution
@ -294,10 +309,10 @@ class VariableOsInstallFbResolution(ResolutionVariable):
def get(self):
"""Get current framebuffer resolution"""
try:
fbdev = os.open('/dev/fb0',os.O_RDONLY)
data = fcntl.ioctl(fbdev, self.FBIOGET_VSCREENINFO, " "*8)
res = struct.unpack("II",data)
return "%sx%s"%(res[0],res[1])
except (IOError,OSError):
fbdev = os.open('/dev/fb0', os.O_RDONLY)
data = fcntl.ioctl(fbdev, self.FBIOGET_VSCREENINFO, " " * 8)
res = struct.unpack("II", data)
return "%sx%s" % (res[0], res[1])
except (IOError, OSError):
pass
return "1024x768"

@ -1,6 +1,6 @@
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# Copyright 2008-2013 Calculate Ltd. http://www.calculate-linux.org
# Copyright 2008-2015 Calculate Ltd. http://www.calculate-linux.org
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -14,30 +14,31 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import sys
from os import path
from calculate.lib.datavars import (Variable,VariableError,ReadonlyVariable,
ActionVariable)
from calculate.lib.datavars import ActionVariable
from calculate.lib.cl_lang import setLocalTranslate
setLocalTranslate('cl_install3',sys.modules[__name__])
setLocalTranslate('cl_install3', sys.modules[__name__])
class VariableAcInstallMerge(ActionVariable):
"""
Action variable which has value "on"
in ebuild phase preinst or reconfigure system
"""
def action(self,cl_action):
if cl_action in ("system","merge") and \
self.Get('os_install_root_type') != 'flash' and \
self.Get('os_install_pxe') == 'off' and \
self.Get('cl_live') == 'off' or \
cl_action in ("sync","domain","undomain") \
and self.Get('cl_merge_pkg'):
def action(self, cl_action):
if (cl_action in ("system", "merge") and
self.Get('os_install_root_type') != 'flash' and
self.Get('os_install_pxe') == 'off' and
self.Get('cl_live') == 'off' or
cl_action in ("sync", "domain", "undomain")
and self.Get('cl_merge_pkg')):
return "on"
return "off"
class VariableAcInstallLive(ActionVariable):
"""
Action variable which has value "on"
@ -46,72 +47,84 @@ class VariableAcInstallLive(ActionVariable):
"""
nonchroot = True
def action(self,cl_action):
if cl_action in ("system","merge") and \
self.Get('os_install_root_type') != 'flash' and \
self.Get('os_install_pxe') == 'off' or \
cl_action in ("sync","domain","undomain") \
and self.Get('cl_merge_pkg'):
def action(self, cl_action):
if (cl_action in ("system", "merge") and
self.Get('os_install_root_type') != 'flash' and
self.Get('os_install_pxe') == 'off' or
cl_action in ("sync", "domain", "undomain")
and self.Get('cl_merge_pkg')):
return "on"
return "off"
class VariableAcInstallDisk(ActionVariable):
"""
Action variable which has value "on" for installation on hdd
"""
def action(self,cl_action):
if cl_action == 'system' and \
self.Get('os_install_root_type') != "flash" and \
self.Get('os_install_pxe') != "on":
def action(self, cl_action):
if (cl_action == 'system' and
self.Get('os_install_root_type') != "flash" and
self.Get('os_install_pxe') != "on"):
return "on"
else:
return "off"
class VariableAcInstallFlash(ActionVariable):
"""
Action variable which has value "on" for USB flash
"""
def action(self,cl_action):
if cl_action == 'system' \
and self.Get('os_install_root_type') == 'flash':
def action(self, cl_action):
if (cl_action == 'system' and
self.Get('os_install_root_type') == 'flash'):
return "on"
return "off"
class VariableAcInstallPxe(ActionVariable):
"""
Action variable which has value "on" for PXE installation
"""
def action(self,cl_action):
def action(self, cl_action):
if cl_action == 'system' and self.Get('os_install_pxe') == 'on':
return "on"
return "off"
class VariableAcInstallConfigure(ActionVariable):
"""
Action variable which has value "up" for configuration
"""
def action(self,cl_action):
clSetup = self.Get('cl_setup')
if cl_action == "merge" and clSetup:
def action(self, cl_action):
cl_setup = self.Get('cl_setup')
if cl_action == "merge" and cl_setup:
return "on"
return "off"
class VariableAcInstallUnmerge(ActionVariable):
"""
Action variable which has value "up" on prerm ebuild phase
"""
def action(self,cl_action):
if cl_action == "merge" and \
self.Get('cl_ebuild_phase') in ('prerm','postrm'):
def action(self, cl_action):
if (cl_action == "merge" and
self.Get('cl_ebuild_phase') in ('prerm', 'postrm')):
return "on"
return "off"
class VariableAcInstallPatch(ActionVariable):
"""
Action variable which has value "on"
in ebuild phase preinst or reconfigure system
"""
def action(self,cl_action):
def action(self, cl_action):
if cl_action in ("patch",):
return "on"
return "off"

@ -1,6 +1,6 @@
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# Copyright 2008-2013 Calculate Ltd. http://www.calculate-linux.org
# Copyright 2008-2015 Calculate Ltd. http://www.calculate-linux.org
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -14,16 +14,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import sys
import re
from os import path
from calculate.lib.datavars import (Variable, VariableError, ReadonlyVariable,
ReadonlyTableVariable, FieldValue)
from calculate.lib.utils.files import (readFile, getProgPath, process)
from calculate.lib.datavars import (Variable, ReadonlyVariable,
ReadonlyTableVariable, FieldValue,
HumanReadable)
from calculate.lib.utils.files import readFile
from calculate.lib.cl_lang import setLocalTranslate, _
setLocalTranslate('cl_install3', sys.modules[__name__])
from calculate.lib.cl_lang import setLocalTranslate
setLocalTranslate('cl_install3',sys.modules[__name__])
class VariableOsAudioData(ReadonlyTableVariable):
"""
@ -32,9 +33,9 @@ class VariableOsAudioData(ReadonlyTableVariable):
source = ['os_audio_id',
'os_audio_name']
def get(self,hr=False):
def get(self, hr=HumanReadable.No):
data = readFile('/proc/asound/cards')
cards = re.findall('^\s*(\d+).*\n\s+(\S.*) at .*$',data,re.M)
cards = re.findall('^\s*(\d+).*\n\s+(\S.*) at .*$', data, re.M)
if cards:
return map(list, cards)
else:
@ -42,7 +43,8 @@ class VariableOsAudioData(ReadonlyTableVariable):
setValue = Variable.setValue
class VariableOsAudioId(FieldValue,ReadonlyVariable):
class VariableOsAudioId(FieldValue, ReadonlyVariable):
"""
Order Id of audio card
"""
@ -50,7 +52,8 @@ class VariableOsAudioId(FieldValue,ReadonlyVariable):
source_variable = "os_audio_data"
column = 0
class VariableOsAudioName(FieldValue,ReadonlyVariable):
class VariableOsAudioName(FieldValue, ReadonlyVariable):
"""
Name of audio card
"""
@ -58,6 +61,7 @@ class VariableOsAudioName(FieldValue,ReadonlyVariable):
source_variable = "os_audio_data"
column = 1
class VariableOsAudioDefaultSet(ReadonlyVariable):
"""
Force write in config 0
@ -65,34 +69,36 @@ class VariableOsAudioDefaultSet(ReadonlyVariable):
type = "bool"
def get(self):
res = self.Select('os_audio_id',where='os_audio_name',
notlike='HDMI',limit=1)
audioDefault = self.Get('os_audio_default')
if audioDefault != '0' or \
res and res != "0" and audioDefault == '0' or \
audioDefault != self.Get('os_audio_current'):
res = self.Select('os_audio_id', where='os_audio_name',
notlike='HDMI', limit=1)
audio_default = self.Get('os_audio_default')
if (audio_default != '0' or
res and res != "0" and audio_default == '0' or
audio_default != self.Get('os_audio_current')):
return 'on'
return 'off'
class VariableOsAudioCurrent(ReadonlyVariable):
"""
Current default audio card
"""
def get(self):
defaultCardRe = re.compile('defaults.ctl.card\s+(\d+)')
entry = defaultCardRe.search(readFile('/etc/asound.conf'))
default_card_re = re.compile('defaults.ctl.card\s+(\d+)')
entry = default_card_re.search(readFile('/etc/asound.conf'))
if entry and entry.groups()[0] in self.Get('os_audio_id'):
return entry.groups()[0]
res = self.Select('os_audio_id',where='os_audio_name',
notlike='HDMI',limit=1)
res = self.Select('os_audio_id', where='os_audio_name',
notlike='HDMI', limit=1)
return res or '0'
class VariableOsAudioDefault(Variable):
"""
Current default audio card
"""
type = "choice"
type = "choice"
opt = ['--audio']
def init(self):

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -1,4 +1,4 @@
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# Copyright 2008-2013 Calculate Ltd. http://www.calculate-linux.org
#
@ -20,26 +20,28 @@ from os import path
import re
import operator
from operator import itemgetter
from calculate.lib.datavars import Variable,VariableError,ReadonlyVariable, \
CommonVariableError
from calculate.lib.utils.common import getSupportArch,getTupleVersion, \
cmpVersion
from calculate.lib.utils.files import readLinesFile, listDirectory, pathJoin
from calculate.lib.datavars import (Variable, VariableError, ReadonlyVariable,
CommonVariableError)
from calculate.lib.utils.common import (getSupportArch, getTupleVersion,
cmpVersion)
from calculate.lib.utils.files import listDirectory, pathJoin
from calculate.lib.variables.linux import Linux
from calculate.install.distr import (Distributive,PartitionDistributive,
DirectoryDistributive, DefaultMountPath,
ScratchPartitionDistributive,DistributiveError,FlashDistributive,
MultiPartitions,PxeDistributive)
from calculate.install.distr import (Distributive, PartitionDistributive,
DirectoryDistributive, DefaultMountPath,
DistributiveError, FlashDistributive,
MultiPartitions, PxeDistributive)
from calculate.lib.cl_lang import setLocalTranslate, _
setLocalTranslate('cl_install3', sys.modules[__name__])
from calculate.lib.cl_lang import setLocalTranslate
setLocalTranslate('cl_install3',sys.modules[__name__])
class DistroRepository(Linux):
contentCache = {}
marches = ['i686','x86_64']
marches = ['i686', 'x86_64']
extensiton = ['iso','tar.bz2','tar.gz','tar.7z','tar.lzma']
extensiton = ['iso', 'tar.bz2', 'tar.gz', 'tar.7z', 'tar.lzma']
reDistName = re.compile("""
^.*/(?P<os_linux_shortname>%(name)s)
@ -47,14 +49,14 @@ class DistroRepository(Linux):
(?:-(?P<serial_id>%(ser)s))?
-(?P<os_arch_machine>%(march)s)
.(?P<ext>%(ext)s)$""" %
{'name':"[a-z0-9]+",
'ver':r"(\d+\.)*\d+",
'ser':r"\d+",
'march':"|".join(marches),
'ext':"|".join(extensiton)
}, re.X)
def _getDistrInfo(self,filename):
{'name': "[a-z0-9]+",
'ver': r"(\d+\.)*\d+",
'ser': r"\d+",
'march': "|".join(marches),
'ext': "|".join(extensiton)
}, re.X)
def _getDistrInfo(self, filename):
"""Get information by distributive"""
# if filename is directory
if not path.isfile(filename):
@ -71,8 +73,8 @@ class DistroRepository(Linux):
distdic["os_linux_ver"] = ""
return distdic
def getImage(self,scratch,rootType,imagePath,march=None,
shortName=None,linuxVer=None,linuxBuild=None):
def getImage(self, scratch, rootType, imagePath, march=None,
shortName=None, linuxVer=None, linuxBuild=None):
"""Get image by parameters"""
# exclude directory distributive for flash and scratch install
if scratch == "on" or rootType == "flash":
@ -86,40 +88,44 @@ class DistroRepository(Linux):
version=linuxVer,
build=linuxBuild)
def _getAvailableShortnames(self,dirs):
def _getAvailableShortnames(self, dirs):
"""Get available distributives shortnames"""
distros = filter(lambda x:x,
map(self.reDistName.search,self._getAvailableDistributives(dirs)))
return sorted(list(set(map(lambda x:x.groupdict()['name'],distros))))
distros = filter(lambda x: x,
map(self.reDistName.search,
self._getAvailableDistributives(dirs)))
return sorted(list(set(map(lambda x: x.groupdict()['name'], distros))))
def opcompareByString(self,buf):
def opcompareByString(self, buf):
if buf:
reOp = re.compile("^(!=|=|==|<=|>=|>|<)?(\d+.*)$")
res = reOp.search(buf)
if res:
return ({'!=':operator.ne,
'=':operator.eq,
'==':operator.eq,
'>=':operator.ge,
'<=':operator.le,
'<':operator.lt,
'>':operator.gt}.get(res.group(1),operator.eq),
return ({'!=': operator.ne,
'=': operator.eq,
'==': operator.eq,
'>=': operator.ge,
'<=': operator.le,
'<': operator.lt,
'>': operator.gt}.get(res.group(1), operator.eq),
res.group(2))
else:
return operator.eq,buf
return None,None
return operator.eq, buf
return None, None
def _getAvailableDistributives(self,dirs,system=None,shortname=None,
march=None,version=None,build=None):
def _getAvailableDistributives(self, dirs, system=None, shortname=None,
march=None, version=None, build=None):
"""Get all distributives by filter"""
def systemByName(name):
return self.dictNameSystem.get(name.upper(),"")
return self.dictNameSystem.get(name.upper(), "")
verCmp, version = self.opcompareByString(version)
if version:
version = getTupleVersion(version)
buildCmp, build = self.opcompareByString(build)
if build and build.isdigit():
build = int(build)
def distfilter(dist):
d = self._getDistrInfo(dist)
if not d:
@ -127,123 +133,127 @@ class DistroRepository(Linux):
# check filter conditions
if system and systemByName(d['os_linux_shortname']) != system:
return False
if not "os_linux_shortname" in d or not "os_linux_ver" in d:
if "os_linux_shortname" not in d or "os_linux_ver" not in d:
return False
if shortname and \
d['os_linux_shortname'].lower() != shortname.lower():
if (shortname and
d['os_linux_shortname'].lower() != shortname.lower()):
return False
if march and d['os_arch_machine'] != march:
return False
if version and \
not verCmp(getTupleVersion(d['os_linux_ver']), version):
not verCmp(getTupleVersion(d['os_linux_ver']), version):
return False
if build and "os_linux_build" in d and \
(not d['os_linux_build'].isdigit() or
not buildCmp(int(d['os_linux_build']),build)):
(not d['os_linux_build'].isdigit() or
not buildCmp(int(d['os_linux_build']), build)):
return False
return True
def listdistr(pathname):
if path.exists(path.join(pathname,'etc/make.profile')) or \
path.exists(path.join(pathname,'etc/portage/make.profile')) or \
path.exists(path.join(pathname,'livecd')) or \
pathname.startswith('/dev/'):
if path.exists(path.join(pathname, 'etc/make.profile')) or \
path.exists(
path.join(pathname, 'etc/portage/make.profile')) or \
path.exists(path.join(pathname, 'livecd')) or \
pathname.startswith('/dev/'):
return [pathname]
else:
# discard inner directories
return filter(lambda x:not path.isdir( path.join(pathname,x)),
return filter(lambda x: not path.isdir(path.join(pathname, x)),
listDirectory(pathname))
# get lists files in directories
allFiles = map(lambda x: map(lambda y: path.join(x,y),
allFiles = map(lambda x: map(lambda y: path.join(x, y),
listdistr(x)),
dirs)
dirs)
# filter distributives
return filter(distfilter,
# join files lists to one list
reduce(lambda x,y: x + y,
reduce(lambda x, y: x + y,
allFiles, []))
def extcomparator(self,*exts):
def extcomparator(self, *exts):
"""Compare extensions"""
mapExts = {'iso':0,
'flash':-1,
'isodir':-2,
'partdir':-3,
'dir':-4}
return cmp(mapExts.get(exts[0],-4),mapExts.get(exts[1],-4))
def sortdistrfunc(self,x,y):
mapExts = {'iso': 0,
'flash': -1,
'isodir': -2,
'partdir': -3,
'dir': -4}
return cmp(mapExts.get(exts[0], -4), mapExts.get(exts[1], -4))
def sortdistrfunc(self, x, y):
"""Func of comparing two distributive"""
ver1, ver2 = x[1].get('os_linux_ver',""), y[1].get('os_linux_ver',"")
ver1, ver2 = x[1].get('os_linux_ver', ""), y[1].get('os_linux_ver', "")
if ver1 and ver2 and ver1 != "0" and ver2 != "0" and ver1 != ver2:
return cmpVersion(ver1,ver2)
build1 = getTupleVersion(x[1].get('os_linux_build',""))
build2 = getTupleVersion(y[1].get('os_linux_build',""))
return cmpVersion(ver1, ver2)
build1 = getTupleVersion(x[1].get('os_linux_build', ""))
build2 = getTupleVersion(y[1].get('os_linux_build', ""))
if build1 != build2:
return cmp(build1,build2)
return cmp(build1, build2)
else:
ser1, ser2 = (x[1].get('serial_id') or "0",
y[1].get('serial_id') or "0")
if ser1 != ser2:
return cmp(int(ser1), int(ser2))
ext1 = x[1].get('ext',"")
ext2 = y[1].get('ext',"")
return self.extcomparator(ext1,ext2)
ext1 = x[1].get('ext', "")
ext2 = y[1].get('ext', "")
return self.extcomparator(ext1, ext2)
def getAvailableDristibutives(self,dirs,system=None,shortname=None,
march=None, version=None, build=None,discardType=[]):
def getAvailableDristibutives(self, dirs, system=None, shortname=None,
march=None, version=None, build=None,
discardType=()):
"""Get list available distributives"""
if shortname:
shortname = shortname.lower()
availDistrs = self._getAvailableDistributives(dirs,system,shortname,
march,version,
build)
availDistrs = filter(lambda x:x[1] and "ext" in x[1] and
not x[1]["ext"] in discardType,
map(lambda x:(x,self._getDistrInfo(x)),
availDistrs))
return map(lambda x:x[0],
sorted(availDistrs,self.sortdistrfunc,reverse=True))
def getBestDistributive(self,dirs,system=None,shortname=None,march=None,
version=None, build=None,discardType=[]):
availDistrs = self._getAvailableDistributives(dirs, system, shortname,
march, version,
build)
availDistrs = filter(lambda x: x[1] and "ext" in x[1] and
not x[1]["ext"] in discardType,
map(lambda x: (x, self._getDistrInfo(x)),
availDistrs))
return map(lambda x: x[0],
sorted(availDistrs, self.sortdistrfunc, reverse=True))
def getBestDistributive(self, dirs, system=None, shortname=None, march=None,
version=None, build=None, discardType=()):
"""Get the actualest distributive"""
availDistrs = self.getAvailableDristibutives(dirs,system,shortname,
march,version,build,discardType)
availDistrs = self.getAvailableDristibutives(dirs, system, shortname,
march, version, build,
discardType)
if availDistrs:
return availDistrs[0]
else:
return None
def _findLatestFile(self,dirs,reMatch,keyfunc):
def _findLatestFile(self, dirs, reMatch, keyfunc):
"""Find latest file in dirs, which match by reMatch,
comparable part get by keyfunc"""
existsdirs = filter(path.exists,dirs)
listimgs = reduce(lambda x,y:x + \
map(lambda x:reMatch.search(path.join(y,x)),
listDirectory(y)),
existsdirs,[])
listimgs = filter(lambda x:x, listimgs)
existsdirs = filter(path.exists, dirs)
listimgs = reduce(lambda x, y: x + map(
lambda x: reMatch.search(
path.join(y, x)),
listDirectory(y)),
existsdirs, [])
listimgs = filter(lambda x: x, listimgs)
if listimgs:
return max(listimgs,key=keyfunc).group()
return max(listimgs, key=keyfunc).group()
return ""
def getBestStage(self,dirs,march=None,hardened=None):
def getBestStage(self, dirs, march=None, hardened=None):
"""Get latest stage by march"""
if march:
march = {'x86_64':'amd64'}.get(march,march)
march = {'x86_64': 'amd64'}.get(march, march)
else:
march = "[^-]+"
if hardened is None:
hardened = "(?:-hardened)?"
elif hardened == True:
elif hardened is True:
hardened = "-hardened"
elif hardened == False:
elif hardened is False:
hardened = ""
reStage = re.compile(r'^.*/stage3-%s%s-(\d+)\.tar\.bz2$'%
(march,hardened),re.S)
return self._findLatestFile(dirs,reStage,lambda x:x.groups()[0])
reStage = re.compile(r'^.*/stage3-%s%s-(\d+)\.tar\.bz2$' %
(march, hardened), re.S)
return self._findLatestFile(dirs, reStage, lambda x: x.groups()[0])
class VariableClImage(ReadonlyVariable):
@ -271,7 +281,8 @@ class VariableClImage(ReadonlyVariable):
return filename.getType()
return filename
class VariableClImageFilename(Variable,DistroRepository):
class VariableClImageFilename(DistroRepository, Variable):
"""
Distributive image filename
"""
@ -291,44 +302,45 @@ class VariableClImageFilename(Variable,DistroRepository):
return ""
arch = self.Get('cl_image_arch_machine') or self.Get('os_arch_machine')
shortname = self.Get('cl_image_linux_shortname') or \
self.Get('os_linux_shortname')
self.Get('os_linux_shortname')
ver = self.Get('cl_image_linux_ver') or None
build = self.Get('cl_image_linux_build') or None
return self.getImage(self.Get('os_install_scratch'),
self.Get('os_install_root_type'),
self.Get('cl_image_path'),
arch,shortname,ver,build) or ""
self.Get('os_install_root_type'),
self.Get('cl_image_path'),
arch, shortname, ver, build) or ""
def check(self,isoimage):
def check(self, isoimage):
"""Set image file"""
if self.Get('cl_action') == 'system' and not isoimage:
raise VariableError(_("You need to select a distribution image"))
imageData = Distributive().getInfo(isoimage)
if not("os_linux_shortname" in imageData and \
imageData.get('os_linux_build','') and \
"os_arch_machine" in imageData):
if not ("os_linux_shortname" in imageData and
imageData.get('os_linux_build', '') and
"os_arch_machine" in imageData):
raise VariableError(_("Wrong image file"))
def humanImageName(self,distroinfo,filepath):
def humanImageName(self, distroinfo, filepath):
if all(x in distroinfo for x in ("os_linux_shortname",
"os_arch_machine",
"os_linux_build")):
distroinfo['os_linux_shortname'] = \
distroinfo['os_linux_shortname'].upper()
fullname = distroinfo.get('os_linux_name',
Linux.dictLinuxName.get(
distroinfo['os_linux_shortname'],"Calculate"))
Linux.dictLinuxName.get(
distroinfo['os_linux_shortname'],
"Calculate"))
subname = distroinfo.get('os_linux_subname',
Linux.dictLinuxSubName.get(
distroinfo['os_linux_shortname'],""))
Linux.dictLinuxSubName.get(
distroinfo['os_linux_shortname'], ""))
if subname:
subname=" %s"%subname
subname = " %s" % subname
build = distroinfo['os_linux_build'] or \
distroinfo.get('os_linux_ver','')
ver = distroinfo.get('os_linux_ver','')
distroinfo.get('os_linux_ver', '')
ver = distroinfo.get('os_linux_ver', '')
return "{fullname} {os_arch_machine} {build}".format(
fullname="%s%s"%(fullname,subname),filepath=filepath,
build=build,ver=ver,**distroinfo)
fullname="%s%s" % (fullname, subname), filepath=filepath,
build=build, ver=ver, **distroinfo)
else:
return filepath
@ -336,34 +348,34 @@ class VariableClImageFilename(Variable,DistroRepository):
fullname = self.Get('os_install_linux_name')
subname = self.Get('os_install_linux_subname')
if subname:
subname = " %s"%subname
subname = " %s" % subname
arch = self.Get('os_install_arch_machine')
build = self.Get('os_install_linux_build')
ver = self.Get('os_install_linux_ver')
return "{fullname} {ver} {arch} {build}".format(
fullname="%s%s"%(fullname,subname),
build=build,ver=ver,arch=arch)
fullname="%s%s" % (fullname, subname),
build=build, ver=ver, arch=arch)
def choice(self):
scratch = self.Get('os_install_scratch')
rootType = self.Get('os_install_root_type')
imagePath = self.Get('cl_image_path')
if scratch == "on" or rootType == "flash" or \
self.Get('cl_install_type') == 'flash':
self.Get('cl_install_type') == 'flash':
discardType = ["dir"]
else:
discardType = []
distros = self.getAvailableDristibutives(imagePath,
discardType=discardType)
discardType=discardType)
if self.wasSet and not self.value in distros:
distros.append(self.value)
return sorted(map(lambda x: (
x, self.humanImageName(self._getDistrInfo(x), x)), distros),
key=itemgetter(1))
key=itemgetter(1))
class VariableClImageArchMachine(Variable,DistroRepository):
class VariableClImageArchMachine(DistroRepository, Variable):
"""
Filter by architecture
"""
@ -371,73 +383,77 @@ class VariableClImageArchMachine(Variable,DistroRepository):
type = 'choice'
opt = ['--march']
metavalue = "ARCH"
available_arch = ["i686","x86_64"]
available_arch = ["i686", "x86_64"]
def init(self):
self.label = "%s %s"%(_("Filter"),_("by processor architecture"))
self.label = "%s %s" % (_("Filter"), _("by processor architecture"))
self.help = _("select the processor architecture")
def set(self,march):
def set(self, march):
if march == "auto":
march = getSupportArch()[-1]
return march
def choice(self):
return [("",_("Not used"))]+\
[("auto",_("Auto"))] + \
[(x,x) for x in self.available_arch]
return [("", _("Not used"))] + \
[("auto", _("Auto"))] + \
[(x, x) for x in self.available_arch]
def humanReadable(self):
return self.Get() or _("Not used")
class VariableClImageLinuxShortname(Variable,Linux,DistroRepository):
class VariableClImageLinuxShortname(DistroRepository, Variable):
"""
Filter by shortname
"""
value = ""
type = 'choiceedit'
metavalue = "SYSTEM"
opt = ['--os','-s']
opt = ['--os', '-s']
def init(self):
self.label = "%s %s"%(_("Filter"),_("by distribution"))
self.label = "%s %s" % (_("Filter"), _("by distribution"))
self.help = _("select the operation system")
def choice(self):
return [("",_("Not used"))]+\
sorted(map(lambda x:(x,self.getFullNameByShort(x)),
self.dictLinuxName.keys()),
key=itemgetter(1))
return [("", _("Not used"))] + \
sorted(map(lambda x: (x, self.getFullNameByShort(x)),
self.dictLinuxName.keys()),
key=itemgetter(1))
def humanReadable(self):
return self.Get() or _("Not used")
class VariableClImageLinuxVer(Variable,DistroRepository):
class VariableClImageLinuxVer(DistroRepository, Variable):
"""
Filter by version
"""
value = ""
def init(self):
self.label = "%s %s"%(_("Filter"),_("by version"))
self.label = "%s %s" % (_("Filter"), _("by version"))
self.help = _("select the operation system by version")
def humanReadable(self):
return self.Get() or _("Not used")
class VariableClImageLinuxBuild(Variable,DistroRepository):
class VariableClImageLinuxBuild(DistroRepository, Variable):
"""
Filter by build
"""
value = ""
def init(self):
self.label = "%s %s"%(_("Filter"),_("by build"))
self.label = "%s %s" % (_("Filter"), _("by build"))
self.help = _("select the operation system by build")
def humanReadable(self):
return self.Get() or _("Not used")
class VariableClImagePath(ReadonlyVariable):
"""
Image search path
@ -466,20 +482,20 @@ class VariableClImagePath(ReadonlyVariable):
'/run/initramfs/live',
'/mnt/cdrom']
livedistr = filter(listDirectory,
livedistr)[:1]
livedistr)[:1]
else:
livedistr = []
# search all partition for source installation distributive
rootDev = self.Get('os_install_root_dev')
livedistr += \
map(lambda x:x[0],
filter(lambda x:" live" in x[1] and x[0] != rootDev,
zip(self.Get('os_disk_dev'),
self.Get('os_disk_content'))))
map(lambda x: x[0],
filter(lambda x: " live" in x[1] and x[0] != rootDev,
zip(self.Get('os_disk_dev'),
self.Get('os_disk_content'))))
# add to standard path
return filter(path.exists,
['/var/calculate/remote/linux',
'/var/calculate/linux'] + livedistr)
['/var/calculate/remote/linux',
'/var/calculate/linux'] + livedistr)
class VariableClSource(ReadonlyVariable):
@ -491,6 +507,7 @@ class VariableClSource(ReadonlyVariable):
def get(self):
return DirectoryDistributive('/')
class VariableClTarget(ReadonlyVariable):
"""
Target distributive
@ -506,23 +523,18 @@ class VariableClTarget(ReadonlyVariable):
ver=self.Get('os_install_linux_ver'))
osInstallScratch = self.isTrue(self.Get('os_install_scratch'))
mapDevId = dict(self.ZipVars('os_disk_dev','os_disk_id'))
disk, mount, fileSystem, isFormat, partTable,systemId = \
mapDevId = dict(self.ZipVars('os_disk_dev', 'os_disk_id'))
disk, mount, fileSystem, isFormat, partTable, systemId = \
self.Select(listVars,
where='os_install_disk_mount',
eq='/',limit=1)
if not systemId or mapDevId.get(disk,'') == systemId:
eq='/', limit=1)
if not systemId or mapDevId.get(disk, '') == systemId:
systemId = None
if osInstallScratch:
target = ScratchPartitionDistributive(
disk, mdirectory=DefaultMountPath.InstallMount,
check=True, fileSystem=fileSystem,
isFormat=self.isTrue(isFormat),
systemId=systemId,
partitionTable=partTable)
elif self.Get('os_install_pxe') == "on":
raise VariableError("Scratch is not supported")
if self.Get('os_install_pxe') == "on":
return PxeDistributive(self.Get('os_install_pxe_path'))
elif self.Get('os_install_root_type')=="flash":
elif self.Get('os_install_root_type') == "flash":
flashLabel = "{short}-{build}".format(
short="CL", build=self.Get('os_install_linux_build'))
return FlashDistributive(
@ -545,41 +557,42 @@ class VariableClTarget(ReadonlyVariable):
ne='/')
bindData = self.Select(['os_install_bind_path',
'os_install_bind_mountpoint'],
where='os_install_bind_mountpoint',
ne='')
where='os_install_bind_mountpoint',
ne='')
if diskData or bindData:
multiPartition = MultiPartitions()
target.multipartition = multiPartition
for disk,mount,fileSystem,isFormat,partTable,systemId in diskData:
if not systemId or mapDevId.get(disk,'') == systemId:
for disk, mount, fileSystem, isFormat, partTable, systemId in diskData:
if not systemId or mapDevId.get(disk, '') == systemId:
systemId = None
multiPartition.addPartition(dev=disk,
mountPoint=mount,
fileSystem=fileSystem,
isFormat=self.isTrue(isFormat),
systemId=systemId,
partitionTable=partTable)
for source,dest in bindData:
mountPoint=mount,
fileSystem=fileSystem,
isFormat=self.isTrue(isFormat),
systemId=systemId,
partitionTable=partTable)
for source, dest in bindData:
multiPartition.addPartition(dev=source,
mountPoint=dest,
fileSystem='bind',
isFormat=False,
systemId=None,
partitionTable='')
mountPoint=dest,
fileSystem='bind',
isFormat=False,
systemId=None,
partitionTable='')
return target
class VariableClImageNewOnly(Variable):
"""
Distributive image filename
"""
type = 'bool'
opt = ['-U','--update']
opt = ['-U', '--update']
value = "off"
def init(self):
self.label = _("Install the newer image only")
self.help = _("install the newer image only")
def installedBuild(self):
"""
Get build already installed system
@ -590,20 +603,22 @@ class VariableClImageNewOnly(Variable):
return ""
try:
imageData = Distributive().getInfo(rootDev)
return imageData.get('os_linux_build','')
except:
return imageData.get('os_linux_build', '')
except Exception:
pass
return ""
def check(self,value):
def check(self, value):
if value == 'on':
try:
imageData = Distributive().getInfo(self.Get('cl_image_filename'))
imageData = Distributive().getInfo(
self.Get('cl_image_filename'))
except Exception as e:
raise VariableError(_("Wrong image file"))
if imageData.get('os_linux_build','') <= \
self.Get('os_linux_build') or \
imageData.get('os_linux_build','') <= self.installedBuild():
if imageData.get('os_linux_build', '') <= \
self.Get('os_linux_build') or \
imageData.get('os_linux_build',
'') <= self.installedBuild():
raise CommonVariableError(_("The image for update not found"))
@ -611,6 +626,7 @@ class VariableClInstallPathFrom(ReadonlyVariable):
"""
Путь из устанавливаемой системы до устанавливающий системы
"""
def get(self):
template_path = pathJoin(self.Get('cl_chroot_path'),
self.Get('cl_root_path'))

@ -1,6 +1,6 @@
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# Copyright 2008-2013 Calculate Ltd. http://www.calculate-linux.org
# Copyright 2008-2015 Calculate Ltd. http://www.calculate-linux.org
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -18,23 +18,26 @@ import os
import sys
import re
from os import path
from calculate.lib.datavars import (Variable,VariableError,ReadonlyVariable,
ReadonlyTableVariable, FieldValue)
from calculate.lib.datavars import (Variable, ReadonlyVariable,
ReadonlyTableVariable, FieldValue,
HumanReadable, VariableInterface)
from calculate.lib.utils.files import (readFile,
typeFile,process,listDirectory,MAGIC_SYMLINK,MAGIC_COMPRESS)
typeFile, process, listDirectory,
MAGIC_SYMLINK, MAGIC_COMPRESS)
from calculate.lib.cl_lang import setLocalTranslate
setLocalTranslate('cl_install3',sys.modules[__name__])
_ = lambda x: x
setLocalTranslate('cl_install3', sys.modules[__name__])
from operator import itemgetter
from calculate.lib.utils.files import readLinesFile,pathJoin
from calculate.lib.utils.common import (getKernelUid,getTupleVersion,
getValueFromCmdLine)
from calculate.lib.utils.device import getUdevDeviceInfo
from calculate.lib.utils.files import readLinesFile
from calculate.lib.utils.common import (getKernelUid, getTupleVersion,
getValueFromCmdLine)
from itertools import *
from contextlib import contextmanager
from calculate.install.distr import DistributiveError
class VariableOsInstallKernelScheduler(Variable):
"""
Install scheduler opts (cfq,bfq,none,deadline)
@ -49,20 +52,20 @@ class VariableOsInstallKernelScheduler(Variable):
def check_scheduler(self, scheduler):
return scheduler in self.Select('os_install_kernel_schedule_name',
where='os_install_kernel_schedule_set',
eq='on')
where='os_install_kernel_schedule_set',
eq='on')
def get_default(self):
root_dev = self.Select('os_install_disk_parent',
where='os_install_disk_mount',
eq='/',limit=1)
eq='/', limit=1)
if root_dev:
dev_ssd, dev_virtual = self.Select(['os_device_ssd_set',
'os_device_virtual_set'],
where='os_device_dev',
eq=root_dev,limit=1)
if ((dev_ssd == 'on' or dev_virtual == 'on')
and self.check_scheduler("noop")):
where='os_device_dev',
eq=root_dev, limit=1)
if ((dev_ssd == 'on' or dev_virtual == 'on') and
self.check_scheduler("noop")):
return "noop"
return self.Get('os_install_kernel_schedule_default')
@ -71,20 +74,20 @@ class VariableOsInstallKernelScheduler(Variable):
if self.Get('os_root_type') == 'livecd':
return self.get_default()
else:
currentScheduler = getValueFromCmdLine('elevator',0)
if currentScheduler in map(lambda x:x[0],self.choice()):
currentScheduler = getValueFromCmdLine('elevator', 0)
if currentScheduler in map(lambda x: x[0], self.choice()):
return currentScheduler
return self.Get('os_install_kernel_schedule_default')
def choice(self):
schedulers = {"deadline": "Deadline",
"cfq": "CFQ",
"noop": "No-op",
"bfq": "BFQ"}
return [(x, schedulers.get(x,x))
return [(x, schedulers.get(x, x))
for x in self.Select('os_install_kernel_schedule_name',
where='os_install_kernel_schedule_set',
eq='on')] + [("auto",_("Default"))]
eq='on')] + [("auto", _("Default"))]
def set(self, value):
if value == "auto":
@ -108,7 +111,7 @@ class KernelConfig:
return iter(self.data)
def __str__(self):
return "kernel config (%s)"%self.config
return "kernel config (%s)" % self.config
def __contains__(self, item):
if "=" in item:
@ -121,11 +124,11 @@ class KernelConfig:
return any(key in x for x in self)
class VariableOsInstallKernelConfig(ReadonlyVariable):
"""
Install config kernel filename
"""
def get_kernel_src(self, distr_path):
"""
Get version of kernel from .config
@ -135,9 +138,9 @@ class VariableOsInstallKernelConfig(ReadonlyVariable):
# get version from Makefile
re_makefile = re.compile("^VERSION = (\S+)\n"
"PATCHLEVEL = (\S+)\n"
"SUBLEVEL = (\S+)\n"
"EXTRAVERSION = (\S*)\n", re.M)
"PATCHLEVEL = (\S+)\n"
"SUBLEVEL = (\S+)\n"
"EXTRAVERSION = (\S*)\n", re.M)
if path.exists(makefile_path):
with open(makefile_path) as f:
match = re_makefile.search(f.read(200))
@ -148,23 +151,23 @@ class VariableOsInstallKernelConfig(ReadonlyVariable):
def configs(self, distr_path):
src_kernel_ver = self.get_kernel_src(distr_path)
if src_kernel_ver:
yield path.join("boot", "config-%s"%src_kernel_ver)
yield path.join("boot", "config-%s" % src_kernel_ver)
if self.Get('cl_chroot_path') == '/':
ver = process('/bin/uname','-r').read().strip()
yield path.join("boot", "config-%s"%ver)
ver = process('/bin/uname', '-r').read().strip()
yield path.join("boot", "config-%s" % ver)
yield 'usr/src/linux/.config'
def get(self):
image = self.Get('cl_image')
if image:
with image as distr:
with image:
try:
distrPath = image.getDirectory()
for config in self.configs(distrPath):
config_name = path.join(distrPath, config)
if path.exists(config_name):
return KernelConfig(config_name)
except DistributiveError as e:
except DistributiveError:
return ""
return ""
@ -184,8 +187,8 @@ class VariableOsInstallKernelScheduleDefault(Variable):
def choice(self):
return self.Select('os_install_kernel_schedule_name',
where='os_install_kernel_schedule_set',
eq='on')
where='os_install_kernel_schedule_set',
eq='on')
class VariableOsInstallKernelScheduleData(ReadonlyTableVariable):
@ -195,21 +198,21 @@ class VariableOsInstallKernelScheduleData(ReadonlyTableVariable):
source = ['os_install_kernel_schedule_name',
'os_install_kernel_schedule_set']
def get(self,hr=False):
installed = ['cfq']
schedulers = {'CONFIG_IOSCHED_BFQ=y':'bfq',
'CONFIG_IOSCHED_NOOP=y':'noop',
'CONFIG_IOSCHED_CFQ=y':'cfq',
'CONFIG_IOSCHED_DEADLINE=y':'deadline'}
def get(self, hr=HumanReadable.No):
schedulers = {'CONFIG_IOSCHED_BFQ=y': 'bfq',
'CONFIG_IOSCHED_NOOP=y': 'noop',
'CONFIG_IOSCHED_CFQ=y': 'cfq',
'CONFIG_IOSCHED_DEADLINE=y': 'deadline'}
installed = map(schedulers.get,
filter(lambda x:x in schedulers,
self.Get('os_install_kernel_config'))) or ['cfq']
return [[x,"on" if x in installed else "off"]
filter(lambda x: x in schedulers,
self.Get('os_install_kernel_config'))) or ['cfq']
return [[x, "on" if x in installed else "off"]
for x in sorted(schedulers.values())]
setValue = Variable.setValue
class VariableOsInstallKernelScheduleName(FieldValue,ReadonlyVariable):
class VariableOsInstallKernelScheduleName(FieldValue, ReadonlyVariable):
"""
Schedule name
"""
@ -217,7 +220,8 @@ class VariableOsInstallKernelScheduleName(FieldValue,ReadonlyVariable):
source_variable = "os_install_kernel_schedule_data"
column = 0
class VariableOsInstallKernelScheduleSet(FieldValue,ReadonlyVariable):
class VariableOsInstallKernelScheduleSet(FieldValue, ReadonlyVariable):
"""
Kernel has schedule
"""
@ -225,6 +229,7 @@ class VariableOsInstallKernelScheduleSet(FieldValue,ReadonlyVariable):
source_variable = "os_install_kernel_schedule_data"
column = 1
class VariableOsInstallKernelTuxoniceSet(ReadonlyVariable):
"""
Available BFQ in kernel
@ -237,6 +242,7 @@ class VariableOsInstallKernelTuxoniceSet(ReadonlyVariable):
return "on"
return "off"
class VariableOsInstallKernelBfqSet(ReadonlyVariable):
"""
Available BFQ in kernel
@ -249,10 +255,12 @@ class VariableOsInstallKernelBfqSet(ReadonlyVariable):
return "on"
return "off"
class VariableOsInstallKernelAttr(Variable):
"""
Install kernel attributes
"""
def get(self):
# on usb-hdd install must be "delay=5"
attr = ""
@ -268,102 +276,110 @@ class VariableOsInstallKernelAttr(Variable):
rdauto = " rd.auto"
return attr + rdauto
class VariableOsInstallKernelResume(ReadonlyVariable):
"""
Install kernel resume
"""
def get(self):
"""install kernel resume parameter"""
for dev, install in zip(self.Get('os_install_disk_use'),
self.Get('os_install_disk_mount')):
if install == "swap":
if self.Get('os_install_kernel_tuxonice_set') == 'on':
return \
"tuxonice tuxonice_resume=%s real_resume=%s"%(dev,dev)
return "tuxonice tuxonice_resume=%s real_resume=%s" % (
dev, dev)
else:
return "real_resume=%s"%dev
return "real_resume=%s" % dev
return ""
class KernelHelper:
class KernelHelper(VariableInterface):
"""
Helper for kernel variables
"""
reFindVer = re.compile(
"(?<=version )(\d+\.?\d*\.?\d*\.?\d*)([^\d* ])*(\d*)")
def getFilesByType(self,pathname,descr):
def getFilesByType(self, pathname, descr):
"""Get files from "pathname" has "descr" in descriptions"""
filelist = map(lambda x:path.join(pathname,x),os.listdir(pathname))
ftype = typeFile(magic=MAGIC_COMPRESS|MAGIC_SYMLINK).getMType
filesWithType = map(lambda x:(x,ftype(x)),
filter(path.exists,
filelist))
return filter(lambda x:descr in x[1],filesWithType)
def getInitrd(self,arch,shortname,chroot,kernel,suffix="",notsuffix=""):
filelist = map(lambda x: path.join(pathname, x), os.listdir(pathname))
ftype = typeFile(magic=MAGIC_COMPRESS | MAGIC_SYMLINK).getMType
filesWithType = map(lambda x: (x, ftype(x)),
filter(path.exists,
filelist))
return filter(lambda x: descr in x[1], filesWithType)
def getInitrd(self, arch, shortname, chroot, kernel, suffix="",
notsuffix=""):
"""Get initrd for kernel"""
reInitrdVer = re.compile("(initrd|initramfs)-(.+?)(-install)?$",re.S)
reInitrdVer = re.compile("(initrd|initramfs)-(.+?)(-install)?$", re.S)
def initrd_version_by_name(filename):
resInitrdVer = reInitrdVer.search(filename)
if resInitrdVer:
return resInitrdVer.groups()[1]
return ""
ftype = typeFile(magic=MAGIC_COMPRESS|MAGIC_SYMLINK).getMType
kernelfile = path.join(chroot,'boot',kernel)
ftype = typeFile(magic=MAGIC_COMPRESS | MAGIC_SYMLINK).getMType
kernelfile = path.join(chroot, 'boot', kernel)
typeKernelFile = ftype(kernelfile)
if typeKernelFile == None:
if typeKernelFile is None:
return ""
resKernelVer = self.reFindVer.search(ftype(kernelfile))
if resKernelVer:
kernelVersion = "%s-%s-%s"% \
(resKernelVer.group().replace('-calculate',''),
arch, shortname)
kernelVersion = "%s-%s-%s" % \
(resKernelVer.group().replace('-calculate', ''),
arch, shortname)
origKernelVer = resKernelVer.group()
bootdir = path.join(chroot,'boot')
initramfsFiles = self.getFilesByType(bootdir,"ASCII cpio archive")
bootdir = path.join(chroot, 'boot')
initramfsFiles = self.getFilesByType(bootdir, "ASCII cpio archive")
initramfsWithVer = \
filter(lambda x: (kernelVersion in x[1] or
origKernelVer in x[1]) and \
x[0].endswith(suffix) and \
(not notsuffix or not x[0].endswith(notsuffix)),
map(lambda x:(x[0],initrd_version_by_name(x[0])),
filter(lambda x: (kernelVersion in x[1] or
origKernelVer in x[1]) and \
x[0].endswith(suffix) and \
(
not notsuffix or not x[0].endswith(notsuffix)),
map(lambda x: (x[0], initrd_version_by_name(x[0])),
initramfsFiles))
if initramfsWithVer:
return path.split(min(initramfsWithVer,
key=itemgetter(0))[0])[-1]
key=itemgetter(0))[0])[-1]
return ""
class VariableOsInstallKernel(ReadonlyVariable,KernelHelper):
class VariableOsInstallKernel(ReadonlyVariable, KernelHelper):
"""
Kernel filename
"""
def get(self):
bootdir = path.join(self.Get('cl_chroot_path'),'boot')
modulesdir = path.join(self.Get('cl_chroot_path'),'lib/modules')
bootdir = path.join(self.Get('cl_chroot_path'), 'boot')
modulesdir = path.join(self.Get('cl_chroot_path'), 'lib/modules')
validKernel = listDirectory(modulesdir)
kernelFiles = self.getFilesByType(bootdir,"Linux kernel")
kernelFiles = self.getFilesByType(bootdir, "Linux kernel")
installMarch = self.Get('os_install_arch_machine')
kernelsWithVer = \
map(lambda x:(x[0],(getTupleVersion("".join(x[1].groups()[0:3:2])),
path.getmtime(x[0]))),
# convert version to tuple( versionTuple, mtime)
# version detect, for this version lib contains moudules
# kernel arch equal install arch
ifilter(lambda x:x[1] and x[1].group() in validKernel and
installMarch in x[0].rpartition('/')[2],
# (filename,version)
imap(lambda x:(x[0],self.reFindVer.search(x[1])),
kernelFiles)))
map(lambda x: (
x[0], (getTupleVersion("".join(x[1].groups()[0:3:2])),
path.getmtime(x[0]))),
# convert version to tuple( versionTuple, mtime)
# version detect, for this version lib contains moudules
# kernel arch equal install arch
ifilter(lambda x: x[1] and x[1].group() in validKernel and
installMarch in x[0].rpartition('/')[2],
# (filename,version)
imap(lambda x: (x[0], self.reFindVer.search(x[1])),
kernelFiles)))
if kernelsWithVer:
return path.split(max(kernelsWithVer,key=itemgetter(1))[0])[-1]
return path.split(max(kernelsWithVer, key=itemgetter(1))[0])[-1]
else:
return "vmlinuz"
class VariableOsInstallInitrd(ReadonlyVariable,KernelHelper):
class VariableOsInstallInitrd(ReadonlyVariable, KernelHelper):
"""
Optimized initramfs filename
"""
@ -373,18 +389,20 @@ class VariableOsInstallInitrd(ReadonlyVariable,KernelHelper):
self.Get('os_install_linux_shortname'),
self.Get('cl_chroot_path'),
self.Get('os_install_kernel'),
suffix="",notsuffix="-install") or \
suffix="", notsuffix="-install") or \
self.getInitrd(self.Get('os_install_arch_machine'),
self.Get('os_install_linux_shortname'),
self.Get('cl_chroot_path'),
self.Get('os_install_kernel'),
suffix="-install")[:-8] \
or "initrd"
or "initrd"
class VariableOsInstallInitrdInstall(ReadonlyVariable,KernelHelper):
class VariableOsInstallInitrdInstall(ReadonlyVariable, KernelHelper):
"""
Install initramfs filename
"""
def get(self):
return self.getInitrd(self.Get('os_install_arch_machine'),
self.Get('os_install_linux_shortname'),
@ -397,33 +415,37 @@ class VariableOsInstallSystemMap(ReadonlyVariable):
"""
Install system map filename
"""
def get(self):
systemmapfile = self.Get('os_install_kernel').replace('vmlinuz',
'System.map')
'System.map')
if systemmapfile.startswith('System.map') and path.exists(
path.join(self.Get('cl_chroot_path'),'boot',systemmapfile)):
path.join(self.Get('cl_chroot_path'), 'boot', systemmapfile)):
return systemmapfile
else:
return ""
class VariableOsInstallKernelCpufreq(ReadonlyVariable):
"""
Cpufreq modules
"""
def get(self):
"""Get cpufreq (and other from modules_3= param) from conf.d/modules"""
cpufreqmods = map(lambda x:x.partition('=')[2].strip("\n '\""),
filter(lambda x:x.startswith('modules_3'),
readLinesFile('/etc/conf.d/modules')))
cpufreqmods = map(lambda x: x.partition('=')[2].strip("\n '\""),
filter(lambda x: x.startswith('modules_3'),
readLinesFile('/etc/conf.d/modules')))
if cpufreqmods:
return cpufreqmods[0]
else:
return ""
class VariableClInstallKernelUid(ReadonlyVariable):
"""
Variable install kernel UID
"""
def get(self):
return getKernelUid(self.Get('os_install_root_dev'))

@ -1,6 +1,6 @@
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# Copyright 2008-2013 Calculate Ltd. http://www.calculate-linux.org
# Copyright 2008-2015 Calculate Ltd. http://www.calculate-linux.org
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -14,25 +14,24 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import sys
from os import path
from calculate.lib.datavars import Variable,VariableError,ReadonlyVariable
from calculate.lib.variables.linux import (Linux,VariableOsLinuxName,
VariableOsLinuxSystem,VariableOsLinuxSubname)
from calculate.lib.datavars import ReadonlyVariable, VariableInterface
from calculate.lib.variables.linux import Linux
from calculate.lib.cl_lang import setLocalTranslate
setLocalTranslate('cl_install3',sys.modules[__name__])
class InstallLinux(Linux):
def __getFromImageOrCurrent(self,currentVar):
setLocalTranslate('cl_install3', sys.modules[__name__])
class InstallLinux(Linux, VariableInterface):
def __getFromImageOrCurrent(self, currentVar):
"""Get value from install image or current system"""
if self.Get('cl_action') == 'system':
image = self.Get('cl_image')
if image:
d = image.getInfo()
# support lazy values
res = d.get(currentVar,"")
res = d.get(currentVar, "")
return str(res()) if callable(res) else res
else:
return ""
@ -48,39 +47,47 @@ class InstallLinux(Linux):
"""Get by distroinfo or current info"""
return self.__getFromImageOrCurrent(self.current_variable)
class VariableOsInstallLinuxShortname(InstallLinux,ReadonlyVariable):
class VariableOsInstallLinuxShortname(InstallLinux, ReadonlyVariable):
"""Shortname of system"""
current_variable = "os_linux_shortname"
class VariableOsInstallLinuxVer(InstallLinux,ReadonlyVariable):
"""Shortname of system"""
class VariableOsInstallLinuxVer(InstallLinux, ReadonlyVariable):
"""Version of system"""
current_variable = "os_linux_ver"
class VariableOsInstallLinuxBuild(InstallLinux,ReadonlyVariable):
"""Shortname of system"""
class VariableOsInstallLinuxBuild(InstallLinux, ReadonlyVariable):
"""Build of system"""
current_variable = "os_linux_build"
class VariableOsInstallArchMachine(InstallLinux,ReadonlyVariable):
"""Shortname of system"""
class VariableOsInstallArchMachine(InstallLinux, ReadonlyVariable):
"""Arch of system"""
current_variable = "os_arch_machine"
class VariableOsInstallLinuxFiles(InstallLinux,ReadonlyVariable):
"""Shortname of system"""
class VariableOsInstallLinuxFiles(InstallLinux, ReadonlyVariable):
"""Files num in system"""
current_variable = "os_linux_files"
class VariableOsInstallLinuxName(InstallLinux,ReadonlyVariable):
class VariableOsInstallLinuxName(InstallLinux, ReadonlyVariable):
"""
Install distro name
"""
current_variable = "os_linux_name"
class VariableOsInstallLinuxSystem(InstallLinux,ReadonlyVariable):
class VariableOsInstallLinuxSystem(InstallLinux, ReadonlyVariable):
"""
Install system name
"""
current_variable = "os_linux_system"
class VariableOsInstallLinuxSubname(InstallLinux,ReadonlyVariable):
class VariableOsInstallLinuxSubname(InstallLinux, ReadonlyVariable):
"""
Install subname
"""

@ -1,6 +1,6 @@
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# Copyright 2008-2013 Calculate Ltd. http://www.calculate-linux.org
# Copyright 2008-2015 Calculate Ltd. http://www.calculate-linux.org
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -14,24 +14,26 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import sys
from os import path
from calculate.lib.datavars import Variable, VariableError, ReadonlyVariable
from calculate.lib.variables.locale import Locale
from calculate.lib.utils.files import readLinesFile, process
from calculate.lib.utils.common import getValueFromCmdLine, getValueFromConfig
from pytz import timezone,country_timezones,UnknownTimeZoneError
from pytz import timezone, country_timezones, UnknownTimeZoneError
from datetime import datetime
from operator import itemgetter
from calculate.lib.cl_lang import setLocalTranslate
setLocalTranslate('cl_install3',sys.modules[__name__])
from calculate.lib.cl_lang import setLocalTranslate, _
class LocaleVariable(ReadonlyVariable,Locale):
setLocalTranslate('cl_install3', sys.modules[__name__])
class LocaleVariable(ReadonlyVariable, Locale):
"""
Locale variables not using for flash installation
"""
def uncompatible(self):
"""
Network setting up unavailable for flash installation
@ -41,6 +43,7 @@ class LocaleVariable(ReadonlyVariable,Locale):
_("Locale configuration unavailable for Flash install")
return ""
class VariableOsInstallLinguas(LocaleVariable):
"""
Current LINGUAS value
@ -49,74 +52,79 @@ class VariableOsInstallLinguas(LocaleVariable):
def get(self):
def get_linguas(lines):
linguas = map(lambda x:x.strip().rpartition('=')[-1].strip('"\''),
filter(lambda x: x.startswith("LINGUAS="),
lines))
linguas = map(lambda x: x.strip().rpartition('=')[-1].strip('"\''),
filter(lambda x: x.startswith("LINGUAS="),
lines))
return linguas[-1] if linguas else ""
makeconf = '/etc/make.conf'
emerge_config = self.Get('cl_emerge_config')
if emerge_config and "LINGUAS" in emerge_config:
return emerge_config['LINGUAS'].encode('UTF-8')
infocommand = ['emerge','--info']
infocommand = ['emerge', '--info']
defaultLinguas = "bg en de es fr it pl pt_BR nl ru uk"
# get linguas from make.conf, emerge --info or default
curlanguage = self.Get('os_install_locale_language')
return get_linguas(readLinesFile(makeconf)) or \
" ".join(filter(lambda x:x=="en" or x==curlanguage,
get_linguas(
process(*infocommand).readlines() or "").split())) or \
" ".join(filter(lambda x: x == "en" or x == curlanguage,
get_linguas(
process(
*infocommand).readlines() or "").split())) or \
defaultLinguas
class VariableOsInstallLocaleConsolefont(LocaleVariable):
"""
Consolefont for locale
"""
def get(self):
return self.getFieldByKeymap("consolefont",
self.Get('os_install_locale_keymap'))
self.Get('os_install_locale_keymap'))
class VariableOsInstallLocaleKeymap(LocaleVariable):
"""
Keymap of locale (used for /etc/conf.d/keymaps)
"""
def get(self):
# get keymap from boot calculate param (keymap specified
# by lang)
keymapConfd = '/etc/conf.d/keymaps'
keymap = getValueFromCmdLine("calculate",1)
keymap = getValueFromCmdLine("calculate", 1)
if self.isLangExists(keymap):
return self.getFieldByLang('keymap',keymap)
# get keymap by os_install_locale_lang
# Temporary comment get keymap from config file
#keymap = getValueFromConfig(keymapConfd,'KEYMAP')
#if keymap:
# return keymap
return self.getFieldByLang('keymap', keymap)
return self.getFieldByLang("keymap",
self.Get("os_install_locale_lang"))
self.Get("os_install_locale_lang"))
class VariableOsInstallLocaleDumpkeys(LocaleVariable):
"""
Dumpkeys_charset for keymap
"""
def get(self):
# is specified keymap support by locale hash
if self.Get('os_install_locale_keymap') in self.getFields('keymap'):
return self.getFieldByKeymap("dumpkeys_charset",
self.Get('os_install_locale_keymap'))
self.Get('os_install_locale_keymap'))
else:
return self.getFieldByLang("dumpkeys_charset",
self.Get('os_install_locale_lang'))
self.Get('os_install_locale_lang'))
class VariableOsInstallLocaleLocale(LocaleVariable):
"""
Locale (at example: ru_RU.UTF-8)
"""
def get(self):
"""locale (example: ru_RU.UTF-8)"""
return self.getFieldByLang("locale",
self.Get('os_install_locale_lang'))
self.Get('os_install_locale_lang'))
class VariableOsInstallLocaleLang(LocaleVariable):
"""
@ -125,7 +133,7 @@ class VariableOsInstallLocaleLang(LocaleVariable):
mode = 'w'
metavalue = "LANG"
type = 'choice'
opt = ["--lang","-l"]
opt = ["--lang", "-l"]
def init(self):
self.label = _("Language")
@ -137,28 +145,35 @@ class VariableOsInstallLocaleLang(LocaleVariable):
def choice(self):
return sorted(zip(self.Get('os_lang'),
map(str,self.Get('os_lang',humanreadable=True))),key=itemgetter(1))
map(str, self.Get('os_lang', humanreadable=True))),
key=itemgetter(1))
class VariableOsInstallLocaleLanguage(LocaleVariable):
"""
Short language (at example ru)
"""
def get(self):
return self.getFieldByLang("language",
self.Get('os_install_locale_lang'))
self.Get('os_install_locale_lang'))
class VariableOsInstallLocaleXkb(LocaleVariable):
"""
Keyboard layout for X server
"""
def get(self):
return self.getFieldByLang("xkblayout",
self.Get('os_install_locale_lang'))
self.Get('os_install_locale_lang'))
class VariableOsInstallLocaleXkbname(LocaleVariable):
"""
Keyboard layout name for X server
"""
def get(self):
localeXkb = self.Get("os_install_locale_xkb")
if localeXkb:
@ -182,131 +197,135 @@ class VariableOsInstallClockTimezone(LocaleVariable):
def get(self):
return self.Get('os_clock_timezone')
def check(self,value):
def check(self, value):
if not value or not path.isfile(path.join(
"/usr/share/zoneinfo",value)):
raise VariableError(_("Wrong timezone %s")%value)
"/usr/share/zoneinfo", value)):
raise VariableError(_("Wrong timezone %s") % value)
def generateComments(self,tzs):
def generateComments(self, tzs):
"""
Generate comments by timezone names
"""
for tzname in tzs:
# add separator
if tzname == "---":
yield ("---","---")
yield ("---", "---")
continue
try:
tz = timezone(tzname)
strinfo = tz.localize(datetime.now()).strftime('%z')
yield (tzname,"%s (%s:%s)"%(tzname,strinfo[:3],strinfo[-2:]))
yield (
tzname, "%s (%s:%s)" % (tzname, strinfo[:3], strinfo[-2:]))
except UnknownTimeZoneError:
pass
def choice(self):
source = ["Etc/GMT-12",
"Pacific/Midway",
"Pacific/Honolulu",
"America/Anchorage",
"Canada/Pacific",
"America/Tijuana",
"America/Phoenix",
"America/Denver",
"America/Mazatlan",
"America/Monterrey",
"America/Regina",
"America/Mexico_City",
"Canada/Central",
"America/Bogota",
"America/New_York",
"America/Indiana/Indianapolis",
"America/Halifax",
"America/Caracas",
"America/Manaus",
"America/Santiago",
"America/St_Johns",
"America/Sao_Paulo",
"America/Argentina/Buenos_Aires",
"Etc/GMT+3",
"America/Montevideo",
"Atlantic/South_Georgia",
"Atlantic/Azores",
"Atlantic/Cape_Verde",
"UTC",
"Africa/Casablanca",
"Europe/Amsterdam",
"Europe/Belgrade",
"Europe/Brussels",
"Europe/Zagreb",
"Africa/Tunis",
"Europe/Kaliningrad",
"Asia/Amman",
"Europe/Istanbul",
"Asia/Beirut",
"Europe/Helsinki",
"Europe/Kiev",
"Europa/Sofia",
"Africa/Windhoek",
"Asia/Jerusalem",
"Africa/Cairo",
"Europe/Minsk",
"Africa/Harare",
"Europe/Moscow",
"Asia/Baghdad",
"Asia/Kuwait",
"Africa/Nairobi",
"Asia/Tbilisi",
"Asia/Tehran",
"Europe/Samara",
"Asia/Muscat",
"Asia/Baku",
"Asia/Yerevan",
"Asia/Kabul",
"Asia/Yekaterinburg",
"Asia/Karachi",
"Asia/Calcutta",
"Asia/Jayapura",
"Asia/Katmandu",
"Asia/Almaty",
"Asia/Omsk",
"Asia/Dhaka",
"Asia/Rangoon",
"Asia/Krasnoyarsk",
"Asia/Bangkok",
"Asia/Irkutsk",
"Asia/Hong_Kong",
"Asia/Singapore",
"Australia/Perth",
"Asia/Taipei",
"Asia/Yakutsk",
"Asia/Tokyo",
"Asia/Seoul",
"Australia/Adelaide",
"Australia/Darwin",
"Asia/Vladivostok",
"Australia/Brisbane",
"Pacific/Guam",
"Australia/Melbourne",
"Australia/Hobart",
"Asia/Srednekolymsk",
"Asia/Kamchatka",
"Pacific/Auckland",
"Etc/GMT-13"]
"Pacific/Midway",
"Pacific/Honolulu",
"America/Anchorage",
"Canada/Pacific",
"America/Tijuana",
"America/Phoenix",
"America/Denver",
"America/Mazatlan",
"America/Monterrey",
"America/Regina",
"America/Mexico_City",
"Canada/Central",
"America/Bogota",
"America/New_York",
"America/Indiana/Indianapolis",
"America/Halifax",
"America/Caracas",
"America/Manaus",
"America/Santiago",
"America/St_Johns",
"America/Sao_Paulo",
"America/Argentina/Buenos_Aires",
"Etc/GMT+3",
"America/Montevideo",
"Atlantic/South_Georgia",
"Atlantic/Azores",
"Atlantic/Cape_Verde",
"UTC",
"Africa/Casablanca",
"Europe/Amsterdam",
"Europe/Belgrade",
"Europe/Brussels",
"Europe/Zagreb",
"Africa/Tunis",
"Europe/Kaliningrad",
"Asia/Amman",
"Europe/Istanbul",
"Asia/Beirut",
"Europe/Helsinki",
"Europe/Kiev",
"Europa/Sofia",
"Africa/Windhoek",
"Asia/Jerusalem",
"Africa/Cairo",
"Europe/Minsk",
"Africa/Harare",
"Europe/Moscow",
"Asia/Baghdad",
"Asia/Kuwait",
"Africa/Nairobi",
"Asia/Tbilisi",
"Asia/Tehran",
"Europe/Samara",
"Asia/Muscat",
"Asia/Baku",
"Asia/Yerevan",
"Asia/Kabul",
"Asia/Yekaterinburg",
"Asia/Karachi",
"Asia/Calcutta",
"Asia/Jayapura",
"Asia/Katmandu",
"Asia/Almaty",
"Asia/Omsk",
"Asia/Dhaka",
"Asia/Rangoon",
"Asia/Krasnoyarsk",
"Asia/Bangkok",
"Asia/Irkutsk",
"Asia/Hong_Kong",
"Asia/Singapore",
"Australia/Perth",
"Asia/Taipei",
"Asia/Yakutsk",
"Asia/Tokyo",
"Asia/Seoul",
"Australia/Adelaide",
"Australia/Darwin",
"Asia/Vladivostok",
"Australia/Brisbane",
"Pacific/Guam",
"Australia/Melbourne",
"Australia/Hobart",
"Asia/Srednekolymsk",
"Asia/Kamchatka",
"Pacific/Auckland",
"Etc/GMT-13"]
def sortkey(s):
tz = timezone(s)
strinfo = tz.localize(datetime.now()).strftime('%z')
return (int(strinfo[:3]),int("%s%s"%(strinfo[0],strinfo[-2:])))
return int(strinfo[:3]), int("%s%s" % (strinfo[0], strinfo[-2:]))
try:
lang = self.Get('os_install_locale_lang').split('_')[1]
nativeTZ = map(lambda x:x.encode('utf-8'),
country_timezones[lang])
nativeTZ = map(lambda x: x.encode('utf-8'),
country_timezones[lang])
source = nativeTZ + ["---"] + \
sorted(filter(lambda x:not x in nativeTZ,source),
key=sortkey)
except (KeyError,IndexError) as e:
sorted(filter(lambda x: not x in nativeTZ, source),
key=sortkey)
except (KeyError, IndexError):
pass
return list(self.generateComments(source))
class VariableOsInstallClockType(Variable):
"""
Type of clock (UTC or local)
@ -321,9 +340,9 @@ class VariableOsInstallClockType(Variable):
def get(self):
"""type of clock (UTC or local)"""
clockTypeFile = ['/etc/conf.d/clock','/etc/conf.d/hwclock']
clockTypeFile = ['/etc/conf.d/clock', '/etc/conf.d/hwclock']
for f in clockTypeFile:
clock = getValueFromConfig(f,"clock")
clock = getValueFromConfig(f, "clock")
if clock:
if clock.upper() == 'UTC':
return clock.upper()
@ -332,4 +351,4 @@ class VariableOsInstallClockType(Variable):
return "local"
def choice(self):
return ["local","UTC"]
return ["local", "UTC"]

@ -1,6 +1,6 @@
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# Copyright 2008-2013 Calculate Ltd. http://www.calculate-linux.org
# Copyright 2008-2015 Calculate Ltd. http://www.calculate-linux.org
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -14,38 +14,33 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import sys
import re
import pty,fcntl
from subprocess import Popen
from os import path
from itertools import *
from calculate.lib.datavars import (TableVariable,Variable,VariableError,
ReadonlyVariable,ReadonlyTableVariable,
FieldValue)
from calculate.lib.utils.files import (process,checkUtils)
from calculate.install.distr import PartitionDistributive
from calculate.install.fs_manager import FileSystemManager
from calculate.lib.datavars import (Variable, VariableInterface,
ReadonlyVariable, ReadonlyTableVariable,
FieldValue, HumanReadable)
from calculate.lib.utils.files import (process, checkUtils)
from calculate.lib.cl_lang import setLocalTranslate
setLocalTranslate('cl_install3',sys.modules[__name__])
class LvmHelper:
setLocalTranslate('cl_install3', sys.modules[__name__])
class LvmHelper(VariableInterface):
def getLvmData(self):
"""Get route table, exclude specifed iface"""
pvDisplayProg = checkUtils('/sbin/pvdisplay')
pvDisplay = process(pvDisplayProg,"--noh","-Co",
"lv_name,vg_name,pv_name")
pvDisplay = process(pvDisplayProg, "--noh", "-Co",
"lv_name,vg_name,pv_name")
for line in pvDisplay:
line = line.split()
if len(line) == 3:
yield line
#######################################################
# Devices variables
#######################################################
class VariableOsLvmData(ReadonlyTableVariable,LvmHelper):
class VariableOsLvmData(ReadonlyTableVariable, LvmHelper):
"""
Information about disk devices
"""
@ -53,13 +48,14 @@ class VariableOsLvmData(ReadonlyTableVariable,LvmHelper):
'os_lvm_vgname',
'os_lvm_pvname']
def get(self,hr=False):
def get(self, hr=HumanReadable.No):
"""LVM hash"""
return list(self.getLvmData()) or [[]]
setValue = Variable.setValue
class VariableOsLvmLvname(FieldValue,ReadonlyVariable):
class VariableOsLvmLvname(FieldValue, ReadonlyVariable):
"""
Logical volumes names
"""
@ -67,7 +63,8 @@ class VariableOsLvmLvname(FieldValue,ReadonlyVariable):
source_variable = "os_lvm_data"
column = 0
class VariableOsLvmVgname(FieldValue,ReadonlyVariable):
class VariableOsLvmVgname(FieldValue, ReadonlyVariable):
"""
Volume groups names
"""
@ -75,7 +72,8 @@ class VariableOsLvmVgname(FieldValue,ReadonlyVariable):
source_variable = "os_lvm_data"
column = 1
class VariableOsLvmPvname(FieldValue,ReadonlyVariable):
class VariableOsLvmPvname(FieldValue, ReadonlyVariable):
"""
Phisical volumes names
"""

@ -1,6 +1,6 @@
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# Copyright 2008-2013 Calculate Ltd. http://www.calculate-linux.org
# Copyright 2008-2015 Calculate Ltd. http://www.calculate-linux.org
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -14,35 +14,36 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import sys
import re
from os import path,readlink
from calculate.lib.datavars import Variable,VariableError,ReadonlyVariable, \
READONLY, TableVariable,FieldValue
from os import path, readlink
from calculate.lib.datavars import (Variable, VariableError, ReadonlyVariable,
READONLY, TableVariable, FieldValue,
VariableInterface, HumanReadable)
from calculate.lib.cl_lang import setLocalTranslate
setLocalTranslate('cl_install3',sys.modules[__name__])
from calculate.lib.cl_lang import setLocalTranslate, _
from calculate.lib.utils.ip import (getInterfaces,getIp,getMask,getMac,
cidrToMask,maskToCidr,getIpNet,isDhcpIp,checkIp,checkMask,
getOperState,getPlugged)
setLocalTranslate('cl_install3', sys.modules[__name__])
from calculate.lib.utils.ip import (getInterfaces, getIp, getMask, getMac,
cidrToMask, maskToCidr, getIpNet, isDhcpIp,
checkIp, checkMask,
getOperState, getPlugged)
from calculate.lib.utils.device import lspci
from calculate.lib.utils.files import listDirectory,readLinesFile,process,\
readFile
from calculate.lib.utils.files import (listDirectory, readLinesFile)
from calculate.lib.utils import ip
from calculate.lib.utils.portage import isPkgInstalled
from operator import itemgetter
from itertools import *
from functools import partial
import hashlib
from calculate.install.distr import DistributiveError
class NetHelper:
class NetHelper(VariableInterface):
"""
Network variables not using for flash installation
"""
routing = False
def uncompatible(self):
"""
Network setting up unavailable for flash installation
@ -51,13 +52,14 @@ class NetHelper:
return \
_("Network configuration is unavailable for Flash install")
if self.routing and not self.Select('os_install_net_interfaces',
where='os_install_net_status',
_notin=('off','dhcp'),limit=1):
where='os_install_net_status',
_notin=('off', 'dhcp'), limit=1):
return _("Network routing configuration is not available if all "
"interfaces are set to DHCP")
return ""
class VariableOsInstallNtp(NetHelper,Variable):
class VariableOsInstallNtp(NetHelper, Variable):
"""
NTP server for system
"""
@ -69,13 +71,15 @@ class VariableOsInstallNtp(NetHelper,Variable):
self.label = _("NTP server")
self.help = _("set the NTP server for the system")
class VariableOsInstallProxy(NetHelper,Variable):
class VariableOsInstallProxy(NetHelper, Variable):
"""
Proxy for system
"""
value = ""
class VariableOsInstallNetInterfaces(NetHelper,ReadonlyVariable):
class VariableOsInstallNetInterfaces(NetHelper, ReadonlyVariable):
"""
Net interface devices
"""
@ -87,7 +91,8 @@ class VariableOsInstallNetInterfaces(NetHelper,ReadonlyVariable):
def get(self):
return sorted(getInterfaces())
class VariableOsInstallNetInterfacesOrig(NetHelper,ReadonlyVariable):
class VariableOsInstallNetInterfacesOrig(NetHelper, ReadonlyVariable):
"""
Net interface devices orig name from udev (enp0s2)
Depricated
@ -97,26 +102,30 @@ class VariableOsInstallNetInterfacesOrig(NetHelper,ReadonlyVariable):
def get(self):
return self.Get('os_install_net_interfaces')
class VariableOsNetInterfacesInfo(NetHelper,ReadonlyVariable):
class VariableOsNetInterfacesInfo(NetHelper, ReadonlyVariable):
"""
Inforamation about net interfaces
"""
def get(self):
netInterfaces=self.Get("os_net_interfaces")
self.Get("os_net_interfaces")
listInterfacesInfo = []
# Получена ли сеть по DHCP если нет to ip или off
for interface,ipaddr,dhcp in zip(self.Get('os_install_net_interfaces'),
self.Get('os_install_net_ip'),
self.Get('os_install_net_dhcp_set')):
for interface, ipaddr, dhcp in zip(
self.Get('os_install_net_interfaces'),
self.Get('os_install_net_ip'),
self.Get('os_install_net_dhcp_set')):
if dhcp == "on":
listInterfacesInfo.append((interface, _("DHCP")))
else:
listInterfacesInfo.append((interface,
ipaddr if ipaddr else _("Off")))
return ", ".join(map(lambda x:"%s (%s)"%(x[0],x[1]),
return ", ".join(map(lambda x: "%s (%s)" % (x[0], x[1]),
listInterfacesInfo))
class VariableOsInstallNetData(NetHelper,TableVariable):
class VariableOsInstallNetData(NetHelper, TableVariable):
"""
Hash for information about net
"""
@ -135,27 +144,31 @@ class VariableOsInstallNetData(NetHelper,TableVariable):
return ifaces[0]
else:
return "enp0s0"
self.label = _("Addresses")
# self.help = _("IP address with network (example:%s)")%"192.168.1.1/24"
# self.help = _("IP address with network (example:%s)")%"192.168.1.1/24"
self.help = _("Network interface, DHCP or IP address and network mask "
"(example: %s)")%(" --iface %s:192.168.1.1:24"%
defaultInterface())
"(example: %s)") % (" --iface %s:192.168.1.1:24" %
defaultInterface())
def raiseReadonlyIndexError(self,fieldname="",variablename="",
def raiseReadonlyIndexError(self, fieldname="", variablename="",
value=""):
"""
Behavior on change readonly index
"""
raise VariableError(_("Network interface %s not found")%value)
raise VariableError(_("Network interface %s not found") % value)
class VariableOsInstallNetHostname(NetHelper,Variable):
class VariableOsInstallNetHostname(NetHelper, Variable):
"""
Computer hostname
"""
def get(self):
return self.Get('os_install_net_fqdn').partition('.')[0]
class VariableOsInstallNetFqdn(NetHelper,Variable):
class VariableOsInstallNetFqdn(NetHelper, Variable):
"""
Full host name
"""
@ -166,41 +179,46 @@ class VariableOsInstallNetFqdn(NetHelper,Variable):
self.label = _("Hostname")
self.help = _("set either the short or the full hostname")
def set(self,value):
def set(self, value):
if "." in value:
return value
else:
return "%s.%s"%(value,self.Get('os_install_net_domain'))
return "%s.%s" % (value, self.Get('os_install_net_domain'))
def check(self,value):
def check(self, value):
maxfqdn = 254
if len(value) > maxfqdn:
raise VariableError(
_("The hostname length should be less than %d")%maxfqdn)
_("The hostname length should be less than %d") % maxfqdn)
def get(self):
if path.exists('/proc/self/fd/1') and \
readlink('/proc/self/fd/1') == '/dev/console' and \
self.Get('os_root_dev') == '/dev/nfs':
readlink('/proc/self/fd/1') == '/dev/console' and \
self.Get('os_root_dev') == '/dev/nfs':
return "calculate.local"
return self.Get('os_net_fqdn')
class VariableOsInstallNetDomain(NetHelper,Variable):
class VariableOsInstallNetDomain(NetHelper, Variable):
"""
Domain on install system
"""
def get(self):
return self.Get('os_install_net_fqdn').partition('.')[2]
class VariableOsInstallNetAllow(NetHelper,Variable):
class VariableOsInstallNetAllow(NetHelper, Variable):
"""
Allowed network
"""
def get(self):
"""Allowed network"""
return self.Get("os_net_allow")
class VariableOsInstallNetName(NetHelper,ReadonlyVariable):
class VariableOsInstallNetName(NetHelper, ReadonlyVariable):
"""
Net device names
"""
@ -211,22 +229,25 @@ class VariableOsInstallNetName(NetHelper,ReadonlyVariable):
def get(self):
rePci = re.compile(r"(\d\d:\d\d\.\d)(?:/[^/]+){2}$")
def getPci(interface):
pathname = path.realpath(path.join('/sys/class/net',
interface))
interface))
pci = rePci.search(pathname)
if pci:
return pci.group(1)
else:
return ""
pciEthernet = lspci(shortInfo=True)
return map(lambda x:"{vendor} {name}".format(**x),
map(lambda x:pciEthernet.get(getPci(x),
{'vendor':_("Unknown"),
'name':_("vendor")}),
self.Get('os_install_net_interfaces')))
return map(lambda x: "{vendor} {name}".format(**x),
map(lambda x: pciEthernet.get(getPci(x),
{'vendor': _("Unknown"),
'name': _("vendor")}),
self.Get('os_install_net_interfaces')))
class VariableOsInstallNetMac(NetHelper,ReadonlyVariable):
class VariableOsInstallNetMac(NetHelper, ReadonlyVariable):
"""
Net devices mac (Example: 01:02:03:04:05:06)
"""
@ -236,10 +257,11 @@ class VariableOsInstallNetMac(NetHelper,ReadonlyVariable):
self.label = _("MAC")
def get(self):
return map(lambda x:getMac(x).lower(),
self.Get('os_install_net_interfaces'))
return map(lambda x: getMac(x).lower(),
self.Get('os_install_net_interfaces'))
class VariableOsInstallNetStatus(NetHelper,Variable):
class VariableOsInstallNetStatus(NetHelper, Variable):
"""
Net status (dhcp,ip,or off)
"""
@ -250,10 +272,10 @@ class VariableOsInstallNetStatus(NetHelper,Variable):
def get(self):
return map(self.getDefaultValue,
self.Get('os_install_net_interfaces'))
self.Get('os_install_net_interfaces'))
def getDefaultValue(self,iface):
def statusValue(ipaddr,dhcp):
def getDefaultValue(self, iface):
def statusValue(ipaddr, dhcp):
if not getPlugged(iface):
return 'off'
if dhcp == "on":
@ -265,29 +287,31 @@ class VariableOsInstallNetStatus(NetHelper,Variable):
return "off"
else:
return "dhcp"
rootDevNfs = self.Get('os_root_dev') == '/dev/nfs'
return statusValue(getIp(iface),"on" \
if rootDevNfs or isDhcpIp(iface) else "off")
return statusValue(getIp(iface), "on" \
if rootDevNfs or isDhcpIp(iface) else "off")
def set(self,value):
value = map(lambda x:x.lower() if x else x,value)
def set(self, value):
value = map(lambda x: x.lower() if x else x, value)
ifaces = self.Get('os_install_net_interfaces')
return map(lambda x:self.getDefaultValue(x[1]) \
if x[0] == "auto" else x[0],
zip(value,ifaces))
return map(lambda x: self.getDefaultValue(x[1]) \
if x[0] == "auto" else x[0],
zip(value, ifaces))
def check(self,value):
def check(self, value):
for status in value:
if status not in map(lambda x:x[0],self.choice()) and \
not checkIp(status):
raise VariableError(_("Wrong IP address %s")%status)
if status not in map(lambda x: x[0], self.choice()) and \
not checkIp(status):
raise VariableError(_("Wrong IP address %s") % status)
def choice(self):
return (("dhcp",_("DHCP")),
return (("dhcp", _("DHCP")),
("off", _("Disabled")),
("auto", _("Auto")))
class VariableOsInstallNetIp(NetHelper,ReadonlyVariable):
class VariableOsInstallNetIp(NetHelper, ReadonlyVariable):
"""
IP for all network interfaces
"""
@ -297,20 +321,21 @@ class VariableOsInstallNetIp(NetHelper,ReadonlyVariable):
self.label = _("IP address")
def get(self):
return map(lambda x:"" if x[1].lower() == "off" else
getIp(x[0]) if x[1].lower() == "dhcp" else x[1],
zip(self.Get('os_install_net_interfaces'),
self.Get('os_install_net_status')))
return map(lambda x: "" if x[1].lower() == "off" else
getIp(x[0]) if x[1].lower() == "dhcp" else x[1],
zip(self.Get('os_install_net_interfaces'),
self.Get('os_install_net_status')))
# def check(self,value):
# dhcps = self.Get('os_install_net_dhcp_set')
# wrongIp = filter(lambda x:x[0] and not checkIp(x[0]),
# zip(value,dhcps))
# if wrongIp:
# if wrongIp[0][0]:
# raise VariableError(_("Wrong IP address %s")%wrongIp[0][0])
#def check(self,value):
# dhcps = self.Get('os_install_net_dhcp_set')
# wrongIp = filter(lambda x:x[0] and not checkIp(x[0]),
# zip(value,dhcps))
# if wrongIp:
# if wrongIp[0][0]:
# raise VariableError(_("Wrong IP address %s")%wrongIp[0][0])
class VariableOsInstallNetNetwork(NetHelper,ReadonlyVariable):
class VariableOsInstallNetNetwork(NetHelper, ReadonlyVariable):
"""
Network for ip (Example:192.168.0.0/16)
"""
@ -320,11 +345,12 @@ class VariableOsInstallNetNetwork(NetHelper,ReadonlyVariable):
self.label = _("Network")
def get(self):
return map(lambda x:getIpNet(x[0],x[1]) if x[0] and x[1] else "",
zip(self.Get('os_install_net_ip'),
self.Get('os_install_net_mask')))
return map(lambda x: getIpNet(x[0], x[1]) if x[0] and x[1] else "",
zip(self.Get('os_install_net_ip'),
self.Get('os_install_net_mask')))
class VariableOsInstallNetCidr(NetHelper,ReadonlyVariable):
class VariableOsInstallNetCidr(NetHelper, ReadonlyVariable):
"""
CIDR of interfaces
"""
@ -337,10 +363,11 @@ class VariableOsInstallNetCidr(NetHelper,ReadonlyVariable):
"""
Get CIDR of ip,net (Example: 24)
"""
return map(lambda x:maskToCidr(x) if x else '',
self.Get('os_install_net_mask'))
return map(lambda x: maskToCidr(x) if x else '',
self.Get('os_install_net_mask'))
class VariableOsInstallNetMask(NetHelper,Variable):
class VariableOsInstallNetMask(NetHelper, Variable):
"""
Net mask of interfaces (Example:255.255.0.0)
"""
@ -350,28 +377,30 @@ class VariableOsInstallNetMask(NetHelper,Variable):
self.label = _("Mask")
def get(self):
return map(lambda x:cidrToMask(getMask(x)),
self.Get('os_install_net_interfaces'))
return map(lambda x: cidrToMask(getMask(x)),
self.Get('os_install_net_interfaces'))
def set(self,value):
def set(self, value):
"""
Convert to mask CIDR value
"""
def convertCidrToMask(x):
if x and x.isdigit() and int(x) in range(0,33):
if x and x.isdigit() and int(x) in range(0, 33):
return cidrToMask(int(x))
else:
return x
res = map(convertCidrToMask,value)
res = map(convertCidrToMask, value)
return res
def check(self,value):
def check(self, value):
dhcps = self.Get('os_install_net_status')
wrongMask = filter(lambda x:(x[0] or not x[1] in ("off","dhcp")) and \
not checkMask(x[0]),
zip(value,dhcps))
wrongMask = filter(lambda x: (x[0] or not x[1] in ("off", "dhcp")) and \
not checkMask(x[0]),
zip(value, dhcps))
if wrongMask:
raise VariableError(_("Wrong mask %s")%wrongMask[0][0])
raise VariableError(_("Wrong mask %s") % wrongMask[0][0])
def choice(self):
return ["255.255.255.255",
@ -381,7 +410,7 @@ class VariableOsInstallNetMask(NetHelper,Variable):
"0.0.0.0"]
class VariableOsInstallNetDhcpSet(NetHelper,Variable):
class VariableOsInstallNetDhcpSet(NetHelper, Variable):
"""
Describe ip was get by DHCP or manualy
"""
@ -391,10 +420,11 @@ class VariableOsInstallNetDhcpSet(NetHelper,Variable):
self.label = _("DHCP")
def get(self):
return map(lambda x:"on" if x == "dhcp" else "off",
self.Get('os_install_net_status'))
return map(lambda x: "on" if x == "dhcp" else "off",
self.Get('os_install_net_status'))
class VariableOsInstallNetRouteData(NetHelper,TableVariable):
class VariableOsInstallNetRouteData(NetHelper, TableVariable):
"""
Route table data
"""
@ -415,41 +445,42 @@ class VariableOsInstallNetRouteData(NetHelper,TableVariable):
_("add a routing rule (specified as "
"NETWORK:[GATEWAY][:DEV[:SOURCE]])")
def get(self,hr=False):
def get(self, hr=HumanReadable.No):
"""Routing hash"""
interfaces = self.Get('os_install_net_interfaces')
interfaces_status = self.Get('os_install_net_status')
interfaces_network = self.Get('os_install_net_network')
staticInterface = \
map(itemgetter(0,2),
filter(lambda x:not x[1] in ("off","dhcp"),
zip(interfaces,interfaces_status,interfaces_network)))
map(itemgetter(0, 2),
filter(lambda x: not x[1] in ("off", "dhcp"),
zip(interfaces, interfaces_status, interfaces_network)))
route_data = []
if staticInterface:
staticInterface,skipNet = zip(*staticInterface)
return map(lambda x:[x[0],
x[1].get('via',''),
x[1].get('dev',''),
x[1].get('src','')],
ifilter(lambda x:not x[0] in skipNet,
ip.getRouteTable(staticInterface))) or [[]]
staticInterface, skipNet = zip(*staticInterface)
return map(lambda x: [x[0],
x[1].get('via', ''),
x[1].get('dev', ''),
x[1].get('src', '')],
ifilter(lambda x: not x[0] in skipNet,
ip.getRouteTable(staticInterface))) or [[]]
return [[]]
def getHumanReadableAuto(self):
return Variable.getHumanReadableAuto(self)
def setValue(self,value,force=False):
def setValue(self, value, force=False):
"""
Standard action for set value
"""
self.value = self.set(value)
self.wasSet = True
self.wasSet = True
self.invalid = False
# run check
if not force:
self._check()
class VariableOsInstallNetRouteNetwork(FieldValue,NetHelper,Variable):
class VariableOsInstallNetRouteNetwork(NetHelper, FieldValue, Variable):
"""
Net for route table record
"""
@ -461,23 +492,24 @@ class VariableOsInstallNetRouteNetwork(FieldValue,NetHelper,Variable):
self.label = _("Network")
def choice(self):
return ["default"] #+self.Get('os_install_net_network')
return ["default"] # +self.Get('os_install_net_network')
def check(self,value):
def check(self, value):
##########################
# detect duplicate network
##########################
for wrongnet in ifilterfalse(ip.checkNet,
ifilter("default".__ne__,
value)):
raise VariableError(_("Wrong network %s")%wrongnet)
dupNetwork = list(set(filter(lambda x:value.count(x)>1,
ifilter("default".__ne__,
value)):
raise VariableError(_("Wrong network %s") % wrongnet)
dupNetwork = list(set(filter(lambda x: value.count(x) > 1,
value)))
if dupNetwork:
raise VariableError(
_("Network '%s' is used more than once")%dupNetwork[0])
_("Network '%s' is used more than once") % dupNetwork[0])
class VariableOsInstallNetRouteGw(FieldValue,NetHelper,Variable):
class VariableOsInstallNetRouteGw(NetHelper, FieldValue, Variable):
"""
Gateway for route table record
"""
@ -487,30 +519,32 @@ class VariableOsInstallNetRouteGw(FieldValue,NetHelper,Variable):
def init(self):
self.label = _("Gateway")
def check(self,value):
def check(self, value):
#############################
# search unreachable gateways
#############################
NET,GW = 0,1
NET, GW = 0, 1
netsGw = zip(self.Get('os_install_net_route_network'),
value)
nets = filter(lambda x:x and x != "default",
chain(self.Get('os_install_net_route_network'),
self.Get('os_install_net_network')))
for wrongip in ifilterfalse(ip.checkIp,value):
raise VariableError(_("Wrong gateway IP %s")%wrongip)
wrongGws = map(lambda x:x[GW],
filter(lambda x:not ip.isIpInNet(x[GW],
*(set(nets) - set(x[NET]))),
filter(lambda x:x[GW],
netsGw)))
nets = filter(lambda x: x and x != "default",
chain(self.Get('os_install_net_route_network'),
self.Get('os_install_net_network')))
for wrongip in ifilterfalse(ip.checkIp, value):
raise VariableError(_("Wrong gateway IP %s") % wrongip)
wrongGws = map(lambda x: x[GW],
filter(lambda x: not ip.isIpInNet(x[GW],
*(set(nets) - set(
x[NET]))),
filter(lambda x: x[GW],
netsGw)))
if wrongGws:
raise VariableError(_("Gateways %s are unreachable")%
(",".join(wrongGws)))
raise VariableError(_("Gateways %s are unreachable") %
(",".join(wrongGws)))
class VariableOsInstallNetRouteDev(FieldValue,NetHelper,Variable):
class VariableOsInstallNetRouteDev(NetHelper, FieldValue, Variable):
"""
Device for route table record
"""
@ -524,7 +558,8 @@ class VariableOsInstallNetRouteDev(FieldValue,NetHelper,Variable):
def choice(self):
return self.Get('os_install_net_interfaces')
class VariableOsInstallNetRouteSrc(FieldValue,NetHelper,Variable):
class VariableOsInstallNetRouteSrc(NetHelper, FieldValue, Variable):
"""
Source ip for route table record
"""
@ -536,61 +571,64 @@ class VariableOsInstallNetRouteSrc(FieldValue,NetHelper,Variable):
self.label = _("Source IP")
def choice(self):
return [""]+self.Get('os_install_net_ip')
def check(self,value):
return [""] + self.Get('os_install_net_ip')
def check(self, value):
for wrongip in ifilterfalse(ip.checkIp,
ifilter(None,value)):
raise VariableError(_("Wrong source IP %s")%wrongip)
ifilter(None, value)):
raise VariableError(_("Wrong source IP %s") % wrongip)
ipAddrs = self.Get('os_install_net_ip')
wrongIps = filter(lambda x: x and not x in ipAddrs,
value)
value)
if wrongIps:
raise VariableError(
_("Wrong IP address %s in the specified source IP")%
(",".join(wrongIps)))
_("Wrong IP address %s in the specified source IP") %
(",".join(wrongIps)))
class VariableOsInstallNetRoute(NetHelper,ReadonlyVariable):
class VariableOsInstallNetRoute(NetHelper, ReadonlyVariable):
"""
Data by route for conf.d/net
"""
def performRouteData(self,performFunc):
def performRouteData(self, performFunc):
routeMatrix = zip(self.Get('os_install_net_route_network'),
self.Get('os_install_net_route_gw'),
self.Get('os_install_net_route_dev'),
self.Get('os_install_net_route_src'))
DEV,IP,CIDR,NET = 0,1,2,1
return map(lambda x:performFunc(x[DEV],x[NET],routeMatrix),
# union ip and mask to ip/net
map(lambda x:(x[DEV],ip.getIpNet(x[IP],cidr=x[CIDR])) \
if x[IP] and x[CIDR] else (x[DEV],""),
#filter(lambda x:x[IP] and x[CIDR],
zip(self.Get('os_install_net_interfaces'),
self.Get('os_install_net_ip'),
self.Get('os_install_net_cidr'))))
DEV, IP, CIDR, NET = 0, 1, 2, 1
return map(lambda x: performFunc(x[DEV], x[NET], routeMatrix),
# union ip and mask to ip/net
map(lambda x: (x[DEV], ip.getIpNet(x[IP], cidr=x[CIDR])) \
if x[IP] and x[CIDR] else (x[DEV], ""),
# filter(lambda x:x[IP] and x[CIDR],
zip(self.Get('os_install_net_interfaces'),
self.Get('os_install_net_ip'),
self.Get('os_install_net_cidr'))))
def get(self):
"""Route info for conf.d/net"""
defaultDev = 0
workIfaces = self.Select('os_install_net_interfaces',
where='os_install_net_status',
_notin="off")
where='os_install_net_status',
_notin="off")
if len(workIfaces) == 1:
defaultDev = workIfaces[0]
def getRouteForInterfaceConf(interface,net,routeMatrix):
NET,GW,DEV,SRC = 0,1,2,3
def getRouteForInterfaceConf(interface, net, routeMatrix):
NET, GW, DEV, SRC = 0, 1, 2, 3
return "\n".join(
# build string for route from net,gateway,dev and src
map(lambda x:"{net}{gateway}{src}".format(
net=x[NET],
gateway=" via %s"%x[GW] if x[GW] else "",
src=" src %s"%x[SRC] if x[SRC] else ""),
# filter by interface and discard direct routes
# example: for 192.168.1.5/24 discard 192.168.1.0/24 net
filter(lambda x:(interface==x[DEV] or defaultDev and \
interface==defaultDev) \
and net!=x[NET],routeMatrix)))
# build string for route from net,gateway,dev and src
map(lambda x: "{net}{gateway}{src}".format(
net=x[NET],
gateway=" via %s" % x[GW] if x[GW] else "",
src=" src %s" % x[SRC] if x[SRC] else ""),
# filter by interface and discard direct routes
# example: for 192.168.1.5/24 discard 192.168.1.0/24 net
filter(lambda x: (interface == x[DEV] or defaultDev and
interface == defaultDev) \
and net != x[NET], routeMatrix)))
return self.performRouteData(getRouteForInterfaceConf)
@ -604,56 +642,65 @@ class VariableOsInstallNetNmroute(VariableOsInstallNetRoute):
"""Route info for system-connections of NetworkManager"""
defaultDev = 0
workIfaces = self.Select('os_install_net_interfaces',
where='os_install_net_status',
_notin="off")
where='os_install_net_status',
_notin="off")
if len(workIfaces) == 1:
defaultDev = workIfaces[0]
def getRouteForInterfaceNM(interface,net,routeMatrix):
NET,GW,DEV,SRC = 0,1,2,3
defaultGw = map(lambda x:"%s;"%x[GW],
filter(lambda x:interface==x[DEV] and \
x[NET]=="default",
routeMatrix))
def getRouteForInterfaceNM(interface, net, routeMatrix):
NET, GW, DEV, SRC = 0, 1, 2, 3
defaultGw = map(lambda x: "%s;" % x[GW],
filter(lambda x: interface == x[DEV] and \
x[NET] == "default",
routeMatrix))
return "{0}\n".format(defaultGw[0] if defaultGw else "") + \
"\n".join(
# build string for route from net,gateway,dev and src
map(lambda x:"routes{num}={ip};{cidr};{gateway};0;".format(
num=x[0]+1,
ip=x[1][NET].partition('/')[0],
cidr=x[1][NET].partition('/')[2],
gateway=x[1][GW] if x[1][GW] else "0.0.0.0"),
# filter by interface and discard direct routes
# example: for 192.168.1.5/24 discard 192.168.1.0/24 net
enumerate(
filter(lambda x:(interface==x[DEV] or defaultDev and \
interface==defaultDev) and net!=x[NET] and \
x[NET]!="default",routeMatrix))))
"\n".join(
# build string for route from net,gateway,dev and src
map(lambda
x: "routes{num}={ip};{cidr};{gateway};0;".format(
num=x[0] + 1,
ip=x[1][NET].partition('/')[0],
cidr=x[1][NET].partition('/')[2],
gateway=x[1][GW] if x[1][GW] else "0.0.0.0"),
# filter by interface and discard direct routes
# example: for 192.168.1.5/24 discard 192.168.1.0/24 net
enumerate(
filter(lambda x: (interface == x[
DEV] or defaultDev and
interface == defaultDev) and net !=
x[
NET] and \
x[NET] != "default",
routeMatrix))))
return self.performRouteData(getRouteForInterfaceNM)
class VariableOsInstallNetConfAvailable(NetHelper,Variable):
class VariableOsInstallNetConfAvailable(NetHelper, Variable):
"""
Available net configuration
"""
type = "list"
def get(self):
mapNetConf = (('networkmanager','net-misc/networkmanager',
_("NetworkManager")),
('openrc','',_('OpenRC')))
mapNetConf = (('networkmanager', 'net-misc/networkmanager',
_("NetworkManager")),
('openrc', '', _('OpenRC')))
image = self.Get('cl_image')
if image:
with image as distr:
try:
distrPath = image.getDirectory()
return map(itemgetter(0,2),
filter(lambda x:not x[1] or isPkgInstalled(x[1],
prefix=distrPath),
mapNetConf))
return map(itemgetter(0, 2),
filter(lambda x: not x[1] or isPkgInstalled(x[1],
prefix=distrPath),
mapNetConf))
except DistributiveError as e:
pass
return sorted(map(itemgetter(0,2),mapNetConf[-1:]),key=itemgetter(1))
return sorted(map(itemgetter(0, 2), mapNetConf[-1:]), key=itemgetter(1))
class VariableOsInstallNetConf(NetHelper,Variable):
class VariableOsInstallNetConf(NetHelper, Variable):
"""
Net setup (networkmanager or openrc)
"""
@ -667,16 +714,17 @@ class VariableOsInstallNetConf(NetHelper,Variable):
def get(self):
"""Net setup (networkmanager or openrc)"""
if filter(lambda x:x.lower() == ("networkmanager"),
listDirectory('/etc/runlevels/boot')+
listDirectory('/etc/runlevels/default')) \
or self.Get('os_root_type') == "livecd":
if filter(lambda x: x.lower() == "networkmanager",
listDirectory('/etc/runlevels/boot') +
listDirectory('/etc/runlevels/default')) \
or self.Get('os_root_type') == "livecd":
nm = "networkmanager"
else:
nm = ""
for val,comment in self.Get('os_install_net_conf_available'):
if nm == val and not (self.Get('os_root_dev') == '/dev/nfs' and \
self.Get('os_install_root_type') == "livecd"):
for val, comment in self.Get('os_install_net_conf_available'):
if nm == val and not (self.Get('os_root_dev') == '/dev/nfs' and
self.Get(
'os_install_root_type') == "livecd"):
return nm
else:
return "openrc"
@ -684,7 +732,8 @@ class VariableOsInstallNetConf(NetHelper,Variable):
def choice(self):
return self.Get('os_install_net_conf_available')
class VariableOsInstallNetDnsSearch(NetHelper,Variable):
class VariableOsInstallNetDnsSearch(NetHelper, Variable):
"""
Dns search
"""
@ -705,22 +754,23 @@ class VariableOsInstallNetDnsSearch(NetHelper,Variable):
return True
return False
def set(self,value):
return " ".join(re.split('[; ,]',value))
def set(self, value):
return " ".join(re.split('[; ,]', value))
def get(self):
"""Get current name servers"""
dnsSearch = " ".join(
map(lambda x:x.strip().partition("search")[2].strip(),
filter(lambda x:x.lstrip().startswith("search"),
readLinesFile('/etc/resolv.conf'))))
map(lambda x: x.strip().partition("search")[2].strip(),
filter(lambda x: x.lstrip().startswith("search"),
readLinesFile('/etc/resolv.conf'))))
return "" if self.isDNSByDHCP() else dnsSearch
def humanReadable(self):
return self.Get() or (_("Get via DHCP")
return self.Get() or (_("Get via DHCP")
if self.isDNSByDHCP()
else _("Not used"))
class VariableOsInstallNetDns(VariableOsInstallNetDnsSearch):
"""
Dns servers
@ -732,27 +782,30 @@ class VariableOsInstallNetDns(VariableOsInstallNetDnsSearch):
self.label = _("Domain name server")
self.help = _("domain name server (comma-separated)")
def set(self,value):
return " ".join(re.split('[; ,]',value))
def set(self, value):
return " ".join(re.split('[; ,]', value))
def get(self):
dnsIps = filter(ip.checkIp,
map(lambda x:x.strip().partition("nameserver")[2].strip(),
filter(lambda x:x.lstrip().startswith("nameserver"),
readLinesFile('/etc/resolv.conf'))))
map(lambda x: x.strip().partition("nameserver")[
2].strip(),
filter(
lambda x: x.lstrip().startswith("nameserver"),
readLinesFile('/etc/resolv.conf'))))
return "" if self.isDNSByDHCP() else " ".join(dnsIps)
def check(self,value):
def check(self, value):
reIp = re.compile(ip.IP_ADDR)
if any(ifilterfalse(reIp.match,value.split(' '))):
if any(ifilterfalse(reIp.match, value.split(' '))):
raise VariableError(_("Wrong IP address for DNS"))
def humanReadable(self):
return self.Get() or (_("Get via DHCP")
return self.Get() or (_("Get via DHCP")
if self.isDNSByDHCP()
else _("Not used"))
class VariableOsInstallNetSettings(NetHelper,Variable):
class VariableOsInstallNetSettings(NetHelper, Variable):
"""
Net service configured
"""
@ -760,7 +813,8 @@ class VariableOsInstallNetSettings(NetHelper,Variable):
value = ""
def choice(self):
return [("","")]+self.Get('os_install_net_conf_available')
return [("", "")] + self.Get('os_install_net_conf_available')
class VariableOsInstallPxeIp(Variable):
"""

@ -1,6 +1,6 @@
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# Copyright 2008-2013 Calculate Ltd. http://www.calculate-linux.org
# Copyright 2008-2015 Calculate Ltd. http://www.calculate-linux.org
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -18,27 +18,27 @@ import os
import sys
import re
from os import path
from calculate.lib.datavars import Variable,VariableError,ReadonlyVariable, \
TableVariable,PasswordError, \
ReadonlyTableVariable,FieldValue, \
DataVarsError
from calculate.lib.datavars import (Variable, VariableError, ReadonlyVariable,
TableVariable, PasswordError,
DataVarsError, VariableInterface)
from calculate.install.fs_manager import FileSystemManager
from calculate.lib.utils.files import (readFile,getProgPath,process,
readLinesFile)
from calculate.lib.utils.common import getPasswdUsers,getUserGroups,getGroups
from calculate.lib.utils.common import getValueFromConfig,getValueFromCmdLine
from calculate.lib.utils.files import (readFile, getProgPath, process,
readLinesFile)
from calculate.lib.utils.common import getPasswdUsers, getUserGroups, getGroups
from calculate.lib.utils.common import getValueFromConfig, getValueFromCmdLine
from calculate.lib.utils.common import getUserPrimaryGroup
from calculate.lib.utils.portage import isPkgInstalled
from calculate.lib.utils.device import getUdevDeviceInfo
from crypt import crypt
from calculate.lib.encrypt import encrypt
import calculate.lib.cl_template as cl_template
import calculate.lib.cl_ini_parser as cl_ini_parser
from calculate.lib.cl_lang import setLocalTranslate
from calculate.lib.cl_lang import setLocalTranslate, _
setLocalTranslate('cl_install3',sys.modules[__name__])
setLocalTranslate('cl_install3', sys.modules[__name__])
class UserHelper:
class UserHelper(VariableInterface):
"""
Locale variables not using for flash installation
"""
@ -54,11 +54,12 @@ class UserHelper:
return _("Autologin is available for Xorg sessions only")
return ""
class VariableOsInstallScratch(ReadonlyVariable):
"""
Install system in scratch mode
"""
type = "bool"
type = "bool"
opt = ['--build']
def get(self):
@ -68,6 +69,7 @@ class VariableOsInstallScratch(ReadonlyVariable):
else:
return self.Get('os_scratch')
class VariableOsFormatType(ReadonlyVariable):
"""
Filesystem format support by calcualte-install
@ -78,26 +80,28 @@ class VariableOsFormatType(ReadonlyVariable):
"""Filesystem format support by calcualte-install"""
return FileSystemManager.supportFS.keys()
class VariableOsFormatUse(ReadonlyVariable):
"""
Avialable format by mkfs utility
"""
type = "list"
# (on or off) autoupdate config from install program
cl_autoupdate_set = {'value': "off",
'type': "bool",
'value': "off"}
cl_autoupdate_set = {
'type': "bool",
'value': "off"}
def checkFunc(self,fs):
def checkFunc(self, fs):
if "format" in FileSystemManager.supportFS[fs] and \
path.exists(FileSystemManager.supportFS[fs]["format"]):
path.exists(FileSystemManager.supportFS[fs]["format"]):
return "yes"
return "no"
def get(self):
return map(self.checkFunc, self.Get('os_format_type'))
class VariableClMigrateRootPwd(UserHelper,Variable):
class VariableClMigrateRootPwd(UserHelper, Variable):
"""
Root password
"""
@ -111,10 +115,10 @@ class VariableClMigrateRootPwd(UserHelper,Variable):
self.label = _("Root password")
def get(self):
rootPasswd = map(lambda x:x[1],
filter("root".__eq__,
map(lambda x:x.split(':')[0:2],
readLinesFile('/etc/shadow'))))
rootPasswd = map(lambda x: x[1],
filter("root".__eq__,
map(lambda x: x.split(':')[0:2],
readLinesFile('/etc/shadow'))))
if rootPasswd:
rootPasswd = rootPasswd[0]
else:
@ -126,7 +130,7 @@ class VariableClMigrateRootPwd(UserHelper,Variable):
rootPasswd = ""
return rootPasswd or ""
def set(self,value):
def set(self, value):
"""
Encrypt password
"""
@ -138,13 +142,14 @@ class VariableClMigrateRootPwd(UserHelper,Variable):
else:
return encryptObj.getHashPasswd(value, "shadow_ssha256")
def check(self,value):
def check(self, value):
if not value:
raise PasswordError(_("Password for user %s missing")%"root")
raise PasswordError(_("Password for user %s missing") % "root")
class VariableClInstallHomeCryptSet(UserHelper,Variable):
class VariableClInstallHomeCryptSet(UserHelper, Variable):
type = 'bool'
opt = ["--crypt-home","-C"]
opt = ["--crypt-home", "-C"]
untrusted = True
def init(self):
@ -155,19 +160,20 @@ class VariableClInstallHomeCryptSet(UserHelper,Variable):
return ("off" if self.Get('cl_autologin')
else self.Get('cl_home_crypt_set'))
def check(self,value):
def check(self, value):
if value == "on" and self.Get('cl_autologin'):
raise VariableError(
_("User profile encryption is uncompatible with autologin"))
class VariableClMigrateData(UserHelper,TableVariable):
class VariableClMigrateData(UserHelper, TableVariable):
"""
User migrate data table
"""
type = 'table'
opt = ["--user","-u"]
opt = ["--user", "-u"]
metavalue = 'USER[:GROUPS]'
source = ['cl_migrate_user','cl_migrate_user_groups',
source = ['cl_migrate_user', 'cl_migrate_user_groups',
'cl_migrate_user_pwd']
untrusted = True
@ -175,15 +181,18 @@ class VariableClMigrateData(UserHelper,TableVariable):
self.help = _("add a user to the installed system")
self.label = _("Migrating users")
class VariableClMigrateDataBrief(UserHelper,TableVariable):
class VariableClMigrateDataBrief(UserHelper, TableVariable):
"""
User migrate data table for brief view
"""
source = ['cl_migrate_user','cl_migrate_user_groups']
source = ['cl_migrate_user', 'cl_migrate_user_groups']
def init(self):
self.label = _("Migrating users")
class VariableClMigrateUser(UserHelper,Variable):
class VariableClMigrateUser(UserHelper, Variable):
"""
Migrate users list
"""
@ -196,26 +205,28 @@ class VariableClMigrateUser(UserHelper,Variable):
"""
Migrating users (users above 1000 uid)
"""
return filter("root".__ne__,getPasswdUsers())
return filter("root".__ne__, getPasswdUsers())
class VariableClMigrateUserGroups(UserHelper,Variable):
class VariableClMigrateUserGroups(UserHelper, Variable):
"""
Migrate users groups
"""
type = 'choice-list-list'
defaultGroupList = ["users","wheel","audio","cdrom","video",
"cdrw","usb","plugdev","games","lp","scanner","uucp"]
defaultGroupList = ["users", "wheel", "audio", "cdrom", "video",
"cdrw", "usb", "plugdev", "games", "lp", "scanner",
"uucp"]
def getDefaultGroups(self):
return list(set(self.defaultGroupList)&set(getGroups()))
return list(set(self.defaultGroupList) & set(getGroups()))
def init(self):
self.label = _("Groups")
def set(self,value):
value = map(lambda x: x \
if x and any(x) else self.getDefaultGroups(),
value)
def set(self, value):
value = map(lambda x: x \
if x and any(x) else self.getDefaultGroups(),
value)
return value
def getPrimaryGroup(self, username):
@ -229,9 +240,9 @@ class VariableClMigrateUserGroups(UserHelper,Variable):
User groups
"""
passwdList = getPasswdUsers()
return map(lambda x:(self.getPrimaryGroup(x) + (getUserGroups(x)
if x in passwdList else self.getDefaultGroups())),
self.Get('cl_migrate_user'))
return map(lambda x: (self.getPrimaryGroup(x) + (getUserGroups(x)
if x in passwdList else self.getDefaultGroups())),
self.Get('cl_migrate_user'))
def choice(self):
"""
@ -239,7 +250,8 @@ class VariableClMigrateUserGroups(UserHelper,Variable):
"""
return getGroups()
class VariableClMigrateUserPwd(UserHelper,Variable):
class VariableClMigrateUserPwd(UserHelper, Variable):
"""
Migrate users who need to change passwords
"""
@ -257,16 +269,16 @@ class VariableClMigrateUserPwd(UserHelper,Variable):
if os.access(fileName, os.R_OK):
migrateusers = self.Get("cl_migrate_user")
if migrateusers:
lenData=9
shadowData = filter(lambda x: len(x)==lenData,
lenData = 9
shadowData = filter(lambda x: len(x) == lenData,
map(lambda x: x.rstrip().split(":"),
open(fileName)))
open(fileName)))
shadowData = filter(lambda x: x[0] in migrateusers, shadowData)
shadowData = map(lambda x: (x[0], x[1]), shadowData)
shadowUsers = map(lambda x: x[0], shadowData)
for userName in migrateusers:
if userName in shadowUsers:
userData = filter(lambda x: x[0]==userName,
userData = filter(lambda x: x[0] == userName,
shadowData)
hashPwd = userData[0][1]
retList.append(hashPwd)
@ -274,34 +286,35 @@ class VariableClMigrateUserPwd(UserHelper,Variable):
retList.append("")
return retList
def check(self,value):
def check(self, value):
"""
Check exists password for all migrate users
"""
for user,pwd in zip(self.Get('cl_migrate_user'),value):
for user, pwd in zip(self.Get('cl_migrate_user'), value):
if not pwd:
raise PasswordError(
_("Password for user %s missing")%user)
_("Password for user %s missing") % user)
def set(self,value):
def set(self, value):
"""
Encrypt passwords
"""
reCheck = re.compile("^\$[^$]+\$[^$]+\$.*$")
encryptObj = encrypt()
return map(lambda x:x if reCheck.match(x) or not x else \
encryptObj.getHashPasswd(x, "shadow_ssha256"),
value)
return map(lambda x: x if reCheck.match(x) or not x else \
encryptObj.getHashPasswd(x, "shadow_ssha256"),
value)
class VariableClAutologin(UserHelper,Variable):
class VariableClAutologin(UserHelper, Variable):
"""
Autologin variable (contains user name for autologin) or
empty string if disable
"""
type = 'choiceedit'
opt = ["--autologin",'-A']
opt = ["--autologin", '-A']
metavalue = "USER"
xorg_need = True
@ -311,13 +324,13 @@ class VariableClAutologin(UserHelper,Variable):
def get(self):
# autologin enable for livecd and all install type CMC
cmdDomainSet = (getValueFromCmdLine("calculate","domain_pw") or
getValueFromCmdLine("calculate","domain") or "")
if (not cmdDomainSet and
self.Get('os_install_root_type') == "livecd" ) or \
self.Get('os_install_linux_shortname') == "CMC":
cmdDomainSet = (getValueFromCmdLine("calculate", "domain_pw") or
getValueFromCmdLine("calculate", "domain") or "")
if (not cmdDomainSet and
self.Get('os_install_root_type') == "livecd") or \
self.Get('os_install_linux_shortname') == "CMC":
nonRootUsers = filter(lambda x: x != "root",
self.Get('cl_migrate_user'))
self.Get('cl_migrate_user'))
if nonRootUsers:
return nonRootUsers[0]
else:
@ -325,19 +338,20 @@ class VariableClAutologin(UserHelper,Variable):
return ""
def set(self, value):
return {'none':''}.get(value, value)
return {'none': ''}.get(value, value)
def choice(self):
return [""]+filter(lambda x:x != "root",self.Get('cl_migrate_user'))
return [""] + filter(lambda x: x != "root", self.Get('cl_migrate_user'))
def check(self,value):
def check(self, value):
"""
Autologin only for migrated non-root users
"""
if value and not value in self.Get('cl_migrate_user'):
raise VariableError(_("User %s does not exist")%value)
raise VariableError(_("User %s does not exist") % value)
if value == "root":
raise VariableError(_("Autologin is unavailable for user %s")%value)
raise VariableError(
_("Autologin is unavailable for user %s") % value)
def humanReadable(self):
return self.Get() or _("Not used")
@ -348,13 +362,14 @@ class VariableClAutologin(UserHelper,Variable):
"""
try:
if (self.Get('cl_action') == 'merge' and
self.Get('client.cl_remote_host')):
self.Get('client.cl_remote_host')):
return \
_("The autologin is not available with domain workstations")
except DataVarsError:
pass
return UserHelper.uncompatible(self)
class VariableClInstallAutoupdateSet(Variable):
"""
(on or off) autoupdate config from install program for install
@ -362,120 +377,120 @@ class VariableClInstallAutoupdateSet(Variable):
type = "bool"
value = "off"
class VariableOsInstallMakeopts(Variable):
"""
Make.conf makeopts
"""
def get(self):
cpunum = self.Get('hr_cpu_num')
if cpunum == "1":
return "-j1"
else:
return "-j%d"%(int(cpunum)+1)
return "-j%d" % (int(cpunum) + 1)
class VariableOsGrubConf(ReadonlyVariable):
"""
DEPRICATED content of current grub.conf
"""
class VariableOsInstallGrubDevicemapConf(ReadonlyVariable):
"""
DEPRICATED content of device.map file for grub
"""
os_install_grub_devicemap_conf = {}
class VariableClDistfilesPath(Variable):
"""
DISTFILES path
"""
value = '/var/calculate/remote/distfiles'
class VariableClPkgdirPath(Variable):
"""
PKGDIR path
"""
def get(self):
return "/var/calculate/remote/packages/%s/%s" % (
self.Get('os_install_linux_shortname'),
self.Get('os_install_arch_machine'))
self.Get('os_install_linux_shortname'),
self.Get('os_install_arch_machine'))
class VariableClInstallDevFrom(Variable):
"""
Root device of previous installed os
"""
def set(self,value):
def set(self, value):
"""
If device in calculate3.env dev_from not exists set ''
"""
if value:
value = getUdevDeviceInfo(name=value).get('DEVNAME',value)
value = getUdevDeviceInfo(name=value).get('DEVNAME', value)
if value in self.Get('os_disk_dev'):
return value
else:
return ""
def get(self):
if (self.Get('cl_autopartition_set') == 'on' and
"root" in self.Get('cl_autopartition_scheme')):
if (self.Get('cl_autopartition_set') == 'on' and
"root" in self.Get('cl_autopartition_scheme')):
return self.Select('cl_autopartition_disk_dev',
where='cl_autopartition_disk_scheme',eq='root',limit=1)
where='cl_autopartition_disk_scheme', eq='root',
limit=1)
return ""
class VariableClInstallAutoupdateSet(Variable):
"""
Autoupdate for install or configure system
"""
def get_cl_install_autoupdate_set(self):
"""Get autoupdate default value"""
if self.Get('ac_install_system') == "up":
if self.Get('os_install_linux_system') == 'desktop':
return "on"
else:
return "off"
else:
return self.Get('cl_autoupdate_set')
class VariableOsNvidiaMask(ReadonlyVariable):
"""
Get nvidia card mask versions
"""
def get(self):
image = self.Get('cl_image')
try:
if image:
image = image.convertToDirectory()
chrootPath = image.getDirectory()
chrootPath = image.getDirectory()
else:
chrootPath = self.Get("cl_chroot_path")
nvidiaeclass = path.join(chrootPath,
'usr/portage/eclass/nvidia-driver.eclass')
if not os.access(nvidiaeclass,os.R_OK):
if not os.access(nvidiaeclass, os.R_OK):
return ""
category = "0300"
vendor = "10de:"
lsPciProg = getProgPath("/usr/sbin/lspci")
nvidiacards = filter(lambda x:" %s: "%category in x,
process(lsPciProg,"-d",vendor,"-n"))
nvidiacards = filter(lambda x: " %s: " % category in x,
process(lsPciProg, "-d", vendor, "-n"))
if not nvidiacards:
return ""
cardsid = \
map(lambda x:x.groups()[0],
filter(lambda x:x,
map(lambda x:re.search("[0-9a-fA-F]{4}:([0-9a-fA-F]{4})",x),
nvidiacards)))
map(lambda x: x.groups()[0],
filter(lambda x: x,
map(lambda x: re.search(
"[0-9a-fA-F]{4}:([0-9a-fA-F]{4})", x),
nvidiacards)))
if not cardsid:
return ""
eclassdata = readFile(nvidiaeclass)
drv_categories = re.findall('^drv_([^=]+)="', eclassdata, re.M)
drvs = map(lambda x:(x[0],x[1].replace('\\\n','').split()),
re.findall('\ndrv_(%s)="(.*?)"'%"|".join(drv_categories),
eclassdata,re.S))
drvs = map(lambda x: (x[0], x[1].replace('\\\n', '').split()),
re.findall(
'\ndrv_(%s)="(.*?)"' % "|".join(drv_categories),
eclassdata, re.S))
mask_categories = re.findall('^mask_([^=]+)="', eclassdata, re.M)
masks = dict(map(lambda x:(x[0],x[1].replace('\\\n','')),
re.findall('\nmask_(%s)="(.*?)"'%"|".join(drv_categories),
eclassdata,re.S)))
drvsForCardsid = filter(lambda x:set(x[1])&set(cardsid),drvs)
masks = dict(map(lambda x: (x[0], x[1].replace('\\\n', '')),
re.findall('\nmask_(%s)="(.*?)"' % "|".join(
drv_categories),
eclassdata, re.S)))
drvsForCardsid = filter(lambda x: set(x[1]) & set(cardsid), drvs)
if drvsForCardsid and drvsForCardsid[0][0] in masks:
return masks[drvsForCardsid[0][0]]
finally:
@ -483,6 +498,7 @@ class VariableOsNvidiaMask(ReadonlyVariable):
image.close()
return ""
class VariableOsInstallLvmSet(ReadonlyVariable):
"""
Using lvm
@ -496,6 +512,7 @@ class VariableOsInstallLvmSet(ReadonlyVariable):
else:
return "off"
class VariableOsInstallMdadmSet(ReadonlyVariable):
"""
Using mdadm
@ -509,23 +526,27 @@ class VariableOsInstallMdadmSet(ReadonlyVariable):
else:
return "off"
class VariableClChrootGrub(ReadonlyVariable):
"""
Chroot for grub-mkconfig
"""
def get(self):
if self.Get('os_install_scratch') == "on":
if self.Get('cl_action') == 'system':
return self.Get('cl_target').mdirectory
else:
return path.join(self.Get('cl_chroot_path'),"mnt/scratch")
return path.join(self.Get('cl_chroot_path'), "mnt/scratch")
else:
return self.Get('cl_chroot_path')
class VariableOsGrub2Path(Variable):
"""
Get Grub2 Install cmd (grub-install or grub2-install)
"""
def get(self):
# find grub2-install
grubInstall = getProgPath('/usr/sbin/grub2-install')
@ -533,11 +554,12 @@ class VariableOsGrub2Path(Variable):
return grubInstall
# find grub-install and check, that this is grub2-install (ver 1.99)
grubInstall = getProgPath('/usr/sbin/grub-install')
if grubInstall and filter(lambda x:"1.99" in x or "2." in x,
process(grubInstall,'--version')):
if grubInstall and filter(lambda x: "1.99" in x or "2." in x,
process(grubInstall, '--version')):
return grubInstall
return ""
class VariableClSetup(Variable):
"""
Type of setup
@ -557,13 +579,14 @@ class VariableClSetup(Variable):
'audio': _("audio parameters"),
'session': _("session settings"),
'users': _("user settings")}
return mapType.get(self.Get(),"")
return mapType.get(self.Get(), "")
def check(self,value):
def check(self, value):
if value == "boot" and self.Get('os_install_root_type') == 'livecd':
raise VariableError(
_("Boot configuration is not available on a LiveCD"))
class VariableClLive(Variable):
"""
Apply live templates
@ -576,6 +599,7 @@ class VariableClLive(Variable):
self.label = _("Configure dynamic options only")
self.help = _("configure dynamic options only")
class VariableOsInstallPxe(Variable):
"""
Installation for PXE loading
@ -584,25 +608,29 @@ class VariableOsInstallPxe(Variable):
value = "off"
untrusted = True
def check(self,value):
def check(self, value):
if value == "on":
if self.Get('os_linux_system') != "server":
raise VariableError(
_("PXE install is available for Calculate Directory Server only")+'.')
for pkg in ['net-misc/dhcp','net-ftp/tftp-hpa','net-fs/nfs-utils']:
_("PXE install is available for Calculate "
"Directory Server only") + '.')
for pkg in ['net-misc/dhcp', 'net-ftp/tftp-hpa',
'net-fs/nfs-utils']:
if not isPkgInstalled(pkg):
raise VariableError(
_("For PXE install, you need to install package %s")
%pkg)
_("For PXE install, you need to install package %s")
% pkg)
try:
config = cl_template.iniParser('/etc/calculate/calculate.env')
val = config.getVar('server','sr_dhcp_set')
config = cl_ini_parser.iniParser('/etc/calculate/calculate.env')
val = config.getVar('server', 'sr_dhcp_set')
if val.encode('utf-8') == "on":
return
except:
except Exception:
pass
raise VariableError(
_("PXE install is only available if the DHCP service has been configured first"))
_("PXE install is only available if the DHCP "
"service has been configured first"))
class VariableOsInstallPxePath(Variable):
"""
@ -616,11 +644,12 @@ class VariableOsInstallPxePath(Variable):
self.label = _("Installation path")
self.help = _("path for PXE install")
class VariableOsInstallUefiSet(Variable):
"""
Install in UEFI
"""
type = "bool"
type = "bool"
opt = ['--uefi']
def init(self):
@ -632,24 +661,24 @@ class VariableOsInstallUefiSet(Variable):
return self.Get('cl_autopartition_uefi_set')
else:
if self.Get('os_install_disk_efi') or \
"/boot/efi" in self.Get('os_location_dest'):
"/boot/efi" in self.Get('os_location_dest'):
if self.Get('os_install_arch_machine') == 'x86_64' and \
self.Get('os_install_root_type') != 'flash':
self.Get('os_install_root_type') != 'flash':
return self.Get('os_uefi_set')
return 'off'
def check(self,value):
def check(self, value):
if value == 'on':
if self.Get('os_uefi_set') == 'off' and \
self.Get('os_install_root_type') == 'hdd':
self.Get('os_install_root_type') == 'hdd':
raise VariableError(
_("Your system must be loaded in UEFI for using this "
"bootloader"))
_("Your system must be loaded in UEFI for using this "
"bootloader"))
if not 'gpt' in self.Get('os_device_table'):
raise VariableError(
_("GPT is needed for using the UEFI bootloader"))
if not (self.Get('os_install_disk_efi') or \
"/boot/efi" in self.Get('os_location_dest')):
if not (self.Get('os_install_disk_efi') or
"/boot/efi" in self.Get('os_location_dest')):
raise VariableError(
_("A EF00 partition is needed for using "
"the UEFI bootloader"))
@ -672,20 +701,22 @@ class VariableOsInstallUefiSet(Variable):
_("This option not used for Flash install")
return ""
class VariableOsInstallUefiBriefSet(VariableOsInstallUefiSet):
def uncompatible(self):
if self.Get('os_install_root_type') == 'flash':
return _("This option not used for Flash install")
return ""
def get(self):
return self.Get('os_install_uefi_set')
class VariableOsInstallGrubTerminal(Variable):
"""
Gfxmode
"""
type = "choice"
type = "choice"
opt = ['--grub-terminal']
metavalue = "TERMINAL"
@ -699,16 +730,16 @@ class VariableOsInstallGrubTerminal(Variable):
return 'console'
grubDefault = path.join(self.Get('cl_chroot_path'),
'etc/default/grub')
if getValueFromConfig(grubDefault,'GRUB_TERMINAL') == 'console':
if getValueFromConfig(grubDefault, 'GRUB_TERMINAL') == 'console':
return 'console'
grubCfg = '/boot/grub/grub.cfg'
if re.search('^terminal_output\s*console',readFile(grubCfg),re.M):
if re.search('^terminal_output\s*console', readFile(grubCfg), re.M):
return 'console'
return 'gfxterm'
def choice(self):
return ['gfxterm','console']
return ['gfxterm', 'console']
def uncompatible(self):
"""
@ -718,7 +749,8 @@ class VariableOsInstallGrubTerminal(Variable):
return _("Grub configuration unavailable for Flash install")
return ""
class PackageCheckHelper(ReadonlyVariable):
class PackageCheckVariable(ReadonlyVariable):
"""
Конструктор для переменных проверки установлен ли пакет
"""
@ -735,25 +767,26 @@ class PackageCheckHelper(ReadonlyVariable):
if image:
with image as distr:
distrPath = image.getDirectory()
if isPkgInstalled(self.package,prefix=distrPath):
if isPkgInstalled(self.package, prefix=distrPath):
return "on"
else:
prefix = self.Get(self.prefix_variable)
if isPkgInstalled(self.package, prefix=prefix):
return "on"
except:
except Exception:
pass
return "off"
class VariableOsInstallAlsaSet(PackageCheckHelper):
class VariableOsInstallAlsaSet(PackageCheckVariable):
"""
Установлен ли media-sound/alsa-utils
"""
image = True
package = "media-sound/alsa-utils"
class VariableOsInstallX11ServerSet(PackageCheckHelper):
class VariableOsInstallX11ServerSet(PackageCheckVariable):
"""
Установлен ли x11-base/xorg-server
"""
@ -761,7 +794,7 @@ class VariableOsInstallX11ServerSet(PackageCheckHelper):
package = "x11-base/xorg-server"
class FlashUncompatible:
class FlashUncompatible(VariableInterface):
def uncompatible(self):
"""
Update setting up unavailable for flash installation
@ -771,6 +804,7 @@ class FlashUncompatible:
_("Update configuration unavailable for Flash install")
return ""
try:
import calculate.update.variables.update as update
@ -780,21 +814,23 @@ try:
return self.Get('update.cl_update_autocheck_set')
class VariableClInstallAutocheckInterval(FlashUncompatible,
update.VariableClUpdateAutocheckInterval):
update.VariableClUpdateAutocheckInterval):
def get(self):
return self.Get('update.cl_update_autocheck_interval')
class VariableClInstallCleanpkgSet(FlashUncompatible,
update.VariableClUpdateCleanpkgSet):
update.VariableClUpdateCleanpkgSet):
def get(self):
return self.Get('update.cl_update_cleanpkg_set')
class VariableClInstallOtherSet(FlashUncompatible,
update.VariableClUpdateOtherSet):
update.VariableClUpdateOtherSet):
def get(self):
return self.Get('update.cl_update_other_set')
except ImportError:
update = None
class VariableClInstallAutocheckSet(FlashUncompatible, Variable):
value = "off"

@ -1,6 +1,6 @@
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# Copyright 2010-2013 Calculate Ltd. http://www.calculate-linux.org
# Copyright 2010-2015 Calculate Ltd. http://www.calculate-linux.org
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -14,287 +14,325 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import sys, time, os
import sys
from calculate.lib.datavars import VariableError,DataVarsError,DataVars
from calculate.install.install import InstallError
from calculate.lib.datavars import VariableError, DataVarsError
from calculate.install.distr import DistributiveError
import install
from calculate.lib.cl_lang import setLocalTranslate,getLazyLocalTranslate
setLocalTranslate('cl_install3',sys.modules[__name__])
from calculate.lib.cl_lang import setLocalTranslate, getLazyLocalTranslate, _
setLocalTranslate('cl_install3', sys.modules[__name__])
__ = getLazyLocalTranslate(_)
from calculate.core.server.func import WsdlBase
from calculate.install.utils.cl_install import ClInstallAction
from calculate.install.utils.cl_setup import (ClSetupAudioAction,
ClSetupLocaleAction,ClSetupVideoAction,ClSetupSystemAction,
ClSetupBootAction,ClSetupNetworkAction,
ClSetupSessionAction)
from calculate.install.utils.cl_setup import (
ClSetupLocaleAction, ClSetupVideoAction, ClSetupSystemAction,
ClSetupBootAction, ClSetupNetworkAction,
ClSetupSessionAction)
class Wsdl(WsdlBase):
methods = [{
# идентификатор метода
'method_name':"install",
'method_name': "install",
# категория метода
'category':__("Installation"),
'category': __("Installation"),
# заголовок метода
'title':__("System Install"),
'title': __("System Install"),
# иконка для графической консоли
'image':'calculate-install,system-installer,applications-other,'\
'drive-harddisk',
'image': ('calculate-install,system-installer,applications-other,'
'drive-harddisk'),
# метод присутствует в графической консоли
'gui':True,
'gui': True,
# консольная команда
'command':'cl-install',
'command': 'cl-install',
# права для запуска метода
'rights':['install'],
'rights': ['install'],
# объект содержащий модули для действия
'logic':{'Install':install.Install},
'logic': {'Install': install.Install},
# описание действия
'action':ClInstallAction,
'action': ClInstallAction,
# объект переменных
'datavars':"install",
'native_error':(VariableError,DistributiveError,
DataVarsError,install.InstallError),
'datavars': "install",
'native_error': (VariableError, DistributiveError,
DataVarsError, install.InstallError),
# значения по умолчанию для переменных этого метода
'setvars':{'cl_action!':'system','cl_dispatch_conf':'usenew'},
'setvars': {'cl_action!': 'system', 'cl_dispatch_conf': 'usenew'},
# описание груп (список лямбда функций)
'groups': [
lambda group:group(_("Language and locale"),
image="welcome",
normal=('os_install_locale_lang','os_install_clock_timezone')),
lambda group:group(_("Distribution"),
normal=('cl_image_filename',),
hide=('cl_image_linux_shortname','cl_image_arch_machine',
'cl_image_new_only'),
expert=('cl_image_linux_shortname', 'cl_image_arch_machine',
'cl_image_new_only')),
lambda group:group(_("Allocate drive space"),
normal=('cl_autopartition_set',),
hide=('cl_autopartition_set',),
brief=('cl_autopartition_brief_set',),
expert=('cl_autopartition_scheme',
'cl_autopartition_table','cl_autopartition_root_size',
'cl_autopartition_swap_size',
'cl_autopartition_device'),
expert_label=_("Click to set up autopartition options")),
lambda group:group(_("Mount points"),
normal=('os_location_data',),
hide=('os_location_data','os_install_mbr','os_install_uefi_set'),
brief_force=('os_location_brief_data','os_install_bootloader'),
brief=('os_install_uefi_brief_set',),
expert=('cl_uuid_set',
'os_install_root_type',
'os_install_mbr',
'os_install_uefi_set',
'os_install_kernel_scheduler')),
lambda group:group(_("Network settings"),
normal=('os_install_net_conf','os_install_net_data',
'os_install_net_fqdn','os_install_ntp'),
expert=('os_install_net_dns','os_install_net_dns_search',
'os_install_net_route_data')),
lambda group:group(_("Users"),
normal=('cl_migrate_root_pwd','cl_migrate_data','cl_autologin'),
expert=('cl_install_home_crypt_set',),
hide=('cl_migrate_data',),
brief=('cl_migrate_data_brief',)),
lambda group:group(_("Video"),
normal=('os_install_x11_video_drv','os_install_x11_composite',
'os_install_x11_resolution','os_install_fb_resolution',
'os_install_grub_terminal')),
lambda group: group(_("Language and locale"),
image="welcome",
normal=('os_install_locale_lang',
'os_install_clock_timezone')),
lambda group: group(_("Distribution"),
normal=('cl_image_filename',),
hide=('cl_image_linux_shortname',
'cl_image_arch_machine',
'cl_image_new_only'),
expert=('cl_image_linux_shortname',
'cl_image_arch_machine',
'cl_image_new_only')),
lambda group: group(_("Allocate drive space"),
normal=('cl_autopartition_set',),
hide=('cl_autopartition_set',),
brief=('cl_autopartition_brief_set',),
expert=('cl_autopartition_scheme',
'cl_autopartition_table',
'cl_autopartition_root_size',
'cl_autopartition_swap_size',
'cl_autopartition_device'),
expert_label=_(
"Click to set up autopartition options")),
lambda group: group(_("Mount points"),
normal=('os_location_data',),
hide=('os_location_data', 'os_install_mbr',
'os_install_uefi_set'),
brief_force=('os_location_brief_data',
'os_install_bootloader'),
brief=('os_install_uefi_brief_set',),
expert=('cl_uuid_set',
'os_install_root_type',
'os_install_mbr',
'os_install_uefi_set',
'os_install_kernel_scheduler')),
lambda group: group(_("Network settings"),
normal=(
'os_install_net_conf',
'os_install_net_data',
'os_install_net_fqdn', 'os_install_ntp'),
expert=('os_install_net_dns',
'os_install_net_dns_search',
'os_install_net_route_data')),
lambda group: group(_("Users"),
normal=(
'cl_migrate_root_pwd', 'cl_migrate_data',
'cl_autologin'),
expert=('cl_install_home_crypt_set',),
hide=('cl_migrate_data',),
brief=('cl_migrate_data_brief',)),
lambda group: group(_("Video"),
normal=('os_install_x11_video_drv',
'os_install_x11_composite',
'os_install_x11_resolution',
'os_install_fb_resolution',
'os_install_grub_terminal')),
lambda group: group(_("Update"),
normal=('cl_install_autocheck_set',
'cl_install_autocheck_interval',
'cl_install_cleanpkg_set',
'cl_install_other_set'))],
# действие выводит информацию перед запуском
'brief':{'next':__("Perform"),
'image':'finish',
'name':__("Start installing")}},
normal=('cl_install_autocheck_set',
'cl_install_autocheck_interval',
'cl_install_cleanpkg_set',
'cl_install_other_set'))],
# действие выводит информацию перед запуском
'brief': {'next': __("Perform"),
'image': 'finish',
'name': __("Start installing")}},
# установка на Flash
{
'method_name': "install_flash",
'category': __("Installation"),
'title': __("Flash Install"),
'image': ('drive-removable-media-usb-pendrive,'
'drive-removable-media-usb,media-flash'),
'gui':True,
'rights':['install'],
'logic':{'Install':install.Install},
'action':ClInstallAction,
'datavars':"install",
'native_error':(VariableError,DistributiveError,
DataVarsError,install.InstallError),
'setvars':{'cl_action!':'system','cl_install_type':'flash',
'cl_protect_use_set!':'off',
'cl_dispatch_conf':'usenew'},
'groups':[
lambda group:group(_("Flash install"),
normal=('os_install_disk_single','cl_image_filename'),
expert=('os_location_data',),
next_label=_("Perform"))]},
'method_name': "install_flash",
'category': __("Installation"),
'title': __("Flash Install"),
'image': ('drive-removable-media-usb-pendrive,'
'drive-removable-media-usb,media-flash'),
'gui': True,
'rights': ['install'],
'logic': {'Install': install.Install},
'action': ClInstallAction,
'datavars': "install",
'native_error': (VariableError, DistributiveError,
DataVarsError, install.InstallError),
'setvars': {'cl_action!': 'system', 'cl_install_type': 'flash',
'cl_protect_use_set!': 'off',
'cl_dispatch_conf': 'usenew'},
'groups': [
lambda group: group(_("Flash install"),
normal=('os_install_disk_single',
'cl_image_filename'),
expert=('os_location_data',),
next_label=_("Perform"))]},
# PXE установка
{
'method_name':"install_pxe",
'category':__("Installation"),
'title':__("PXE Install"),
'image':('gnome-network-properties,network-server,'
'preferences-desktop-remote-desktop'),
'command':'cl-install-pxe',
'gui':True,
'rights':['installpxe'],
'logic':{'Install':install.Install},
'action':ClInstallAction,
'datavars':"install",
'native_error':(VariableError,DistributiveError,
DataVarsError,install.InstallError),
'setvars':{'cl_action!':'system','os_install_pxe':'on',
'cl_protect_use_set!':'off',
'cl_dispatch_conf':'usenew'},
# действие выводит информацию перед запуском
'brief':{'next':__("Installation"),
'image':'finish',
'name':__("Start installing")},
'groups':[
lambda group:group(_("PXE install"),
normal=('cl_image_filename',),
expert=('os_install_pxe_path',
'os_install_pxe_ip'),
next_label=_("Perform"))]},
'method_name': "install_pxe",
'category': __("Installation"),
'title': __("PXE Install"),
'image': ('gnome-network-properties,network-server,'
'preferences-desktop-remote-desktop'),
'command': 'cl-install-pxe',
'gui': True,
'rights': ['installpxe'],
'logic': {'Install': install.Install},
'action': ClInstallAction,
'datavars': "install",
'native_error': (VariableError, DistributiveError,
DataVarsError, install.InstallError),
'setvars': {'cl_action!': 'system', 'os_install_pxe': 'on',
'cl_protect_use_set!': 'off',
'cl_dispatch_conf': 'usenew'},
# действие выводит информацию перед запуском
'brief': {'next': __("Installation"),
'image': 'finish',
'name': __("Start installing")},
'groups': [
lambda group: group(_("PXE install"),
normal=('cl_image_filename',),
expert=('os_install_pxe_path',
'os_install_pxe_ip'),
next_label=_("Perform"))]},
# настройка загрузки системы
{
'method_name':"setup_boot",
'category':__("Configuration"),
'title':__("Boot"),
'image':'stock_save,drive-harddisk',
'command':'cl-setup-boot',
'gui':True,
'rights':['setupboot'],
'logic':{'Install':install.Install},
'action':ClSetupBootAction,
'datavars':"install",
'native_error':(VariableError,DataVarsError,install.InstallError),
'setvars':{'cl_action!':'merge','cl_merge_pkg!':[None],
'cl_merge_set!':"on",'cl_setup':'boot'},
'groups':[
lambda group:group(_("Boot"),
normal=('os_install_mbr','os_install_uefi_set',
'os_install_kernel_scheduler',
'os_install_grub_terminal'),
expert=('cl_templates_locate','cl_dispatch_conf',
'cl_verbose_set'),
next_label=_("Save"))]},
'method_name': "setup_boot",
'category': __("Configuration"),
'title': __("Boot"),
'image': 'stock_save,drive-harddisk',
'command': 'cl-setup-boot',
'gui': True,
'rights': ['setupboot'],
'logic': {'Install': install.Install},
'action': ClSetupBootAction,
'datavars': "install",
'native_error': (
VariableError, DataVarsError, install.InstallError),
'setvars': {'cl_action!': 'merge', 'cl_merge_pkg!': [None],
'cl_merge_set!': "on", 'cl_setup': 'boot'},
'groups': [
lambda group: group(_("Boot"),
normal=(
'os_install_mbr', 'os_install_uefi_set',
'os_install_kernel_scheduler',
'os_install_grub_terminal'),
expert=(
'cl_templates_locate',
'cl_dispatch_conf',
'cl_verbose_set'),
next_label=_("Save"))]},
{
# настройка сети
'method_name':"setup_network",
'category':__("Configuration"),
'title':__("Network"),
'image':'network-workgroup,'
'network-idle,preferences-system-network',
'command':'cl-setup-network',
'gui':True,
'rights':['setupnetwork'],
'logic':{'Install':install.Install},
'action':ClSetupNetworkAction,
'datavars':"install",
'native_error':(VariableError,DataVarsError,install.InstallError),
'setvars':{'cl_action!':'merge','cl_merge_pkg!':[None],
'cl_merge_set!':"on",'cl_setup':'network'},
'groups':[
lambda group:group(_("Network"),
normal=('os_install_net_conf','os_install_net_data',
'os_install_net_fqdn','os_install_ntp'),
expert=('os_install_net_dns','os_install_net_dns_search',
'os_install_net_route_data',
'cl_templates_locate','cl_dispatch_conf',
'cl_verbose_set'),
next_label=_("Save"))]},
# настройка сети
'method_name': "setup_network",
'category': __("Configuration"),
'title': __("Network"),
'image': 'network-workgroup,'
'network-idle,preferences-system-network',
'command': 'cl-setup-network',
'gui': True,
'rights': ['setupnetwork'],
'logic': {'Install': install.Install},
'action': ClSetupNetworkAction,
'datavars': "install",
'native_error': (
VariableError, DataVarsError, install.InstallError),
'setvars': {'cl_action!': 'merge', 'cl_merge_pkg!': [None],
'cl_merge_set!': "on", 'cl_setup': 'network'},
'groups': [
lambda group: group(_("Network"),
normal=('os_install_net_conf',
'os_install_net_data',
'os_install_net_fqdn',
'os_install_ntp'),
expert=('os_install_net_dns',
'os_install_net_dns_search',
'os_install_net_route_data',
'cl_templates_locate',
'cl_dispatch_conf',
'cl_verbose_set'),
next_label=_("Save"))]},
{
# перенастройка системы
'method_name':"setup_system",
'category':__("Configuration"),
'title':__("System"),
'image':'run-build,applications-ide,system-run,system,computer',
'command':'cl-setup-system',
'gui':True,
'rights':['setupsystem'],
'logic':{'Install':install.Install},
'action':ClSetupSystemAction,
'datavars':"install",
'native_error':(VariableError,DataVarsError,install.InstallError),
'setvars':{'cl_action!':'merge','cl_live':'off'},
'groups':[
lambda group:group(_("Update system settings"),
normal=('cl_live',),
expert=('cl_templates_locate','cl_dispatch_conf',
'cl_verbose_set'),
next_label=_("Save"))]},
# перенастройка системы
'method_name': "setup_system",
'category': __("Configuration"),
'title': __("System"),
'image': 'run-build,applications-ide,system-run,system,computer',
'command': 'cl-setup-system',
'gui': True,
'rights': ['setupsystem'],
'logic': {'Install': install.Install},
'action': ClSetupSystemAction,
'datavars': "install",
'native_error': (
VariableError, DataVarsError, install.InstallError),
'setvars': {'cl_action!': 'merge', 'cl_live': 'off'},
'groups': [
lambda group: group(_("Update system settings"),
normal=('cl_live',),
expert=(
'cl_templates_locate',
'cl_dispatch_conf',
'cl_verbose_set'),
next_label=_("Save"))]},
{
# настройка видео
'method_name':"setup_video",
'category':__("Configuration"),
'title':__("Video"),
'image':'system-config-display,video-display,gnome-multimedia',
'command':'cl-setup-video',
'gui':True,
'rights':['setupvideo'],
'logic':{'Install':install.Install},
'action':ClSetupVideoAction,
'datavars':"install",
'native_error':(VariableError,DataVarsError,install.InstallError),
'setvars':{'cl_action!':'merge','cl_merge_pkg!':[None],
'cl_merge_set!':"on",'cl_setup':'video'},
'groups':[
lambda group:group(_("Video"),
normal=('os_install_x11_video_drv',
'os_install_x11_resolution',
'os_install_x11_composite',
'os_install_fb_resolution'),
expert=('cl_templates_locate','cl_dispatch_conf',
'cl_verbose_set'),
next_label=_("Save"))]},
# настройка видео
'method_name': "setup_video",
'category': __("Configuration"),
'title': __("Video"),
'image': 'system-config-display,video-display,gnome-multimedia',
'command': 'cl-setup-video',
'gui': True,
'rights': ['setupvideo'],
'logic': {'Install': install.Install},
'action': ClSetupVideoAction,
'datavars': "install",
'native_error': (
VariableError, DataVarsError, install.InstallError),
'setvars': {'cl_action!': 'merge', 'cl_merge_pkg!': [None],
'cl_merge_set!': "on", 'cl_setup': 'video'},
'groups': [
lambda group: group(_("Video"),
normal=('os_install_x11_video_drv',
'os_install_x11_resolution',
'os_install_x11_composite',
'os_install_fb_resolution'),
expert=(
'cl_templates_locate',
'cl_dispatch_conf',
'cl_verbose_set'),
next_label=_("Save"))]},
{
# настройка локали
'method_name':"setup_locale",
'category':__("Configuration"),
'title':__("Locale"),
'image':'locale,preferences-desktop-locale',
'command':'cl-setup-locale',
'gui':True,
'rights':['setuplocale'],
'logic':{'Install':install.Install},
'action':ClSetupLocaleAction,
'datavars':"install",
'native_error':(VariableError,DataVarsError,install.InstallError),
'setvars':{'cl_action!':'merge','cl_merge_pkg!':[None],
'cl_merge_set!':"on",'cl_setup':'locale'},
'groups':[
lambda group:group(_("Locale"),
normal=('os_install_locale_lang',
'os_install_clock_timezone'),
expert=('cl_templates_locate','cl_dispatch_conf',
'cl_verbose_set'),
next_label=_("Save"))]},
# настройка локали
'method_name': "setup_locale",
'category': __("Configuration"),
'title': __("Locale"),
'image': 'locale,preferences-desktop-locale',
'command': 'cl-setup-locale',
'gui': True,
'rights': ['setuplocale'],
'logic': {'Install': install.Install},
'action': ClSetupLocaleAction,
'datavars': "install",
'native_error': (
VariableError, DataVarsError, install.InstallError),
'setvars': {'cl_action!': 'merge', 'cl_merge_pkg!': [None],
'cl_merge_set!': "on", 'cl_setup': 'locale'},
'groups': [
lambda group: group(_("Locale"),
normal=('os_install_locale_lang',
'os_install_clock_timezone'),
expert=(
'cl_templates_locate',
'cl_dispatch_conf',
'cl_verbose_set'),
next_label=_("Save"))]},
{
# настройка локали
'method_name':"setup_session",
'category':__("Configuration"),
'title':__("Session"),
'image':'system-lock-screen',
'command':'cl-setup-session',
'gui':True,
'rights':['setupsession'],
'logic':{'Install':install.Install},
'action':ClSetupSessionAction,
'datavars':"install",
'native_error':(VariableError,DataVarsError,install.InstallError),
'setvars':{'cl_action!':'merge','cl_merge_pkg!':[None],
'cl_merge_set!':"on",'cl_setup':'session'},
'groups':[
lambda group:group(_("Session"),
normal=('cl_autologin', 'cl_install_home_crypt_set'),
expert=('cl_templates_locate','cl_dispatch_conf',
'cl_verbose_set'),
next_label=_("Save"))]}
]
# настройка локали
'method_name': "setup_session",
'category': __("Configuration"),
'title': __("Session"),
'image': 'system-lock-screen',
'command': 'cl-setup-session',
'gui': True,
'rights': ['setupsession'],
'logic': {'Install': install.Install},
'action': ClSetupSessionAction,
'datavars': "install",
'native_error': (
VariableError, DataVarsError, install.InstallError),
'setvars': {'cl_action!': 'merge', 'cl_merge_pkg!': [None],
'cl_merge_set!': "on", 'cl_setup': 'session'},
'groups': [
lambda group: group(_("Session"),
normal=('cl_autologin',
'cl_install_home_crypt_set'),
expert=(
'cl_templates_locate',
'cl_dispatch_conf',
'cl_verbose_set'),
next_label=_("Save"))]}
]

Loading…
Cancel
Save