Changes for new API

master3.3
parent c9ccf59fff
commit 4e87ca2f5e

@ -1,191 +0,0 @@
#-*- coding: utf-8 -*-
# Copyright 2010 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.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import re
import os
from os import path
from os import access,R_OK
from shutil import copy2
import gzip
from calculate.lib.utils.files import typeFile, process, listDirectory
class KernelConfig:
"""Object for work with kernel config
Example:
# get current config
kc = KernelConfig()
# get specified config
kc = KernelConfig(configFile="/boot/config-2.6.34.1-i686-CLD")
"""
def __init__(self,configFile=None):
if configFile == None:
configFile = '/proc/config.gz'
self.config = self._processConfig(configFile)
def _processConfig(self,configFile):
fileType = typeFile().getMType(configFile).partition(';')[0].strip()
if fileType == "application/x-gzip":
config = gzip.open(configFile)
else:
config = open(configFile,'r')
reEmptyString = re.compile("^(#\s*|\s*)$")
# discard empty strings
data = filter(lambda x:not reEmptyString.match(x),config.readlines())
# convert param names
data = map(lambda x:x.strip().replace("=y","=Y"
).replace("=m","=M"
).replace(" is not set","=N"), data)
# fix data
data = ["# Root"]+map(lambda x: x[2:] if "=N" in x else x,data)[3:]
config = []
curSect = None
for line in data:
if line.startswith('#'):
curSect = line[2:]
else:
config.append([curSect]+line.split('='))
return config
def getSectionParams(self,*regs):
"""Get params from sections specified by regular
Example:
params = kernelconfig.getSectionParams("SCSI Transport","File Sys.*")
"""
params = []
for reg in regs:
reMatch = re.compile(reg,re.M)
params += filter(lambda x:reMatch.search(x[0]),self.config)
return map(lambda x: (x[1],x[2]), params)
def getSections(self):
return list(set(map(lambda x:x[0],self.config)))
class KernelModules:
"""Object for work with current kernel modules"""
def __init__(self):
self._initModulesData()
def _initModulesData(self):
def holderlistdir(dirpath):
dirs = listDirectory(path.join(sysModules,dirpath,"holders"))
return reduce(lambda x,y:x+[y]+holderlistdir(path.join(dirpath,
"holders",y)),
dirs, [])
sysModules = '/sys/module'
holderPath = lambda x: path.join(sysModules,x,"holders")
refPath = lambda x: path.join(sysModules,x,"refcnt")
self.loadModules = filter(lambda x: access(holderPath(x),R_OK) and
access(refPath(x),R_OK),
listDirectory(sysModules))
self.useModules = map(lambda x:int(open(refPath(x),'r').read().strip()),
self.loadModules)
self.depModules = map(lambda x: holderlistdir(x),
self.loadModules)
def getWorkModules(self,forceRemove=[],forceKeep=[]):
"""Get work modules"""
needModules = filter(lambda x:x[1] > len(x[2]),
zip(self.loadModules,
self.useModules,
self.depModules))
needModulesName = set(map(lambda x:x[0],needModules)+forceKeep)
allModules = map(lambda x:x[0],
filter(lambda x:set(x[1])&needModulesName,
zip(self.loadModules,
self.depModules)))
reRemove = re.compile("|".join(forceRemove))
return filter(lambda x: not reRemove.search(x),
map(lambda x:x.replace("-","_"),
allModules+list(needModulesName)))
class InitRamFs:
def __init__(self,initRamFsFile):
self.initrdFile = initRamFsFile
self.tmpPath = path.join('/tmp',path.basename(self.initrdFile))
def _unpackInitRamfs(self):
"""Unpack initramfs"""
self.prevDir = os.getcwd()
if not path.exists(self.tmpPath):
os.mkdir(self.tmpPath)
os.chdir(self.tmpPath)
cpioProcess = process("cpio", "-di")
gzipInitrd = gzip.open(self.initrdFile,'r')
cpioProcess.write(gzipInitrd.read())
res = cpioProcess.success()
os.chdir(self.prevDir)
return res
def searchInside(self,searchFunc):
"""Search data in file list of initramfs"""
cpioProcess = process("cpio", "-tf",
stdin=process("gzip", "-dc", self.initrdFile))
return filter(searchFunc,cpioProcess)
def isModuleInside(self,moduleName):
"""Search module in initramfs"""
return bool(self.searchInside(lambda x: "%s.ko"%moduleName in x))
def _packInitRamfs(self,newInitramfsFile=None):
"""Pack initramfs"""
self.prevDir = os.getcwd()
try:
# get file list for pack
fileList = reduce(lambda x,y: x
+map(lambda z:path.join(y[0],z),y[1])
+map(lambda z:path.join(y[0],z),y[2]),
os.walk(self.tmpPath),
[])
fileList = map(lambda x:x[len(self.tmpPath)+1:],fileList)
# change dir for cpio
os.chdir(self.tmpPath)
# create cpio process
cpioProcess = process("cpio", "-o", "--quiet", "-H","newc")
# send file list to cpio process
cpioProcess.write("\n".join(fileList))
cpioProcess.write("\n")
# get result of cpio
cpioData = cpioProcess.read()
cpioRes = cpioProcess.returncode()
except KeyboardInterrupt:
os.chdir(self.prevDir)
raise KeyboardInterrupt
except Exception,e:
print e.__repr__()
cpioRes = 255
finally:
os.chdir(self.prevDir)
if cpioRes != 0:
return False
# remove old initrd file
if not newInitramfsFile:
newInitramfsFile = self.initrdFile
if path.exists(newInitramfsFile):
os.unlink(newInitramfsFile)
# pack and write new initrd file
initrd = gzip.open(newInitramfsFile,'w')
initrd.write(cpioData)
initrd.close()
return True
def cleanInitRamFs(self,newinitrd=None,video=None):
"""Unpack initramfs clean and pack"""
copy2(self.initrdFile,newinitrd)
return True

