Add appling templates

netsetup
Mike Hiretsky 14 years ago
parent 15d1d79989
commit dd6635caef

@ -12,6 +12,7 @@ import re
import sys
from cl_utils import runOsCommand,isMount,removeDir,typeFile
from shutil import copyfile
from cl_template import _terms
class DistributiveError(Exception):
@ -47,6 +48,7 @@ class DistributiveRepository:
def _getAvailableDistributives(self,system=None,shortname=None,march=None,
version=None):
"""Get all distributives by filter"""
def distfilter(dist):
match = self.reDistName.match(dist)
if not match:
@ -63,6 +65,7 @@ class DistributiveRepository:
return [ dist for dist in os.listdir(self.root) if distfilter(dist) ]
def _getDistributiveByFile(self,filename):
"""Get Distributive object by filename"""
# MAGIC_COMPRESS 0x000004 Check inside compressed files
tf = typeFile(magic=0x4)
ftype = tf.getMType(filename)
@ -77,14 +80,27 @@ class DistributiveRepository:
raise DistributiveError("Wrong distributive '%s':\n%s"%
(filename,ftype))
def getLastDistributive(self,system=None,shortname=None,march=None,
version=None):
"""Get the actualest distributive"""
availDistrs = self._getAvailableDistributives(system,shortname,
march,version)
# TODO: add priority for select actualy distributive
# TODO: improve selecting best distributive
if availDistrs:
term = _terms()
bestDistr = availDistrs[0]
bestDict = self.reDistName.match(bestDistr).groupdict()
for dist in availDistrs[1:]:
match = self.reDistName.match(dist)
d = match.groupdict()
v1,v2 = term._convertVers(d['ver'],bestDict['ver'])
if v1 > v2 or \
bestDict['ext'] != 'iso' and d['ext'] == 'iso':
bestDistr = dist
bestDict = d
return self._getDistributiveByFile(
pathjoin(self.root,availDistrs[0]))
pathjoin(self.root,bestDistr))
else:
return None
@ -111,7 +127,7 @@ class Distributive(object):
DirectoryDistributive object
dist1 = ArchiveDistributive(file="/os.tar.bz2",mdirectory="/tmp/test")
dist2 = dist1.convertTo(DirectoryDistributive)
dist2 = dist1.convertToDirectory()
dist2.detach()
dist1.close()
...
@ -126,7 +142,7 @@ class Distributive(object):
Example:
dist1 = PartitionDistributive(partition="/dev/sda2")
dist2 = dist1.convertTo(DirectoryDistributive)
dist2 = dist1.convertToDirectory()
dist1.close()
"""
# close all child
@ -149,27 +165,25 @@ class Distributive(object):
unmounted."""
pass
def _convertTo(self,typeDistributive):
"""Overridden"""
return None
def convertTo(self,typeDistributive):
def convertToDirectory(self):
"""Default c raise error about impossible convert object"""
obj = self._convertTo(typeDistributive)
if obj:
return obj
else:
raise DistributiveError("Cann't convert '%s' to '%s'" %
raise DistributiveError("Cann't convert '%s' to '%s'" %
(self.__class__.__name__,
typeDistributive.__name__))
"DirectoryDistributive"))
# def __del__(self):
# """Uncomment this method for automaticaly release all distributive
# instance"""
# self.close()
def runOsCommand(self, *argv, **kwarg):
res,mes = runOsCommand(*argv,**kwarg)
if type(mes) == types.ListType:
mes = "\n".join(map(lambda x: x.strip(), mes))
return res,mes
def getDirectory(self):
return self.convertTo(DirectoryDistributive).directory
return self.convertToDirectory().directory
def _makeDirectory(self,path):
"""Make directory and parent.
@ -206,7 +220,7 @@ class Distributive(object):
def copy(self,fromdir,todir):
"""Copy files from 'fromdir' directory to 'todir' directory"""
res,errmes = runOsCommand("rsync -a -x %s/ %s/" % (fromdir,todir))
res,errmes = self.runOsCommand("rsync -a -x %s/ %s/" % (fromdir,todir))
if res == 0:
return True
else:
@ -223,7 +237,7 @@ class Distributive(object):
if isMount(directory):
raise DistributiveError("Cann't mount to directory:\n"+
"Directory already mounted")
res,errmes = runOsCommand("/bin/mount %s %s %s"%
res,errmes = self.runOsCommand("/bin/mount %s %s %s"%
(mountopts,file,directory))
if res == 0:
return True
@ -239,7 +253,7 @@ class Distributive(object):
if isMount(directory):
for wait in [0,0.5,2,5]:
sleep(wait)
res,errmes = runOsCommand("/bin/umount %s"%directory)
res,errmes = self.runOsCommand("/bin/umount %s"%directory)
if res == 0:
return True
raise DistributiveError("Cann't umount %s:\n%s"%
@ -264,9 +278,8 @@ class DirectoryDistributive(Distributive):
if not parent:
self._makeDirectory(self.directory)
def _convertTo(self,typeDistributive):
if typeDistributive == DirectoryDistributive:
return self
def convertToDirectory(self):
return self
def installFrom(self, source):
"""Install distributive to directory from source distributive"""
@ -274,7 +287,7 @@ class DirectoryDistributive(Distributive):
source.unpackTo(self.directory)
else:
# get source distributive as directory distributive
dFrom = source.convertTo(DirectoryDistributive)
dFrom = source.convertToDirectory()
# copy distributive from source to this
self.copy(dFrom.directory,self.directory)
@ -313,7 +326,7 @@ class PartitionDistributive(Distributive):
self._umountPartition(child.directory)
child.directory = None
def _convertToDirectory(self):
def convertToDirectory(self):
mdirectory = self.mdirectory
for child in self.childs:
if isinstance(child,DirectoryDistributive) and \
@ -323,16 +336,19 @@ class PartitionDistributive(Distributive):
self._mountPartition(self.partition,mdirectory)
return DirectoryDistributive(mdirectory,parent=self)
def _convertTo(self,typeDistributive):
if typeDistributive == DirectoryDistributive:
return self._convertToDirectory()
if typeDistributive == PartitionDistributive:
return self
def formatPartition(self,format="reiserfs"):
res,errmes = self.runOsCommand("mkfs.reiserfs -f %s" % self.partition)
if res == 0:
return True
else:
raise DistributiveError("Cann't format partition %s:\n%s"%
(self.partition,errmes))
def installFrom(self, source):
"""Install distributive to partition from source distributive"""
# get currect partition as directory
distrTo = self.convertTo(DirectoryDistributive)
self.formatPartition()
distrTo = self.convertToDirectory()
# install into directroy distributive from source
distrTo.installFrom(source)
@ -347,7 +363,7 @@ class ArchiveDistributive(Distributive):
Return bzip2,gzip,7z or None
"""
res,mes = runOsCommand("/usr/bin/file %s"%file)
res,mes = self.runOsCommand("/usr/bin/file %s"%file)
if "bzip2 compressed data" in mes:
return "bzip2"
elif "gzip compressed data" in mes:
@ -369,13 +385,13 @@ class ArchiveDistributive(Distributive):
self._makeDirectory(directory)
# unpack archive
if archiveType == "7z":
res,mes = runOsCommand("7za x -so %s | tar xf - -C %s/"%
res,mes = self.runOsCommand("7za x -so %s | tar xf - -C %s/"%
(archfile,directory))
elif archiveType == "bzip2":
res,mes = runOsCommand("tar xjf %s -C %s/"%
res,mes = self.runOsCommand("tar xjf %s -C %s/"%
(archfile,directory))
elif archiveType == "gzip":
res,mes = runOsCommand("tar xf %s -C %s/"%
res,mes = self.runOsCommand("tar xf %s -C %s/"%
(archfile,directory))
else:
raise DistributiveError("Unknown archive type by '%s'"%file)
@ -386,7 +402,7 @@ class ArchiveDistributive(Distributive):
"""Unpack currect archive to directory"""
self._unpackArchive(self.file,directory)
def _convertToDirectory(self):
def convertToDirectory(self):
"""Get archive as directory (unpack to directory)"""
# check may be the archive already unpacked
mdirectory = self.mdirectory
@ -406,15 +422,8 @@ class ArchiveDistributive(Distributive):
self._removeDirectory(child.directory)
child.directory = None
def _convertTo(self,typeDistributive):
"""Support DirectroyDistributive and ArchiveDistributive"""
if typeDistributive == DirectoryDistributive:
return self._convertToDirectory()
if typeDistributive == ArchiveDistributive:
return self
def packToArchive(self,directory,file):
res,errmes = runOsCommand("tar cf %s -C %s ."%(file,directory))
res,errmes = self.runOsCommand("tar cf %s -C %s ."%(file,directory))
if res != 0:
raise DistributiveError("Cann't create archive '%s':\n%s"%
(file,errmes))
@ -422,7 +431,7 @@ class ArchiveDistributive(Distributive):
def installFrom(self, source):
"""Install distributive to partition from source distributive"""
# get source distributive as directory distributive
dFrom = source.convertTo(DirectoryDistributive)
dFrom = source.convertToDirectory()
# install into directroy distributive from source
self.packToArchive(dFrom.directory, self.file)
@ -441,7 +450,7 @@ class SquashDistributive(Distributive):
self._umountDirectory(directory)
self._removeDirectory(directory)
def _convertToDirectory(self):
def convertToDirectory(self):
mdirectory = self.mdirectory
for child in self.childs:
if isinstance(child,DirectoryDistributive) and \
@ -457,14 +466,8 @@ class SquashDistributive(Distributive):
self._umountSquash(child.directory)
child.directory = None
def _convertTo(self,typeDistributive):
if typeDistributive == DirectoryDistributive:
return self._convertToDirectory()
elif typeDistributive == SquashDistributive:
return self
def packToSquash(self,directory,file):
res,errmes = runOsCommand("/usr/bin/mksquashfs %s/ %s"%
res,errmes = self.runOsCommand("/usr/bin/mksquashfs %s/ %s"%
(directory,file))
if res != 0:
raise DistributiveError("Cann't create squashfs '%s':\n%s"%
@ -473,7 +476,7 @@ class SquashDistributive(Distributive):
def installFrom(self, source):
"""Install distributive to partition from source distributive"""
# get source distributive as directory distributive
dFrom = source.convertTo(DirectoryDistributive)
dFrom = source.convertToDirectory()
# install into directroy distributive from source
self.packToSquash(dFrom.directory, self.file)
@ -510,7 +513,7 @@ class IsoDistributive(Distributive):
curnum = num
return curfile
def _convertToSquash(self):
def convertToSquash(self):
mdirectory = self.mdirectory
for child in self.childs:
if isinstance(child,SquashDistributive) and \
@ -531,14 +534,8 @@ class IsoDistributive(Distributive):
self._umountIso(pathdirname(child.file))
child.directory = None
def _convertTo(self,typeDistributive):
if typeDistributive == DirectoryDistributive:
return self.convertTo(SquashDistributive).\
convertTo(DirectoryDistributive)
if typeDistributive == SquashDistributive:
return self._convertToSquash()
if typeDistributive == IsoDistributive:
return self
def convertToDirectory(self):
return self.convertToSquash().convertToDirectory()
def prepareIso(self,directory):
print("apply iso templates to %s/"%directory)
@ -554,8 +551,14 @@ class IsoDistributive(Distributive):
except (Exception,KeyboardInterrupt),e:
raise DistributiveError("Cann't remove %s:\n%s"%(file,str(e)))
res,errmes = runOsCommand("/usr/bin/mkisofs -b isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table -iso-level 4 -hide boot.catalog -o %s %s/"%
(file,directory))
res,errmes = self.runOsCommand(
"%(progname)s %(params)s -o %(target)s %(source)s/"%
{'progname':'/usr/bin/mkisofs',
'params':" ".join(["-b isolinux/isolinux.bin","-no-emul-boot",
"-boot-load-size 4","-boot-info-table","-iso-level 4",
"-hide boot.catalog"]),
'target':file,
'source':directory})
if res == 0:
return True
else:
@ -575,7 +578,7 @@ class IsoDistributive(Distributive):
self._copyfile(source.file,
pathjoin(isoDirectory,"livecd.squashfs"))
else:
distDirectory = source.convertTo(DirectoryDistributive)
distDirectory = source.convertToDirectory()
squashDistr = SquashDistributive(
pathjoin(isoDirectory,"livecd.squashfs"))
squashDistr.installFrom(distDirectory)

@ -19,18 +19,5 @@ import re
from cl_datavars import glob_attr
class fillVars(object, glob_attr):
def get_cl_template_path(self):
"""list appied templates"""
profpath = []
profPaths=['/usr/lib/calculate-2.2/calculate-install/templates',
'/var/calculate/remote/templates',
'/var/calculate/templates']
for profPath in profPaths:
if os.path.isdir(profPath):
paths = os.listdir(profPath)
for path in paths:
ph = os.path.join(profPath,path)
if os.path.isdir(ph) and os.listdir(ph):
profpath.append(ph)
return profpath
pass

@ -29,11 +29,17 @@ from cl_print import color_print
from cl_distr import PartitionDistributive,DistributiveRepository,\
DistributiveError, ScratchDistributive
from time import sleep
import cl_overriding
tr = lang()
tr.setGlobalDomain('cl_install')
tr.setLanguage(sys.modules[__name__])
def installExit(*args,**kwars):
raise InstallError("Processing template error")
cl_overriding.exit = installExit
class InstallError(Exception):
"""Installation Error"""
pass
@ -88,8 +94,58 @@ class cl_install(color_print):
return dirsFiles
def printInfo(self,sourceDistr,targetDistr):
self.printSUCCESS(_("Machine hardware name: %s")%
self.clVars.Get('os_arch_machine'))
self.printSUCCESS(_("Installation %s %s")%
("<needed>","<needed>"))
# (self.clVars.Get('os_linux_name'),
# self.clVars.Get('os_linux_subname')))
self.defaultPrint(_("System information\n"))
self.printSUCCESS(_("Computer name")+": %s"%
self.clVars.Get('os_net_hostname'))
self.printSUCCESS(_("Domain name")+": %s"%
self.clVars.Get('os_net_domain'))
self.printSUCCESS(_("Network devices")+": %s"%
"<needed>")
self.printSUCCESS(_("Installed system")+": %s %s"%
(self.clVars.Get('os_linux_name'),
self.clVars.Get('os_linux_ver')))
self.defaultPrint(_("Hardware\n"))
self.printSUCCESS(_("Machine hardware name")+": %s"%
self.clVars.Get('os_arch_machine'))
self.printSUCCESS(_("Quantity processors")+": %s(var name)"%
self.clVars.Get('hr_cpus'))
self.printSUCCESS(_("Videocard")+": %s"%
'<needed>')
self.printSUCCESS(_("Screen resolution")+": %s"%
'<needed>')
self.defaultPrint(_("Localization\n"))
self.printSUCCESS(_("Language")+": %s"%
self.clVars.Get('os_locale_lang'))
self.printSUCCESS(_("Keymap")+": %s"%
self.clVars.Get('os_locale_xkbname'))
self.printSUCCESS(_("Timezone")+": %s"%
self.clVars.Get('os_clock_timezone'))
self.defaultPrint(_("Location\n"))
self.printSUCCESS(_("Working volume")+": %s"%
self.clVars.Get('os_root_dev'))
self.printSUCCESS(_("Installation volume")+": %s"%
"<needed>")
self.printSUCCESS(_("File system")+": %s"%
"<needed>")
self.printSUCCESS(_("Swap disk")+": %s"%
"<needed>")
self.printSUCCESS(_("Mounted disks")+": %s"%
"<needed>")
self.defaultPrint(_("Network services\n"))
self.printSUCCESS(_("PROXY")+": %s"%
"<needed>")
self.printSUCCESS(_("NTP")+": %s"%
"<needed>")
self.printSUCCESS(_("Authentification")+": %s"%
"<needed>")
self.printSUCCESS("Found update: %s"%self.clVars.Get('os_linux_name'))
def wait(self,sec=10):
@ -108,8 +164,16 @@ class cl_install(color_print):
return PartitionDistributive(disk,mdirectory="/mnt/install",
check=True)
def joinTemplates(self,directory):
pass
def applyTemplates(self,directory):
"""Apply templates for root of system."""
self.clVars.Set("cl_root_path",directory, True)
self.clTemp = template(self.clVars)
dirsFiles = self.clTemp.applyTemplates()
if self.clTemp.getError():
self.printERROR(self.clTemp.getError())
return False
else:
return dirsFiles
def installSystem(self,disk="",buildermode=False):
"""install System by current variable enviroment"""
@ -126,30 +190,40 @@ class cl_install(color_print):
# print info
self.printInfo(sourceDistr,targetDistr)
# wait 10 sec
self.wait(3)
waittime = 3
self.printSUCCESS(_("Installation will start pass %d seconds.")
%waittime)
self.wait(waittime)
# install distributive
self.printSUCCESS(_("Unpacking system image into target"))
targetDistr.installFrom(sourceDistr)
self.printOK("Unpacking complete")
# join templates
self.printSUCCESS(_("Update config"))
self.joinTemplates(targetDistr.getDirectory())
self.applyTemplates(targetDistr.getDirectory())
# change boot config
self.printSUCCESS(_("Prepare system for reboot"))
self.prepareBoot()
else:
self.printWARNING("No update available.")
except DistributiveError,e:
except (InstallError,DistributiveError),e:
error = e
except KeyboardInterrupt,e:
self.printWARNING("Interruping the installation")
error = _("Installation manually interrupt")
if sourceDistr:
sourceDistr.close()
if targetDistr:
targetDistr.close()
try:
if sourceDistr:
self.printSUCCESS("Releasing source distributive")
sourceDistr.close()
if targetDistr:
self.printSUCCESS("Unmount installed system volume")
targetDistr.close()
except KeyboardInterrupt,e:
pass
if error:
self.printERROR(str(error))
for line in str(error).split('\n'):
self.printERROR(line)
return False
return False

@ -22,9 +22,6 @@
# printval - print value of variable
class Data:
# list of applied templates
cl_template_path = {}
# relative path for apply templates on files of system
cl_root_path = {}

@ -56,6 +56,6 @@ if __name__ == "__main__":
else:
if not install.installSystem():
sys.exit(1)
if not install.writeVars(opts):
if not install.writeVars(options):
sys.exit(1)
sys.exit(0)

@ -0,0 +1 @@
# Calculate append=skip cl_name==calculate-install

@ -0,0 +1 @@
# Calculate append=skip

@ -0,0 +1,2 @@
# Calculate belong()!=&&pkg(sys-apps/openrc)!= append=skip

@ -0,0 +1 @@
# Calculate path=/etc name=conf.d

@ -0,0 +1,8 @@
# Calculate os_linux_shortname!=CSS
# On which TTYs should fbcondecor be enabled? Defaults to RC_TTY_NUMBER.
FBCONDECOR_TTYS="1 2 3 4 5 6"
# Allows to set different themes on different consoles
# format: "<console>:<theme> <console>:<theme> (...)"
FBCONDECOR_TTY_MAP="1:tty1 2:tty2 3:tty3 4:tty4 5:tty5 6:tty6"

@ -0,0 +1,2 @@
MOUSE=imps2
MOUSEDEV=/dev/psaux

@ -0,0 +1,3 @@
pata_all_args="-d1 -X69 -c1"
sata_all_args=""
all_args=""

@ -0,0 +1 @@
HOSTNAME="#-os_net_hostname-#"

@ -0,0 +1,4 @@
# Calculate os_root_type==ram
#переведем системное время на livecd
hwclock --hctosys
Loading…
Cancel
Save