|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# Copyright 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.
|
|
|
|
# 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
|
|
|
|
import os
|
|
|
|
from os import path
|
|
|
|
import re
|
|
|
|
from calculate.install import distr
|
|
|
|
from calculate.install.distr import DistributiveError
|
|
|
|
from calculate.lib.datavars import ReadonlyVariable, SimpleDataVars
|
|
|
|
from calculate.lib.utils.tools import ignore
|
|
|
|
from calculate.lib.variables import linux
|
|
|
|
from calculate.update.variables import update
|
|
|
|
from calculate.lib.variables import system
|
|
|
|
|
|
|
|
from calculate.lib.cl_lang import setLocalTranslate
|
|
|
|
import datetime
|
|
|
|
import profiles
|
|
|
|
|
|
|
|
setLocalTranslate('cl_builder3', sys.modules[__name__])
|
|
|
|
|
|
|
|
|
|
|
|
class BuilderLinux(ReadonlyVariable):
|
|
|
|
# variable for get current system info (example: os_linux_shortname)
|
|
|
|
variable = ""
|
|
|
|
|
|
|
|
def get(self):
|
|
|
|
dv = self.Get('cl_builder_linux_datavars')
|
|
|
|
if dv:
|
|
|
|
return dv[self.variable]
|
|
|
|
else:
|
|
|
|
return ""
|
|
|
|
|
|
|
|
class DataVarsBuilderLinux(linux.LinuxDataVars):
|
|
|
|
"""
|
|
|
|
Упрощенная модель переменных для собираемого образа
|
|
|
|
"""
|
|
|
|
def variables(self):
|
|
|
|
l = super(DataVarsBuilderLinux, self).variables()
|
|
|
|
return l + [update.VariableClProfileSystem(),
|
|
|
|
update.VariableClProfileRepository(),
|
|
|
|
system.VariableOsArchMachineGentoo(),
|
|
|
|
update.VariableClProfileData()]
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def StageInformation(cls, fn):
|
|
|
|
re_stage = re.compile("stage(\d)-(amd64|x86)-(\d{8}).tar.\w+")
|
|
|
|
m = re_stage.search(fn)
|
|
|
|
if m:
|
|
|
|
map_arch = {'amd64': 'x86_64', 'x86': 'i686'}
|
|
|
|
c = {'os_linux_build': m.group(3),
|
|
|
|
'os_arch_machine':map_arch[m.group(2)],
|
|
|
|
'os_linux_shortname': 'Gentoo',
|
|
|
|
'os_linux_subname': "Stage%s"%m.group(1),
|
|
|
|
'cl_profile_name': 'Gentoo profile',
|
|
|
|
'os_linux_name': 'Gentoo'}
|
|
|
|
else:
|
|
|
|
c = {}
|
|
|
|
obj = cls(cache=c)
|
|
|
|
for vn in obj.allVars.keys():
|
|
|
|
if vn not in obj.cache:
|
|
|
|
obj.cache[vn] = ''
|
|
|
|
return obj
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return "Builder variables"
|
|
|
|
|
|
|
|
|
|
|
|
class VariableClBuilderLinuxDatavars(ReadonlyVariable):
|
|
|
|
"""
|
|
|
|
Переменные дистрибутива
|
|
|
|
"""
|
|
|
|
def source_data(self):
|
|
|
|
image = self.Get('cl_builder_source')
|
|
|
|
image_fn = self.Get('cl_builder_source_filename')
|
|
|
|
return self.get_data(image, image_fn=image_fn)
|
|
|
|
|
|
|
|
def get_data(self, image, image_fn=None):
|
|
|
|
if image:
|
|
|
|
if isinstance(image, distr.ArchiveDistributive):
|
|
|
|
return DataVarsBuilderLinux.StageInformation(image_fn)
|
|
|
|
with image:
|
|
|
|
with ignore(DistributiveError):
|
|
|
|
distr_dn = image.getDirectory()
|
|
|
|
dvbl = DataVarsBuilderLinux(systemRoot=distr_dn)
|
|
|
|
dvbl.prepare_all()
|
|
|
|
return dvbl
|
|
|
|
else:
|
|
|
|
return ""
|
|
|
|
|
|
|
|
def target_data(self):
|
|
|
|
image = self.Get('cl_builder_target')
|
|
|
|
return self.get_data(image, image_fn=None)
|
|
|
|
|
|
|
|
def get(self):
|
|
|
|
"""Get by distroinfo or current info"""
|
|
|
|
if self.Get('cl_action') == 'create':
|
|
|
|
return self.source_data()
|
|
|
|
elif self.Get('cl_action') in ('break', 'restore', 'image'):
|
|
|
|
return self.target_data()
|
|
|
|
return ""
|
|
|
|
|
|
|
|
|
|
|
|
class VariableOsBuilderLinuxShortname(BuilderLinux):
|
|
|
|
"""Shortname of system"""
|
|
|
|
variable = "os_linux_shortname"
|
|
|
|
|
|
|
|
|
|
|
|
class VariableOsBuilderLinuxVer(BuilderLinux):
|
|
|
|
"""Shortname of system"""
|
|
|
|
variable = "os_linux_ver"
|
|
|
|
|
|
|
|
def init(self):
|
|
|
|
self.label = _("Building system version")
|
|
|
|
|
|
|
|
class VariableOsBuilderLinuxBuild(BuilderLinux):
|
|
|
|
"""Shortname of system"""
|
|
|
|
variable = "os_linux_build"
|
|
|
|
|
|
|
|
def get(self):
|
|
|
|
action = self.Get('cl_action')
|
|
|
|
if action == 'image':
|
|
|
|
curdate = datetime.datetime.now()
|
|
|
|
return "%04d%02d%02d" % (curdate.year, curdate.month, curdate.day)
|
|
|
|
else:
|
|
|
|
return BuilderLinux.get(self)
|
|
|
|
|
|
|
|
|
|
|
|
class VariableOsBuilderArchMachine(BuilderLinux):
|
|
|
|
"""Shortname of system"""
|
|
|
|
variable = "os_arch_machine"
|
|
|
|
|
|
|
|
|
|
|
|
class VariableOsBuilderLinuxFiles(BuilderLinux):
|
|
|
|
"""Shortname of system"""
|
|
|
|
variable = "os_linux_files"
|
|
|
|
|
|
|
|
|
|
|
|
class VariableOsBuilderLinuxName(BuilderLinux):
|
|
|
|
"""
|
|
|
|
Install distro name
|
|
|
|
"""
|
|
|
|
variable = "os_linux_name"
|
|
|
|
|
|
|
|
|
|
|
|
class VariableOsBuilderLinuxSystem(BuilderLinux):
|
|
|
|
"""
|
|
|
|
Install system name
|
|
|
|
"""
|
|
|
|
variable = "os_linux_system"
|
|
|
|
|
|
|
|
|
|
|
|
class VariableOsBuilderLinuxSubname(BuilderLinux):
|
|
|
|
"""
|
|
|
|
Install subname
|
|
|
|
"""
|
|
|
|
variable = "os_linux_subname"
|