@ -1,434 +0,0 @@
#-*- coding: utf-8 -*-
# Copyright 2010-2012 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.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import soaplib, sys, time, os
import threading
from soaplib.serializers.primitive import String, Integer, Any, Boolean
from soaplib.serializers.clazz import Array
from soaplib.service import rpc, DefinitionBase
from calculate.core.server.api_types import ReturnedMessage,CommonInfo
from calculate.core.server.api_types import ChoiceValue, Table, Option, Field, \
GroupField, ViewInfo, ViewParams
from calculate.lib.datavars import VariableError,DataVarsError
from calculate.install.cl_install import InstallError
#from cl_install import Install,DataVarsInstall
import cl_install
from calculate.lib.cl_lang import setLocalTranslate,getLazyLocalTranslate
from calculate.core.server.decorators import Dec
from calculate.core.server.func import catchExcept,commonView
core_method = Dec.core_method
setLocalTranslate('cl_install3',sys.modules[__name__])
import traceback
from functools import wraps,WRAPPER_ASSIGNMENTS
__ = getLazyLocalTranslate(_)
class InstallInfo(CommonInfo):
"""Parameters for method install"""
cl_image_filename = String
cl_image_new_only = Boolean
cl_image_linux_shortname = String
cl_image_arch_machine = String
cl_image_linux_ver = String
cl_image_linux_build = String
os_install_disk_single = String
os_location_data = Array(Array(String))
os_install_uefi_set = Boolean
os_install_mbr = Array(String)
os_install_root_type = String
os_install_scratch = Boolean
cl_uuid_set = Boolean
os_install_kernel_scheduler = String
os_install_locale_lang = String
os_install_clock_timezone = String
cl_migrate_root_pwd = String
cl_migrate_data = Array(Array(String))
cl_autologin = String
os_install_net_fqdn = String
os_install_net_data = Array(Array(String))
os_install_net_route_data = Array(Array(String))
os_install_net_conf = String
os_install_net_dns = String
os_install_net_dns_search = String
os_install_ntp = String
os_install_x11_video_drv = String
os_install_x11_resolution = String
os_install_x11_composite = Boolean
os_install_fb_resolution = String
os_install_grub_terminal = String
os_audio_default = String
cl_autopartition_device = Array(String)
cl_autopartition_scheme = Array(String)
cl_autopartition_set = Boolean
cl_autopartition_table = String
cl_autopartition_root_size = String
cl_live = Boolean
os_install_pxe = Boolean
os_install_pxe_path = String
installCatchExcept = catchExcept(VariableError,DataVarsError,
cl_install.InstallError)
class Wsdl:
from calculate.core.server.baseClass import Basic
from calculate.core.server.decorators import Dec
@rpc(Integer, InstallInfo, _returns = Array(ReturnedMessage))
@core_method(category=__('Installation'),title=__("System install"),
image='calculate-install,system-installer,applications-other,'
'drive-harddisk',
gui=True,command='cl-install',
rights=['install'])
def install ( self, sid, info):
return self.callMethod(sid,info,logicClass=cl_install.Install,
method="installSystem",method_name="install",
callbackRefresh=self.fixInstallLocalization)
def install_vars(self,dv=None):
if not dv:
dv = cl_install.DataVarsInstall()
dv.importInstall()
dv.flIniFile()
dv.Set('cl_action','system',True)
dv.Set('cl_dispatch_conf','usenew',True)
dv.addGroup(_("Language and locale"),
image="welcome",
normal=('os_install_locale_lang','os_install_clock_timezone'))
dv.addGroup(_("Distribution"),
normal=('cl_image_filename',),
expert=('cl_image_linux_shortname', 'cl_image_arch_machine','cl_image_new_only'))
dv.addGroup(_("Allocate drive space"),
normal=('cl_autopartition_set',),
expert=('cl_autopartition_scheme','cl_autopartition_device',
'cl_autopartition_table','cl_autopartition_root_size'),
expert_label=_("Click to set up autopartition options"))
dv.addGroup(_("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',
'os_install_uefi_set'),
expert=('os_install_scratch','cl_uuid_set',
'os_install_root_type',
'os_install_mbr',
'os_install_uefi_set',
'os_install_kernel_scheduler'))
dv.addGroup(_("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',))
dv.addGroup(_("Users"),
normal=('cl_migrate_root_pwd','cl_migrate_data','cl_autologin'),
hide=('cl_migrate_data',),
brief=('cl_migrate_user',))
dv.addGroup(_("Audio"),
normal=('os_audio_default',))
dv.addGroup(_("Video"),
normal=('os_install_x11_video_drv','os_install_x11_composite',
'os_install_x11_resolution','os_install_fb_resolution',
'os_install_grub_terminal'))
dv.addBrief(next_label=_("Installation"),image="finish")
return dv
def fixInstallLocalization(self,sid,dv):
"""
Fix localization on change lang in install method
"""
curThread = threading.currentThread()
curThread.lang = dv.Get('os_install_locale_lang')
currentLang = self.get_cache(sid,"install","lang")
if currentLang != curThread.lang:
dv.clearGroups()
self.install_vars(dv)
dv.reinit()
return True
else:
return False
@rpc(Integer, ViewParams, _returns = ViewInfo)
@installCatchExcept
def install_view (self, sid, params):
dv = self.get_cache(sid,"install","vars")
if not dv:
dv = self.install_vars()
langChanged = False
else:
langChanged = self.fixInstallLocalization(sid,dv)
lang = dv.Get('os_install_locale_lang')
self.set_cache(sid,"install","lang",lang,smart=False)
dv.processRefresh()
self.set_cache(sid, 'install', "vars",dv,smart=False)
view = ViewInfo(dv,viewparams=params,
has_brief=True,
allsteps=langChanged,
brief_label=_("Start installing"))
return view
def install_flash_vars(self):
dv = cl_install.DataVarsInstall()
dv.importInstall()
dv.flIniFile()
dv.Set('cl_action','system',True)
dv.Set('cl_install_type','flash')
dv.Set('cl_dispatch_conf','usenew',True)
dv.addGroup(_("Flash install"),
normal=('os_install_disk_single','cl_image_filename'),
expert=('os_location_data',),
next_label=_("Install"))
return dv
@rpc(Integer, InstallInfo, _returns = Array(ReturnedMessage))
@core_method(category=__('Installation'),title=__('Flash install'),
image='drive-removable-media-usb-pendrive,'
'drive-removable-media-usb,media-flash',
gui=True, rights=['install'])
def install_flash ( self, sid, info):
"""
Install to flash
"""
return self.callMethod(sid,info,logicClass=cl_install.Install,
method="installSystem",method_name="install_flash")
@rpc(Integer, ViewParams,_returns = ViewInfo)
@installCatchExcept
def install_flash_view (self, sid, params):
return commonView(self,sid,params,"install_flash")
def install_pxe_vars(self):
dv = cl_install.DataVarsInstall()
dv.importInstall()
dv.flIniFile()
dv.Set('cl_action','system',True)
dv.Set('os_install_pxe','on',True)
dv.Set('cl_dispatch_conf','usenew',True)
dv.addGroup(None,
normal=('cl_image_filename',),
expert=('os_install_pxe_path',),
next_label=_("Install"))
return dv
@rpc(Integer, InstallInfo, _returns = Array(ReturnedMessage))
@core_method(category=__('Installation'),title=__('PXE install'),
image='network-server,preferences-desktop-remote-desktop',
command='cl-install-pxe',
gui=True, rights=['installpxe'])
def install_pxe ( self, sid, info):
"""
Install to flash
"""
return self.callMethod(sid,info,logicClass=cl_install.Install,
method="installSystem",method_name="install_pxe")
@rpc(Integer, ViewParams,_returns = ViewInfo)
@installCatchExcept
def install_pxe_view (self, sid, params):
return commonView(self,sid,params,"install_pxe")
def setup_network_vars(self):
dv = cl_install.DataVarsInstall()
dv.importInstall()
dv.flIniFile()
dv.Set('cl_action','merge',True)
dv.Set('cl_merge_pkg',[None],True)
dv.Set('cl_merge_set',"on",True)
dv.Set('cl_setup','network',True)
dv.addGroup(None,
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"))
return dv
@rpc(Integer, InstallInfo, _returns = Array(ReturnedMessage))
@core_method(category=__('Configuration'),title=__('Network'),
image='gnome-network-properties,'
'network-idle,preferences-system-network',
command="cl-setup-network",
gui=True, rights=['setup'])
def setup_network ( self, sid, info):
"""
Setup network
"""
return self.callMethod(sid,info,logicClass=cl_install.Install,
method="setupSystem",method_name="setup_network")
@rpc(Integer, ViewParams,_returns = ViewInfo)
@installCatchExcept
def setup_network_view (self, sid, params):
return commonView(self,sid,params,"setup_network")
def setup_video_vars(self):
dv = cl_install.DataVarsInstall()
dv.importInstall()
dv.flIniFile()
dv.Set('cl_action','merge',True)
dv.Set('cl_merge_pkg',[None],True)
dv.Set('cl_merge_set',"on",True)
dv.Set('cl_setup','video',True)
dv.addGroup(None,
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"))
return dv
@rpc(Integer, InstallInfo, _returns = Array(ReturnedMessage))
@core_method(category=__('Configuration'),title=__('Video'),
image='video-display,gnome-multimedia',
command="cl-setup-video",
gui=True, rights=['setup'])
def setup_video ( self, sid, info):
"""
Setup video
"""
return self.callMethod(sid,info,logicClass=cl_install.Install,
method="setupSystem",method_name="setup_video")
@rpc(Integer, ViewParams,_returns = ViewInfo)
@installCatchExcept
def setup_video_view (self, sid, params):
return commonView(self,sid,params,"setup_video")
def setup_locale_vars(self):
dv = cl_install.DataVarsInstall()
dv.importInstall()
dv.flIniFile()
dv.Set('cl_action','merge',True)
dv.Set('cl_merge_pkg',[None],True)
dv.Set('cl_merge_set',"on",True)
dv.Set('cl_setup','locale',True)
dv.addGroup(None,
normal=('os_install_locale_lang',
'os_install_clock_timezone'),
expert=('cl_templates_locate',"cl_dispatch_conf","cl_verbose_set"),
next_label=_("Save"))
return dv
@rpc(Integer, InstallInfo, _returns = Array(ReturnedMessage))
@core_method(category=__('Configuration'),title=__('Locale'),
image='locale,preferences-desktop-locale',
command="cl-setup-locale",
gui=True, rights=['setup'])
def setup_locale ( self, sid, info):
"""
Setup locale
"""
return self.callMethod(sid,info,logicClass=cl_install.Install,
method="setupSystem",method_name="setup_locale")
@rpc(Integer, ViewParams,_returns = ViewInfo)
@installCatchExcept
def setup_locale_view (self, sid, params):
return commonView(self,sid,params,"setup_locale")
def setup_boot_vars(self):
dv = cl_install.DataVarsInstall()
dv.importInstall()
dv.flIniFile()
dv.Set('cl_action','merge',True)
dv.Set('cl_merge_pkg',[None],True)
dv.Set('cl_merge_set',"on",True)
dv.Set('cl_setup','boot',True)
dv.addGroup(None,
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"))
return dv
@rpc(Integer, InstallInfo, _returns = Array(ReturnedMessage))
@core_method(category=__('Configuration'),title=__('Boot'),
image='stock_save,drive-harddisk',command="cl-setup-boot",
gui=True, rights=['setup'])
def setup_boot ( self, sid, info):
"""
Setup locale
"""
return self.callMethod(sid,info,logicClass=cl_install.Install,
method="setupSystem",method_name="setup_boot")
@rpc(Integer, ViewParams,_returns = ViewInfo)
@installCatchExcept
def setup_boot_view (self, sid, params):
return commonView(self,sid,params,"setup_boot")
def setup_system_vars(self):
dv = cl_install.DataVarsInstall()
dv.importInstall()
dv.flIniFile()
dv.Set('cl_action','merge',True)
dv.Set('cl_live','off')
dv.addGroup(None,
normal=("cl_live",),
expert=('cl_templates_locate',"cl_dispatch_conf","cl_verbose_set"),
next_label=_("Reconfigure"))
return dv
@rpc(Integer, InstallInfo, _returns = Array(ReturnedMessage))
@core_method(category=__('Configuration'),title=__('System'),
image='system-run,system,computer',command="cl-setup-system",
gui=True, rights=['setup'])
def setup_system ( self, sid, info):
"""
Setup system
"""
return self.callMethod(sid,info,logicClass=cl_install.Install,
method="setupSystem",method_name="setup_system")
@rpc(Integer, ViewParams,_returns = ViewInfo)
@installCatchExcept
def setup_system_view (self, sid, params):
return commonView(self,sid,params,"setup_system")
def setup_audio_vars(self):
dv = cl_install.DataVarsInstall()
dv.importInstall()
dv.flIniFile()
dv.Set('cl_action','merge',True)
dv.Set('cl_merge_pkg',[None],True)
dv.Set('cl_merge_set',"on",True)
dv.Set('cl_setup','audio',True)
dv.addGroup(None,
normal=('os_audio_default',),
expert=('cl_templates_locate',"cl_dispatch_conf","cl_verbose_set"),
next_label=_("Save"))
return dv
@rpc(Integer, InstallInfo, _returns = Array(ReturnedMessage))
@core_method(category=__('Configuration'),title=__('Audio'),
image='audio-card',command="cl-setup-audio",
gui=True, rights=['setup'])
def setup_audio ( self, sid, info):
"""
Setup locale
"""
return self.callMethod(sid,info,logicClass=cl_install.Install,
method="setupSystem",method_name="setup_audio")
@rpc(Integer, ViewParams,_returns = ViewInfo)
@installCatchExcept
def setup_audio_view (self, sid, params):
return commonView(self,sid,params,"setup_audio")

@ -15,7 +15,7 @@
# limitations under the License.
__app__ = 'calculate-install'
__version__ = '3.0.2'
__version__ = '3.1.6'
import os
import sys

@ -26,9 +26,9 @@ from time import sleep
from subprocess import PIPE,STDOUT
from shutil import copy2
from calculate.core.server.func import safetyWrapper
from calculate.lib.utils.files import (runOsCommand,pathJoin,scanDirectory,
from calculate.lib.utils.files import (runOsCommand,pathJoin,
isMount,process,listDirectory,STDOUT,
checkUtils)
checkUtils,Find,readFile)
from calculate.lib.utils.common import (appendProgramToEnvFile,
removeProgramToEnvFile, getTupleVersion,
cmpVersion,getUserPassword,
@ -45,13 +45,10 @@ from calculate.install.variables.autopartition import (AutopartitionError,
AutoPartition)
from calculate.install.fs_manager import FileSystemManager
from cl_kernel_utils import KernelConfig,InitRamFs
from calculate.lib.variables.locale import Locale
from calculate.lib.cl_template import Template,TemplatesError,ProgressTemplate
from calculate.lib.datavars import DataVars
from calculate.lib.cl_print import color_print
from cl_distr import (PartitionDistributive,
from distr import (PartitionDistributive,
DistributiveError, ScratchPartitionDistributive,
MultiPartitions, FlashDistributive,
Distributive)
@ -63,85 +60,24 @@ from itertools import *
class InstallError(Exception):
"""Installation Error"""
from cl_migrate_users import migrate, currentUsers, MigrationError
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__])
__ = getLazyLocalTranslate(_)
class cltCopy(scanDirectory):
"""Copy clt files
Example:
cltCopier = cltCopy(target="/targetdir")
# copy all clt files from etc directory to /targetdir/etc
cltCopier.performCopy('/etc')
"""
def __init__(self,target='/tmp'):
self.target = target
performCopy = scanDirectory.scanningDirectory
def processingFile(self,pathname,prefix):
try:
if pathname.endswith(".clt"):
targetDir = pathJoin(self.target,path.dirname(pathname))
if not path.exists(targetDir):
os.makedirs(targetDir)
copy2(pathname,pathJoin(self.target,pathname))
except Exception,e:
raise InstallError(_("Failed to copy '%(src)s' to '%(dst)s'")%
{'src':pathname,'dst':pathJoin(self.target,pathname)})
return True
class otherfilesCopy(scanDirectory):
"""Copy some files
Example:
otherfilesCopier = otherfilesCopy(target="/targetdir")
# copy need files from etc directory to /targetdir/etc
otherfilesCopier.performCopy('/etc')
"""
def __init__(self,target='/tmp',reTest=".*"):
self.target = target
self.reTest = re.compile(reTest,re.S)
performCopy = scanDirectory.scanningDirectory
def processingFile(self,pathname,prefix):
try:
if self.reTest.search(pathname):
targetDir = pathJoin(self.target,path.dirname(pathname))
if not path.exists(targetDir):
os.makedirs(targetDir)
copy2(pathname,pathJoin(self.target,pathname))
except Exception,e:
raise InstallError(_("Failed to copy '%(src)s' to '%(dst)s'")%
{'src':pathname,'dst':pathJoin(self.target,pathname)})
return True
class Install(color_print):
class Install:
"""Primary class for templates appling and system installation"""
def __init__(self):
self.clVars = None
self.clTempl = None
self.listDisksOptions = []
self.listBindsOptions = []
self.listSwapsOptions = []
self.startMessage = ""
self.lenStartMessage = 0
self.stdoutHide = None
self.stderrHide = None
# refresh information about LVM
refreshLVM()
# refresh information about device in udevadm info
refreshUdev()
def setNoColor(self):
self.color = False
def initVars(self,datavars=None):
"""Primary initialization of variables"""
if not datavars:
@ -169,6 +105,7 @@ class Install(color_print):
self.installGrub2Bootloader(targetDistr)
else:
self.installLegacyGrubBootloader(targetDistr)
return True
def closeClTemplate(self,error=None):
if self.clTempl:
@ -212,44 +149,59 @@ class Install(color_print):
pass
return dirsFiles
def applyTemplatesFlash(self,directory):
"""Apply templates for root of system."""
#self.clVars.Set("cl_root_path",directory, True)
self.clVars.Set("cl_chroot_path","/", True)
self.clVars.Set("cl_chroot_grub","/", True)
self.clVars.Set("cl_root_path",directory, True)
self.clTempl = ProgressTemplate(self.setProgress,self.clVars,
cltObj=False,
printSUCCESS=self.printSUCCESS,
printWARNING=self.printWARNING,
askConfirm=self.askConfirm,
printERROR=self.printERROR)
dirsFiles = self.clTempl.applyTemplates()
if self.clTempl.getError():
raise InstallError(self.clTempl.getError())
def applyTemplates(self,target=None,cltPath=[],cltFilter=False,root=None,
templates_locate=None):
"""
Применить шаблоны. Если указан target, то директория, где развернут
образ устанавливается как cl_chroot_path. Если указан root, то как
cl_root_path
"""
if target is None:
chroot = '/'
grubdir = '/'
else:
return dirsFiles
def applyTemplates(self,directory,grubDirectory):
"""Apply templates for root of system."""
self.clVars.Set("cl_chroot_path",directory, True)
self.clVars.Set("cl_chroot_grub",grubDirectory, True)
clTemplateCltPath = \
filter(lambda x:path.exists(x),
map(lambda x:pathJoin(directory,x),
self.clVars.Get('cl_template_clt_path')))
self.clVars.Set('cl_template_clt_path',clTemplateCltPath,True)
chroot = target.getDirectory()
grubdir = target.getBootDirectory()[:-4]
if root is None:
root = '/'
else:
root = root.getDirectory()
cltFilter=True if cltFilter in (True,"on") else False,
self.clVars.Set("cl_chroot_path",chroot, True)
self.clVars.Set("cl_chroot_grub",grubdir, True)
self.clVars.Set("cl_root_path",root, True)
# определение каталогов содержащих шаблоны
templates_locate = templates_locate or \
self.clVars.Get('cl_templates_locate')
dirs_list, files_list = ([],[])
useClt = "clt" in templates_locate
self.clVars.Set("cl_template_path",
map(lambda x:x[1],
filter(lambda x:x[0] in templates_locate,
zip(self.clVars.Get('cl_template_location'),
self.clVars.Get('cl_template_path')))),
True)
if cltPath:
clTemplateCltPath = \
filter(lambda x:path.exists(x),
map(lambda x:pathJoin(chroot,x),
cltPath))
self.clVars.Set('cl_template_clt_path',clTemplateCltPath,True)
self.clTempl = ProgressTemplate(self.setProgress,self.clVars,
cltFilter=False,
cltObj=useClt,
cltFilter=cltFilter,
printSUCCESS=self.printSUCCESS,
printWARNING=self.printWARNING,
askConfirm=self.askConfirm,
dispatchConf=self.dispatchConf,
printERROR=self.printERROR)
dirsFiles = self.clTempl.applyTemplates()
if self.clTempl.getError():
raise InstallError(self.clTempl.getError())
else:
return dirsFiles
try:
dirsFiles = self.clTempl.applyTemplates(clTemplateCltPath)
if self.clTempl.getError():
raise InstallError(self.clTempl.getError())
finally:
self.closeClTemplate()
return True
def setActivePartition(self,partition):
"""Change partition id, specified by systemid,set active"""
@ -360,14 +312,6 @@ class Install(color_print):
# is partition active
return self.setActivePartition(self.clVars.Get('os_install_root_dev'))
def varSelect(self,selField,where="os_disk_dev",eq=""):
"""Select value from os_disk/device matrix"""
res = filter(lambda x: x[1] == eq,
zip(self.clVars.Get(selField),
self.clVars.Get(where))) or\
[("","")]
return res[0][0]
def installGrub2Bootloader(self,target):
"""
Install grub2 boot loader
@ -462,7 +406,9 @@ class Install(color_print):
raise DistributiveError(_("Failed to install the bootloader"))
def setupOpenGL(self):
"""Setup opengl for current video driver"""
"""
Выполнить выбор opengl для текущего видеодрайвера
"""
defaultGL = "xorg-x11"
pathGlModules = path.join(self.clVars.Get('cl_chroot_path'),
'usr/lib/opengl')
@ -486,51 +432,29 @@ class Install(color_print):
curModuleName = curModuleName[-1] if curModuleName else ""
if curModuleName == newModuleName:
return True
res,errmes = runOsCommand('eselect opengl set %s'%newModuleName)
if res == 0:
return True
else:
return False
return process('/usr/bin/eselect','opengl','set',newModuleName).success()
def checkVideoDriver(self):
"""Check video driver and install nvidia driver"""
binPackages = '/usr/portage/packages'
nvidiaBinDrivers = path.join(binPackages,'x11-drivers')
if self.clVars.Get('hr_video') != 'nvidia' or \
not path.exists(nvidiaBinDrivers):
"""
Проверить видео драйвер, и если это nvidia, то
обновить маску на пакет видеодрайвера
"""
if self.clVars.Get('hr_video') != 'nvidia':
return True
maskFile = '/etc/portage/package.mask'
nvidiaMaskFile = path.join(maskFile,'nvidia-drivers')
# convert file package.mask to directory package mask
# если package.mask является файлом - делаем его директорией
if path.isfile(maskFile):
os.rename(maskFile,maskFile+"2")
os.mkdir(maskFile,mode=0755)
os.rename(maskFile+"2",path.join(maskFile,"default"))
if path.exists(nvidiaMaskFile):
curNvidiaMask = open(nvidiaMaskFile,'r').read().strip()
else:
curNvidiaMask = ""
curNvidiaMask = readFile(nvidiaMaskFile).strip()
maskNvidia = self.clVars.Get('os_nvidia_mask')
if maskNvidia == curNvidiaMask:
return True
self.startTask(_("Driver installation for %s")%
self.clVars.Get('hr_video'))
open(nvidiaMaskFile,'w').write(maskNvidia)
return True
def cleanInitrd(self):
"""Clean initrd from needless modules"""
# get path to initrd and initrd-install in new system
# (/boot/initramfs-...-install,/boot/initramfs-...)
chrootPath = path.join(self.clVars.Get('cl_chroot_path'),'boot')
initrdPath = path.join(chrootPath,self.clVars.Get('os_install_initrd'))
initrdInstallPath = path.join(chrootPath,
self.clVars.Get('os_install_initrd_install'))
if path.exists(initrdInstallPath):
copy2(initrdInstallPath,initrdPath);
return True
def afterCopyHDDinstall(self,targetDistr):
"""Action performed after distributive copy for hdd install"""
# copy clt files from current system
@ -652,114 +576,74 @@ class Install(color_print):
pass
return True
def installPostAction(self,error):
def autopartition(self,table,devices,data,lvm,lvm_vgname,bios_grub):
"""
Install post action
Авторазметка диска с таблицей разделов 'table', диски указываются
'device', параметры таблицы 'data', 'lvm' использование LVM,
'lvm_vgname' название группы томов LVM, bios_grub - создавать
bios_grub раздел
"""
self.closeClTemplate()
if self.sourceDistr and self.sourceDistr.childs:
self.startTask(_("Letting go the source distribution"))
self.sourceDistr.close()
self.endTask()
if self.targetDistr and self.targetDistr.childs:
self.startTask(_("Unmounting the target system volume"))
self.targetDistr.close()
self.endTask()
ap = Autopartition()
ap.clearLvm(devices,self.clVars)
ap.clearRaid(devices,self.clVars)
ap.recreateSpace(table,devices,data,lvm,lvm_vgname,bios_grub)
return True
@safetyWrapper(native_errors=(MigrationError, TemplatesError, InstallError,
AutopartitionError, DistributiveError),
man_int= __("Installation manually interrupted"),
post_action=installPostAction,
failed_message=__("Failed to install the system!"),
success_message=__("System successfully installed!"))
def installSystem(self,variables):
"""install System by current variable enviroment"""
self.initVars(variables)
results = []
#self.beginFrame()
self.targetDistr = None
self.sourceDistr = None
#self.clVars.printVars()
self.setTaskNumber(25)
if self.clVars.Get('cl_autopartition_set') == 'on':
self.startTask(_("Creating a new partition table"),
progress=True)
ap = AutoPartition()
devices = self.clVars.Get('cl_autopartition_device')
ap.clearLvm(devices,self.clVars)
ap.clearRaid(devices,self.clVars)
ap.recreateSpace(
self.clVars.Get('cl_autopartition_table'),
devices,
self.clVars.Get('cl_autopartition_disk_data'),
self.clVars.GetBool('cl_autopartition_lvm_set'),
self.clVars.Get('cl_autopartition_lvm_vgname'),
self.clVars.Get('cl_autopartition_bios_grub_set')=="on")
self.endTask()
self.targetDistr = self.clVars.Get('cl_target')
self.sourceDistr = self.clVars.Get('cl_image')
# cmd options
if self.targetDistr.needFormat:
self.startTask(_("Formatting the partitions"),progress=True)
self.targetDistr.performFormat()
self.endTask()
# install distributive
#raise InstallError("Manual stop")
self.startTask(_("Unpacking the system image to the target"),
progress=True,num=18)
self.clVars.Get('os_grub_conf')
# set spinner flag
filesnum = self.clVars.Get('os_install_linux_files')
def format(self,target):
"""
Форматировать разделы для 'target' дистрибутива
"""
target.performFormat()
return True
def unpack(self,source,target,filesnum):
"""
Распаковать 'source' в 'target', 'filesnum' количество копируемых файлов
"""
self.addProgress()
if filesnum.isdigit():
filesnum = int(filesnum)
else:
filesnum = 0
self.targetDistr.installFrom(self.sourceDistr,
callbackProgress=self.setProgress,
filesnum=filesnum)
if self.clVars.Get('os_install_pxe') == 'off':
self.targetDistr.convertToDirectory()
self.endTask()
target.installFrom(source, callbackProgress=self.setProgress,
filesnum=filesnum)
return True
self.clVars.processRefresh()
if self.clVars.Get('os_install_root_type') != "flash" and \
self.clVars.Get('os_install_pxe') == 'off':
self.afterCopyHDDinstall(self.targetDistr)
else:
# join templates
if self.clVars.Get('os_install_pxe') == 'on':
self.startTask(
_("Configuring PXE install"),progress=True)
self.applyTemplatesFlash('/')
else:
self.startTask(
_("Configuring Flash install"),progress=True)
self.applyTemplatesFlash(self.targetDistr.getDirectory())
self.endTask()
self.closeClTemplate()
# change boot config
if (self.clVars.Get('os_install_mbr') or
self.clVars.Get('os_install_uefi_set') == 'on') and \
self.clVars.Get('os_install_pxe') == "off":
self.startTask(_("Preparing the system for reboot"))
self.prepareBoot(self.targetDistr)
self.endTask()
if self.clVars.Get('os_install_pxe') == "off" and \
self.askConfirm(_("Would you like to reboot your computer "
"now to complete the installation?"),
default="no") == "yes":
os.system("/sbin/reboot")
return True
def copyClt(self,source,target,cltpath):
"""
Скопировать clt шаблоны из 'cltpath' в 'target' дистрибутив из
'source' дистрибутива
"""
f = Find()
f.search(source.getDirectory(),'/etc',
f.filter(lambda x:x.endswith('.clt'),
f.copypath(target.getDirectory())))
return True
def copyOther(self,source,target):
"""
Скопировать прочие настройки из текущей системы в новую
"""
fileMask = re.compile("(/etc/ssh/ssh_host_.*|"
"/root/.ssh/(id_.*|known_hosts))")
f = Find()
f.search(source.getDirectory(),['/etc','/root/.ssh'],
f.filter(fileMask.search,
f.copypath(target.getDirectory())))
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)])
def _getFreeDirectory(self,directory):
"""
Get free directory name
Получить название директории
"""
newDirectoryName = directory
while path.exists(newDirectoryName):
@ -768,8 +652,9 @@ class Install(color_print):
def remountNTFS(self):
"""
Remount NTFS partitions
Перемонтировать NTFS разделы для работы os-prober
"""
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')
@ -781,9 +666,37 @@ class Install(color_print):
for i in (0.2,0.5,1,2,4,5):
if process('/bin/umount',mountDir).success():
break
time.sleep(i)
else:
self.printWARNING(_("Unable to umount %s")%mountDir)
res = False
try:
os.rmdir(mountDir)
except:
self.printWARNING(_("Unable to remove directory %s")%mountDir)
return False
return res
def mountBind(self,target):
"""
Подключить bind точки монтирования у дистрибутива
"""
target.postinstallMountBind()
return True
def userMigrate(self,target,migrate_data,root_pwd):
"""
Перенос текущих пользователей в новую систему,
установка пароля пользователя root
"""
objMigrate = migrate(target.getDirectory())
if not objMigrate.migrate(migrate_data,root_pwd,[],[],):
raise InstallError(_("Failed to migrate users onto the new system"))
return True
def umount(self,distr):
"""
Отключить дистрибутив
"""
distr.close()
return True

@ -18,7 +18,6 @@ import os, sys, re, time
from calculate.lib.encrypt import encrypt
from os import path
from calculate.lib.utils.files import pathJoin
from calculate.lib.cl_print import color_print
from calculate.lib.cl_lang import setLocalTranslate
setLocalTranslate('cl_install3',sys.modules[__name__])
@ -244,7 +243,7 @@ class migrateShadow(_shareData):
return (systemShadowThisData, systemShadowNewData, dataNewShadow,
dataThisShadow)
class migrate(color_print):
class migrate:
"""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"

@ -0,0 +1,158 @@
#-*- coding: utf-8 -*-
# Copyright 2010 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.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
from calculate.core.server.func import Action
from calculate.lib.cl_lang import setLocalTranslate,getLazyLocalTranslate
from calculate.lib.utils.files import FilesError
from calculate.install.install import (MigrationError, TemplatesError,
InstallError,
AutopartitionError, DistributiveError)
setLocalTranslate('cl_install3',sys.modules[__name__])
__ = getLazyLocalTranslate(_)
class ClInstallAction(Action):
"""
Установка системы
"""
# ошибки, которые отображаются без подробностей
native_error = (FilesError,MigrationError, TemplatesError,
InstallError, AutopartitionError, DistributiveError)
# список задач для дейсвия
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)",
'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':'copy_clt',
'message':__("Copying clt templates to the new system"),
'method':'Install.copyClt(cl_source,cl_target,cl_template_clt_path)',
'depend':(Action.has('hdd'),Action.success())},
# копирование прочих файлов
{'name':'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",
'depend':(Action.has('hdd'),Action.success())},
# перемонтирование ntfs для определения windows
{'name':'remount_ntfs',
'method':'Install.remountNTFS()',
'essential':False,
'depend':(Action.has('hdd'),Action.success())
},
# наложение шаблонов при установке на жесткий диск
{'name':'apply_templates',
'message':__("Updating the configuration"),
# наложить шаблоны в установленный дистрибутив, включая clt шаблоны
# без использования фильтров по clt шаблонам
'method':'Install.applyTemplates(cl_target,cl_template_clt_path,'\
'False,None,cl_templates_locate)',
'depend':(Action.has('hdd'),Action.success()),
},
# наложение шаблонов при PXE установке
{'name':'apply_templates_pxe',
'message':__("Configuring PXE install"),
# наложить шаблоны в установленный дистрибутив, включая clt шаблоны
# без использования фильтров по clt шаблонам
'method':'Install.applyTemplates(None,None,False,None,'\
'cl_templates_locate)',
'condition':lambda dv:dv.Get('os_install_pxe') == 'on'
},
# наложение шаблонов при установке на flash диск
{'name':'apply_templates_flash',
'message':__("Configuring Flash install"),
# наложить шаблоны в установленный дистрибутив, включая clt шаблоны
# без использования фильтров по clt шаблонам
'method':'Install.applyTemplates(None,None,False,cl_target,'\
'cl_templates_locate)',
'condition':lambda dv:dv.Get('os_install_root_type') == "flash"
},
# подключить точки монтирования bind
{'name':'mount_bind',
'message':__("Post-install configuration"),
'method':"Install.mountBind(cl_target)",
'depend':(Action.has('hdd'),Action.success())
},
# перенос пользователей
{'name':'user_migrate',
'message':__("Migrating users"),
'method':'Install.userMigrate(cl_target,cl_migrate_data,'
'cl_migrate_root_pwd)',
'depend':(Action.has('hdd'),Action.success())
},
# подготовка загрузчика
{'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': Action.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': Action.has("unpack")},
# вывести сообщение в случае успеха
{'name':'success',
'message':__("System successfully installed!")},
# вывести сообщение в случае ошибки
{'name':'failed',
'message':__("Failed to install the system!"),
'depend': (Action.failed(),Action.hasnot("interrupt"))},
# вывести сообщение о том, что установка прервана пользователем
{'name':'intmessage',
'message':__("Installation manually interrupted"),
'depend': (Action.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':Action.result("ask_reboot",eq='yes')}
]

@ -0,0 +1,143 @@
#-*- coding: utf-8 -*-
# Copyright 2010 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.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
from calculate.core.server.func import Action
from calculate.lib.cl_lang import setLocalTranslate,getLazyLocalTranslate
from calculate.lib.utils.files import FilesError
from calculate.install.install import (MigrationError, TemplatesError,
InstallError,
AutopartitionError, DistributiveError)
setLocalTranslate('cl_install3',sys.modules[__name__])
__ = getLazyLocalTranslate(_)
class ClSetupBaseAction(Action):
"""
Общий объект настройки параметров системы
"""
# ошибки, которые отображаются без подробностей
native_error = (FilesError,MigrationError, TemplatesError,
InstallError, AutopartitionError, DistributiveError)
addon_tasks = []
templateTaskMessage = __("System are being configured")
successMessage = __("System configured!")
failedMessage = __("Failed to configure the system!")
interruptMessage = __("Configuration manually interrupted")
def __init__(self):
# список задач для дейсвия
self.tasks = [
{'name':'apply_templates',
'message':self.templateTaskMessage,
# наложить шаблоны на текущий дистрибутив, включая clt шаблоны
# без использования фильтров по clt шаблонам
'method':'Install.applyTemplates(cl_source,cl_template_clt_path,'\
'cl_merge_set,None,cl_templates_locate)',
}]
# выполнить дополнительные задачи
self.tasks.extend(self.addon_tasks)
# вывод сообщений о результате действия
self.tasks.extend([
# вывести сообщение в случае успеха
{'name':'success',
'message': self.successMessage,
# вывести сообщение в случае ошибки
{'name':'failed',
'message': self.failedMessage,
'depend': (Action.failed(),Action.hasnot("interrupt"))},
# вывести сообщение о том, что установка прервана пользователем
{'name':'intmessage',
'message':self.interruptMessage,
'depend': (Action.has("interrupt"))},
]
class ClSetupAudioAction(Action):
"""
Действие для настройки аудио параметров
"""
templateTaskMessage = __("Audio settings are being configured")
successMessage = __("Audio settings configured!")
failedMessage = __("Failed to configure the audio parameters!")
class ClSetupLocaleAction(Action):
"""
Действие для настройки языковых параметров
"""
templateTaskMessage = \
__("Localization and time options are being configured")
successMessage = __("System configured!")
failedMessage = __("Failed to configure the system!")
class ClSetupNetworkAction(Action):
"""
Действие для настройки аудио параметров
"""
templateTaskMessage = __("Network settings are being configured")
successMessage = __("Network settings configured!")
failedMessage = __("Failed to configure the network settings!")
class ClSetupUsersAction(Action):
"""
Действие для настройки пользовательских параметров
"""
templateTaskMessage = __("User settings are being configured")
successMessage = __("User settings configured!")
failedMessage = __("Failed to configure the user settings!")
class ClSetupBootAction(Action):
"""
Действие для настройки параметров загрузки
"""
templateTaskMessage = __("Boot parameters are being configured")
successMessage = __("Boot parameters configured!")
failedMessage = __("Failed to configure the boot parameters!")
class ClSetupVideoAction(Action):
"""
Действие для настройки параметров видео
"""
templateTaskMessage = __("Video settings are being configured")
successMessage = __("Video settings configured!")
failedMessage = __("Failed to configure the video settings!")
addon_tasks = [
# проверить и настроить параметры для nvidia драйвера
{'name':'check_video',
'message':__("Checking the video driver"),
'method':'Install.checkVideoDriver()',
},
{'name':'setup_opengl',
'message':__("Configuring OpenGL"),
'method':'Install.setupOpenGL()',
},
{'name':'reboot',
'message':__("To apply the changes, reboot the system"),
'condition': lambda dv:dv.Get('os_x11_video_drv') != \
dv.Get('os_install_x11_video_drv') and \
(dv.Get('os_x11_video_drv') in dv.Get('os_x11_kms_video_drv') \
or dv.Get('os_install_x11_video_drv') \
in dv.Get('os_x11_kms_video_drv'))
},
{'name':'reboot',
'message':__("To apply the changes, reboot the system"),
'condition': lambda dv:dv.Get('os_x11_video_drv') != \
dv.Get('os_install_x11_video_drv') and \
(dv.Get('os_x11_video_drv') in dv.Get('os_x11_kms_video_drv') \
or dv.Get('os_install_x11_video_drv') \
in dv.Get('os_x11_kms_video_drv'))
}
]

@ -115,6 +115,13 @@ class VariableOsInstallX11VideoAvailable(VideoVariable):
getAvailableVideo(prefix=distrPath)))+['other']
return []
class VariableOsX11KmsVideoDrv(ReadonlyVariables):
"""
Список KMS драйверов
"""
type = "list"
value = ["radeon","i915","intel","nouveau","ati"]
class VariableOsInstallX11VideoDrv(VideoVariable):
"""
Video driver used by xorg

@ -27,7 +27,7 @@ from calculate.lib.utils.device import (getUdevDeviceInfo,getDeviceType,
humanreadableSize,refreshUdev)
from calculate.lib.utils.files import (listDirectory,pathJoin,readFile,FStab,
readLinesFile,process,getProgPath)
from calculate.install.cl_distr import PartitionDistributive
from calculate.install.distr import PartitionDistributive
from calculate.install.fs_manager import FileSystemManager
from itertools import *
import operator

@ -31,7 +31,7 @@ from calculate.lib.utils.device import (getUdevDeviceInfo,getDeviceType,
getUUIDDict,getCommonDeviceName)
from calculate.lib.utils.files import (listDirectory,pathJoin,readFile,FStab,
isMount)
from calculate.install.cl_distr import PartitionDistributive
from calculate.install.distr import PartitionDistributive
from calculate.install.fs_manager import FileSystemManager
from calculate.lib.cl_lang import setLocalTranslate

@ -26,7 +26,8 @@ from calculate.lib.utils.common import getSupportArch,getTupleVersion, \
cmpVersion
from calculate.lib.utils.files import readLinesFile, listDirectory
from calculate.lib.variables.linux import Linux
from calculate.install.cl_distr import (Distributive,PartitionDistributive,
from calculate.install.distr import (Distributive,PartitionDistributive,
DirectoryDistributive,
ScratchPartitionDistributive,DistributiveError,FlashDistributive,
MultiPartitions,PxeDistributive)
@ -459,6 +460,15 @@ class VariableClImagePath(ReadonlyVariable):
['/var/calculate/remote/linux',
'/var/calculate/linux'] + livedistr)
class VariableClSource(ReadonlyVariable):
"""
Дистрибутив текущей системы
"""
type = "object"
def get(self):
return DirectoryDistributive('/')
class VariableClTarget(ReadonlyVariable):
"""
Target distributive

@ -25,7 +25,7 @@ from calculate.lib.datavars import (TableVariable,Variable,VariableError,
ReadonlyVariable,ReadonlyTableVariable,
FieldValue)
from calculate.lib.utils.files import (process,checkUtils)
from calculate.install.cl_distr import PartitionDistributive
from calculate.install.distr import PartitionDistributive
from calculate.install.fs_manager import FileSystemManager
from calculate.lib.cl_lang import setLocalTranslate

@ -0,0 +1,400 @@
#-*- coding: utf-8 -*-
# Copyright 2010-2012 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.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys, time, os
from calculate.lib.datavars import VariableError,DataVarsError,DataVars
from calculate.install.install import InstallError
import install
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
# def setup_network_vars(self):
# dv = install.DataVarsInstall()
# dv.importInstall()
# dv.flIniFile()
# dv.Set('cl_action','merge',True)
# dv.Set('cl_merge_pkg',[None],True)
# dv.Set('cl_merge_set',"on",True)
# dv.Set('cl_setup','network',True)
# dv.addGroup(None,
# 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"))
# return dv
#
# @rpc(Integer, InstallInfo, _returns = Array(ReturnedMessage))
# @core_method(category=__('Configuration'),title=__('Network'),
# image='gnome-network-properties,'
# 'network-idle,preferences-system-network',
# command="cl-setup-network",
# gui=True, rights=['setup'])
# def setup_network ( self, sid, info):
# """
# Setup network
# """
# return self.callMethod(sid,info,logicClass=install.Install,
# method="setupSystem",method_name="setup_network")
#
# @rpc(Integer, ViewParams,_returns = ViewInfo)
# @installCatchExcept
# def setup_network_view (self, sid, params):
# return commonView(self,sid,params,"setup_network")
#
# def setup_video_vars(self):
# dv = install.DataVarsInstall()
# dv.importInstall()
# dv.flIniFile()
# dv.Set('cl_action','merge',True)
# dv.Set('cl_merge_pkg',[None],True)
# dv.Set('cl_merge_set',"on",True)
# dv.Set('cl_setup','video',True)
# dv.addGroup(None,
# 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"))
# return dv
#
# @rpc(Integer, InstallInfo, _returns = Array(ReturnedMessage))
# @core_method(category=__('Configuration'),title=__('Video'),
# image='video-display,gnome-multimedia',
# command="cl-setup-video",
# gui=True, rights=['setup'])
# def setup_video ( self, sid, info):
# """
# Setup video
# """
# return self.callMethod(sid,info,logicClass=install.Install,
# method="setupSystem",method_name="setup_video")
#
# @rpc(Integer, ViewParams,_returns = ViewInfo)
# @installCatchExcept
# def setup_video_view (self, sid, params):
# return commonView(self,sid,params,"setup_video")
#
# def setup_locale_vars(self):
# dv = install.DataVarsInstall()
# dv.importInstall()
# dv.flIniFile()
# dv.Set('cl_action','merge',True)
# dv.Set('cl_merge_pkg',[None],True)
# dv.Set('cl_merge_set',"on",True)
# dv.Set('cl_setup','locale',True)
# dv.addGroup(None,
# normal=('os_install_locale_lang',
# 'os_install_clock_timezone'),
# expert=('cl_templates_locate',"cl_dispatch_conf","cl_verbose_set"),
# next_label=_("Save"))
# return dv
#
# @rpc(Integer, InstallInfo, _returns = Array(ReturnedMessage))
# @core_method(category=__('Configuration'),title=__('Locale'),
# image='locale,preferences-desktop-locale',
# command="cl-setup-locale",
# gui=True, rights=['setup'])
# def setup_locale ( self, sid, info):
# """
# Setup locale
# """
# return self.callMethod(sid,info,logicClass=install.Install,
# method="setupSystem",method_name="setup_locale")
#
# @rpc(Integer, ViewParams,_returns = ViewInfo)
# @installCatchExcept
# def setup_locale_view (self, sid, params):
# return commonView(self,sid,params,"setup_locale")
#
# def setup_boot_vars(self):
# dv = install.DataVarsInstall()
# dv.importInstall()
# dv.flIniFile()
# dv.Set('cl_action','merge',True)
# dv.Set('cl_merge_pkg',[None],True)
# dv.Set('cl_merge_set',"on",True)
# dv.Set('cl_setup','boot',True)
# dv.addGroup(None,
# 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"))
# return dv
#
# @rpc(Integer, InstallInfo, _returns = Array(ReturnedMessage))
# @core_method(category=__('Configuration'),title=__('Boot'),
# image='stock_save,drive-harddisk',command="cl-setup-boot",
# gui=True, rights=['setup'])
# def setup_boot ( self, sid, info):
# """
# Setup locale
# """
# return self.callMethod(sid,info,logicClass=install.Install,
# method="setupSystem",method_name="setup_boot")
#
# @rpc(Integer, ViewParams,_returns = ViewInfo)
# @installCatchExcept
# def setup_boot_view (self, sid, params):
# return commonView(self,sid,params,"setup_boot")
#
# def setup_system_vars(self):
# dv = install.DataVarsInstall()
# dv.importInstall()
# dv.flIniFile()
# dv.Set('cl_action','merge',True)
# dv.Set('cl_live','off')
# dv.addGroup(None,
# normal=("cl_live",),
# expert=('cl_templates_locate',"cl_dispatch_conf","cl_verbose_set"),
# next_label=_("Reconfigure"))
# return dv
#
# @rpc(Integer, InstallInfo, _returns = Array(ReturnedMessage))
# @core_method(category=__('Configuration'),title=__('System'),
# image='system-run,system,computer',command="cl-setup-system",
# gui=True, rights=['setup'])
# def setup_system ( self, sid, info):
# """
# Setup system
# """
# return self.callMethod(sid,info,logicClass=install.Install,
# method="setupSystem",method_name="setup_system")
#
# @rpc(Integer, ViewParams,_returns = ViewInfo)
# @installCatchExcept
# def setup_system_view (self, sid, params):
# return commonView(self,sid,params,"setup_system")
#
# def setup_audio_vars(self):
# dv = install.DataVarsInstall()
# dv.importInstall()
# dv.flIniFile()
# dv.Set('cl_action','merge',True)
# dv.Set('cl_merge_pkg',[None],True)
# dv.Set('cl_merge_set',"on",True)
# dv.Set('cl_setup','audio',True)
# dv.addGroup(None,
# normal=('os_audio_default',),
# expert=('cl_templates_locate',"cl_dispatch_conf","cl_verbose_set"),
# next_label=_("Save"))
# return dv
#
# @rpc(Integer, InstallInfo, _returns = Array(ReturnedMessage))
# @core_method(category=__('Configuration'),title=__('Audio'),
# image='audio-card',command="cl-setup-audio",
# gui=True, rights=['setup'])
# def setup_audio ( self, sid, info):
# """
# Setup locale
# """
# return self.callMethod(sid,info,logicClass=install.Install,
# method="setupSystem",method_name="setup_audio")
#
# @rpc(Integer, ViewParams,_returns = ViewInfo)
# @installCatchExcept
# def setup_audio_view (self, sid, params):
# return commonView(self,sid,params,"setup_audio")
class Wsdl(WsdlBase):
methods = [{
# идентификатор метода
'method_name':"install",
# категория метода
'category':__("Installation"),
# заголовок метода
'title':__("System install"),
# иконка для графической консоли
'image':'calculate-install,system-installer,applications-other,'\
'drive-harddisk',
# метод присутствует в графической консоли
'gui':True,
# консольная команда
'command':'cl-install',
# права для запуска метода
'rights':['install'],
# объект содержащий модули для действия
'logic':{'Install':install.Install},
# описание действия
'action':ClInstallAction,
# объект переменных
'datavars':"install",
'native_error':(VariableError,DataVarsError, install.InstallError),
# значения по умолчанию для переменных этого метода
'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',),
expert=('cl_image_linux_shortname', 'cl_image_arch_machine',
'cl_image_new_only')),
lambda group:group(_("Allocate drive space"),
normal=('cl_autopartition_set',),
expert=('cl_autopartition_scheme','cl_autopartition_device',
'cl_autopartition_table','cl_autopartition_root_size'),
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',
'os_install_uefi_set'),
expert=('os_install_scratch','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'),
hide=('cl_migrate_data',),
brief=('cl_migrate_user',)),
lambda group:group(_("Audio"),
normal=('os_audio_default',)),
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'))],
# действие выводит информацию перед запуском
'brief':{'next':__("Installation"),
'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,DataVarsError,install.InstallError),
'setvars':{'cl_action!':'system','cl_install_type':'flash',
'cl_dispatch_conf':'usenew'},
'groups':[
lambda group:group(_("Flash install"),
normal=('os_install_disk_single','cl_image_filename'),
expert=('os_location_data',),
next_label=_("Install"))]},
# PXE установка
{
'method_name':"install_pxe",
'category':__("Installation"),
'title':__("PXE install"),
'image':'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,DataVarsError,install.InstallError),
'setvars':{'cl_action!':'system','os_install_pxe!':'on',
'cl_dispatch_conf':'usenew'},
'groups':[
lambda group:group(_("PXE install"),
normal=('cl_image_filename',),
expert=('os_install_pxe_path',),
next_label=_("Install"))]},
# настройка аудио
{
'method_name':"setup_audio",
'category':__("Configuration"),
'title':__("Audio"),
'image':'audio-card',
'command':'cl-setup-audio',
'gui':True,
'rights':['setupaudio'],
'logic':{'Install':install.Install},
'action':ClSetupAudioAction,
'datavars':"install",
'native_error':(VariableError,DataVarsError,install.InstallError),
'setvars':{'cl_action!':'merge','cl_merge_pkg!':[None],
'cl_merge_set!':"on",'cl_setup!':'audio'},
'groups':[
lambda group:group(_("Audio"),
normal=('os_audio_default',),
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"))]}]
# def setup_audio_vars(self):
# dv = install.DataVarsInstall()
# dv.importInstall()
# dv.flIniFile()
# dv.Set('cl_action','merge',True)
# dv.Set('cl_merge_pkg',[None],True)
# dv.Set('cl_merge_set',"on",True)
# dv.Set('cl_setup','audio',True)
# dv.addGroup(None,
# normal=('os_audio_default',),
# expert=('cl_templates_locate',"cl_dispatch_conf","cl_verbose_set"),
# next_label=_("Save"))
# return dv
#
# @rpc(Integer, InstallInfo, _returns = Array(ReturnedMessage))
# @core_method(category=__('Configuration'),title=__('Audio'),
# image='audio-card',command="cl-setup-audio",
# gui=True, rights=['setup'])
# def setup_audio ( self, sid, info):
# """
# Setup locale
# """
# return self.callMethod(sid,info,logicClass=install.Install,
# method="setupSystem",method_name="setup_audio")
#
# @rpc(Integer, ViewParams,_returns = ViewInfo)
# @installCatchExcept
# def setup_audio_view (self, sid, params):
# return commonView(self,sid,params,"setup_audio")

@ -176,7 +176,8 @@ setup(
url = "http://calculate-linux.org",
license = "http://www.apache.org/licenses/LICENSE-2.0",
package_dir = {'calculate.install': "install"},
packages = ['calculate.install','calculate.install.variables'],
packages = ['calculate.install','calculate.install.utils',
'calculate.install.variables'],
data_files = data_files,
scripts=[],
cmdclass={'install_data': cl_install_data,

Loading…
Cancel
Save