Запаковка образа новыми утилитами

develop
Mike Hiretsky 10 years ago
parent d28cf22e17
commit ca59346b85

@ -183,7 +183,7 @@ class cl_builder(color_print):
def _getCommand(self,commandlist):
return " ".join(map(lambda x:'"%s"'%x if " " in x else x,commandlist))
def runChroot(self,chroot,command):
def runChroot(self,chroot,command, stderr=STDOUT, stdout=PIPE):
"""Run command in chroot specified by cl_assemble_path"""
try:
envdict = {'CHROOT':"on"}
@ -194,8 +194,8 @@ class cl_builder(color_print):
self.clVars.Get('os_arch_machine') and \
self.clVars.Get('os_arch_machine') == 'x86_64':
commandLine = ["linux32"]+commandLine
chrootCommand = process(*commandLine,stderr=STDOUT,
stdout=PIPE,envdict=envdict)
chrootCommand = process(*commandLine,stderr=stderr,
stdout=stdout,envdict=envdict)
except KeyboardInterrupt:
chrootCommand.kill()
raise BuilderError(
@ -254,9 +254,22 @@ class cl_builder(color_print):
def updatePortage(self,builderPath):
"""Change branch to master and update portage"""
return True
if self.assembleIso:
assembleCalculateEnv = path.join(builderPath,
"etc/calculate/calculate.env")
envData = iniParser(assembleCalculateEnv)
branch_orig = self.clVars.Get('cl_builder_branch_orig')
if branch_orig:
envData.setVar('update',
{'cl_update_branch_name':branch_orig})
else:
envData.delVar('update','cl_update_branch_name')
eixSync = self.runChroot(builderPath,"eix-sync", stderr=None,
stdout=None)
eixSync.success()
return True
# restore resolv conf if needed
resolvFile = "etc/resolv.conf"
if not path.exists(path.join(builderPath,resolvFile)):
@ -349,19 +362,26 @@ class cl_builder(color_print):
self.applyTemplatesForSquash(distrPath)
# change make.profile
curProfileFile = pathJoin(mp,"etc/make.profile")
self.curProfile = os.readlink(curProfileFile)
profile = self.clVars.Get('os_builder_profile')
newProfile = None
if not self.curProfile.endswith(profile):
if profile.startswith("calculate"):
newProfile = path.join("../var/lib/layman/calculate/profiles",
profile)
else:
newProfile = path.join("../usr/portage/profiles",
profile)
os.unlink(curProfileFile)
os.symlink(newProfile,curProfileFile)
#for profile in ('etc/portage/make.profile',
# 'etc/make.profile'):
# profile = path.join(mp, profile)
# if path.exists(profile):
# curProfileFile = pathJoin(mp,"etc/make.profile")
# break
#else:
# raise BuilderError(_("Failed to detect system profile %s")%target)
#self.curProfile = os.readlink(curProfileFile)
#profile = self.clVars.Get('os_builder_profile')
#newProfile = None
#if not self.curProfile.endswith(profile):
# if profile.startswith("calculate"):
# newProfile = path.join("../var/lib/layman/calculate/profiles",
# profile)
# else:
# newProfile = path.join("../usr/portage/profiles",
# profile)
# os.unlink(curProfileFile)
# os.symlink(newProfile,curProfileFile)
def restoreProfile(self):
"""Restore profile"""
@ -448,9 +468,15 @@ class cl_builder(color_print):
return False
return True
def __profileShortname(self,profilename):
return profilename.rpartition('/profiles/')[2]
def printInfo(self):
self.printSUCCESS(_("Creating an image of") + " Calculate Linux")
self.defaultPrint("%s\n"%_("System information"))
self.printSUCCESS(_("System profile")+": %s"%
self.__profileShortname(
self.clVars.Get('os_builder_profile')))
subname = self.clVars.Get('os_builder_linux_subname')
subname = (" %s"%subname) if subname else ""
self.printSUCCESS(_("System to be built")+": %s"%
@ -607,8 +633,11 @@ class cl_builder(color_print):
if not self.checkVariables():
return False
excludeList = self._excludeList(sourceDirectory)
volid = "%s-%s"%(self.clVars.Get('os_builder_linux_shortname'),
self.clVars.Get('os_builder_linux_build'))
self.targetDistr = IsoDistributive(isoFile,bdirectory=buildDirectory,
exclude=excludeList,
volid=volid,
compress=self.compression)
self.sourceDistr = DirectoryDistributive(sourceDirectory,
mdirectory=bindDirectory)
@ -770,7 +799,7 @@ class cl_builder(color_print):
self.printByResult(True)
if self.assembleIso:
self.restoreMount()
self.restoreProfile()
#self.restoreProfile()
except (BuilderError,DistributiveError),e:
error = "%s\n%s" % (str(error),_("Unmounting error"))
except KeyboardInterrupt,e:
@ -785,7 +814,7 @@ class cl_builder(color_print):
self.printSUCCESS(_("System built successfully"))
if self.assembleIso:
os.system("cl-make -p %s -fT &>/dev/null"%
self.clVars.Get('os_builder_profile'))
self.clVars.Get('os_builder_id'))
return True
def restoreMount(self):
@ -813,41 +842,41 @@ class cl_builder(color_print):
{'from':source,'to':target})
self.printByResult(True)
def setAssembleData(self,newprofile,printVars=None):
def setAssembleData(self,new_id,printVars=None):
"""Get assemble data from assemble.env"""
envData = iniParser(self.envFile)
if newprofile == None:
if new_id == None:
distros = self.clVars.Get('cl_builder_distro')
if len(distros) == 1:
newprofile = distros[0]
newprofile = newprofile or ""
# if $ at end of newprofile then it be at end of profile name
if newprofile.endswith("$"):
newprofile = newprofile[:-1]
new_id = distros[0]
new_id = new_id or ""
# if $ at end of new_id then it be at end of profile name
if new_id.endswith("$"):
new_id = new_id[:-1]
reProfile = re.compile('(^|/)%s$'%
"/([^/]+/)*".join(newprofile.strip('/').split('/')),re.S|re.I)
"/([^/]+/)*".join(new_id.strip('/').split('/')),re.S|re.I)
else:
reProfile = re.compile('(^|/)%s(/|$)'%
"/([^/]+/)*".join(newprofile.strip('/').split('/')),re.S|re.I)
"/([^/]+/)*".join(new_id.strip('/').split('/')),re.S|re.I)
likeProfile = filter(reProfile.search,
self.clVars.Get('cl_builder_distro'))
if len(likeProfile) != 1:
if printVars:
return True
if newprofile != "list":
if not newprofile:
self.printERROR(_("need specify '--profile'"))
if new_id != "list":
if not new_id:
self.printERROR(_("need specify '--id'"))
return False
elif not likeProfile:
self.printERROR(_("wrong value for '--profile'"))
self.printERROR(_("wrong value for '--id'"))
self.printERROR(
_("specify '-p list' to print all available "
"distributions to be built"))
return False
else:
self.printERROR(
_("specified value of '--profile' is ambiguous. "
"Please specify profile with more precision."))
_("specified value of '--id' is ambiguous. "
"Please specify ID with more precision."))
self.defaultPrint(_("Select a profile from")+":\n")
else:
likeProfile = self.clVars.Get('cl_builder_distro')
@ -856,16 +885,13 @@ class cl_builder(color_print):
for profile in likeProfile:
self.printSUCCESS(profile)
return False
newprofile = likeProfile[0]
self.clVars.Set('os_builder_profile', newprofile, True)
new_id = likeProfile[0]
self.clVars.Set('os_builder_id', new_id, True)
self.assembleIso = True
self.clVars.Set('cl_builder_path', _toUNICODE(envData.getVar(newprofile,
self.clVars.Set('cl_builder_path', _toUNICODE(envData.getVar(new_id,
'cl_assemble_path')).encode('utf-8'),True)
linuxver = _toUNICODE(envData.getVar(newprofile,
'os_assemble_linux_ver')).encode('utf-8')
if linuxver:
self.clVars.Set('os_builder_linux_ver',linuxver ,True)
self.clVars.Set('os_builder_linux_build','',True)
self.clVars.Set('cl_builder_branch_orig', _toUNICODE(envData.getVar(new_id,
'cl_assemble_branch_orig')).encode('utf-8'),True)
return True
def createPackageList(self,chrootdir,filename):

@ -29,6 +29,7 @@ from types import ListType
from cl_datavars import iniParser
from cl_vars import Data as libData
from datetime import datetime
from tools import SimpleDataVars, SimpleVariable, ArchVariable, ProfileVariable
class fillVars(object, varsShare):
@ -221,8 +222,7 @@ class fillVars(object, varsShare):
return self.getInitrd(archmachine,
shortname,
self.Get('cl_builder_path'),
kernelname,
suffix="install") or ""
kernelname) or ""
def get_cl_builder_kernel_config(self):
kernelname = self.Get('cl_builder_kernel')
@ -260,21 +260,41 @@ class fillVars(object, varsShare):
def get_os_builder_linux_name(self):
"""Build system name"""
linuxShortName = self.Get("os_builder_linux_shortname")
return self.dictLinuxName.get(linuxShortName,"Linux")
return self.Get('cl_builder_linux_info').get('os_linux_name')
def get_os_builder_linux_subname(self):
"""Build system subname"""
linuxShortName = self.Get("os_builder_linux_shortname")
return self.dictLinuxSubName.get(linuxShortName,"")
return self.Get('cl_builder_linux_info').get('os_linux_subname')
def get_os_builder_linux_shortname(self):
"""Build system shortname"""
systemRoot = self.Get('cl_builder_path')
return self.getShortnameByMakeprofile(systemRoot) or \
self.getShortnameByIni(systemRoot) or \
self.detectOtherShortname(systemRoot) or \
"Linux"
return self.Get('cl_builder_linux_info').get('os_linux_shortname')
def get_cl_builder_linux_info(self):
builder_path = self.Get('cl_builder_path')
sdv = SimpleDataVars(
SimpleVariable('os_linux_name'),
SimpleVariable('os_linux_ver'),
SimpleVariable('os_linux_shortname'),
SimpleVariable('os_linux_system'),
SimpleVariable('os_linux_subname'),
SimpleVariable('cl_update_rep_url',section='update', type="list"),
SimpleVariable('cl_update_rep_name',section='update', type="list"),
SimpleVariable('os_linux_subname'),
ArchVariable('os_arch_machine',
prefix=builder_path),
ProfileVariable('os_system_profile',
prefix=builder_path),
)
for profile in ('etc/portage/make.profile',
'etc/make.profile'):
profile = path.join(builder_path, profile)
if path.exists(profile):
sdv.flIniFileFrom(profile)
sdv.Get('os_arch_machine')
sdv.Get('os_system_profile')
return {x:sdv.Get(x) for x in sdv.allVars}
return {}
def get_os_builder_linux_filesnum(self):
"""Files number in image system"""
@ -296,6 +316,9 @@ class fillVars(object, varsShare):
systemRoot = self.Get('cl_builder_path')
return str(countFiles(systemRoot)-excludeCount)
def get_os_builder_profile(self):
return self.Get('cl_builder_linux_info').get('os_system_profile') or ""
def getVersionFromCalculateEnv(self,systemroot):
"""Get version from calculate ini"""
pathname = path.join(systemroot,
@ -317,23 +340,15 @@ class fillVars(object, varsShare):
def get_os_builder_linux_ver(self):
"""Build system ver"""
linuxShortName = self.Get("os_builder_linux_shortname")
rootSystem = self.Get('cl_builder_path')
return self.getVersionFromMetapackage(rootSystem,linuxShortName) or \
self.getVersionFromCalculateEnv(rootSystem) or \
self.getVersionFromCalculateIni(rootSystem) or \
self.getVersionFromGentooFiles(rootSystem) or "0"
return self.Get('cl_builder_linux_info').get('os_linux_ver')
def get_os_builder_arch_machine(self):
"""Build system arch"""
rootSystem = self.Get('cl_builder_path')
lib64path = path.join(rootSystem,"lib64")
return 'x86_64' if path.lexists(lib64path) else "i686"
return self.Get('cl_builder_linux_info').get('os_arch_machine')
def get_os_builder_linux_system(self):
"""Build linux system type"""
shortName = self.Get('os_builder_linux_shortname')
return self.dictNameSystem.get(shortName,"")
return self.Get('cl_builder_linux_info').get('os_linux_system')
def get_cl_builder_cdname(self):
"""Cd size specified by name (DVD/CD)"""
@ -446,9 +461,9 @@ class fillVars(object, varsShare):
imagePath = ['/var/calculate/linux',
'/var/calculate/remote/linux',
'/usr/calculate/share/linux']
if self.Get('os_builder_profile'):
if self.Get('cl_builder_assemble_set') == 'on':
imagePath.insert(0,path.join("/var/calculate/remote/assemble",
self.Get('os_builder_profile').replace('/','-'),
self.Get('os_builder_id').replace('/','-'),
"linux"))
return imagePath
@ -466,3 +481,9 @@ class fillVars(object, varsShare):
suffix = "calculate=lang:%s,keymap:%s" % (lang,lang)
print suffix
return suffix
def get_cl_builder_assemble_set(self):
if self.Get('cl_builder_distro') \
and self.Get('cl_builder_path'):
return "on"
return "off"

@ -36,9 +36,9 @@ DEFAULT_COMPRESS="xz" if "xz" in COMPRESS_METHODS else "gzip"
DESCRIPTION = _("Calculate Linux image builder")
CMD_OPTIONS = [{'shortOption':"p",
'longOption':"profile",
'optVal':"PROFILE",
'help':_("system profile")
'longOption':"id",
'optVal':"ID",
'help':_("assemble id")
},
{'longOption':"compress",
'optVal':"COMPRESS",
@ -103,7 +103,7 @@ class image_cmd(share_cmd):
def __sectionName(self):
"""Get section name of assemble.env by shortname and arch"""
return self.logicObj.clVars.Get('os_builder_profile')
return self.logicObj.clVars.Get('os_builder_id')
def isScratch(self,showError=True):
"""Detect scartch system"""

@ -150,12 +150,22 @@ class Data:
os_builder_profile = {}
# assemble id
os_builder_id = {}
# информация о собираемом образе
cl_builder_linux_info = {}
cl_builder_assemble_set = {}
# count of files and directories in distributive
cl_builder_filesnum = {}
# path which contains images
cl_builder_image_path = {}
cl_builder_branch_orig = {}
cl_builder_live_set = {'value':'off'}
os_builder_locale_lang = {'mode':'w','value':''}

Loading…
Cancel
Save