From 1fa4e0d09b826c2409aed1ff3e8c6ce348e6a1e7 Mon Sep 17 00:00:00 2001 From: Mike Hiretsky Date: Mon, 1 Nov 2010 18:32:15 +0300 Subject: [PATCH] Add calculate package list and digest. --- i18n/cl_builder_ru.mo | Bin 11832 -> 12031 bytes pym/cl_builder.py | 51 ++++++++++++++++++++++++++++++++++++++--- pym/cl_fill_builder.py | 17 +++++++++++++- pym/cl_image_cmd.py | 8 ++----- pym/cl_vars_builder.py | 6 +++++ 5 files changed, 72 insertions(+), 10 deletions(-) diff --git a/i18n/cl_builder_ru.mo b/i18n/cl_builder_ru.mo index 8cb38be5da7749ef5703557ae64c8add5eb6b2b3..c58ed19f55f1b0e1e90f6137e4c1b50284639169 100644 GIT binary patch delta 2390 zcmY+_e@srU53{ZW53S!-P(rif(C>1zldd@k|InQ&x z&+}X^w*A{4yqOwz#!z~QbwqQlF|Xq5D>zWXD~(CV^LRhbV+P*FLi8jUlY*7F6B}_e zhVWke6n*#&T6o*ln`q2>V}hoDiW=_6EF8eqIEog&hedc5^YAa%?4;<6>rw3ksOJYU z6+`a*_pyNU%lH5;y7yC)^YI?lV*eH&7W$=4L+Tp)z^^m7!r&KW}0V&Y&{$QyTeK!+73iVGiDdwWt?&pi+4T zdB#kkg)4BX z8FnGgU;!>-C0ZA+W||5+#{7)R#1ihoN|x#{zJWCu&)bWz0rh1gSdDYY1~49$I8BX( zN3a&#FpS!k9@0WnQ;OPEhcLLG%4sV4f?x0z%%=4tcn+&{9UsG7HnlqJ!<~2@m6;{f z8p&Zkw&4(t;s?k_n+kf{f&qLHN0CR2XAAk)7j5Tm3m!wwIf|= z-s5zjg{PvA(erzWeS`+5HBmySXmBLg*?P(Ns5WIH70t6n>>1cPA$4}RE=}b z6Hv>UUo>a``BB@X-tZQ!4mNc3w-8xK=4m3EP{|^+avF()gqHImLS-$n%&A3xthL8f z(upcUEA!#WQ!77OmRwy|Thr9sWF0=**B#oJl;P_i918UHb$3|w(hl3x_DpEhzb4e>&)gOnv9H({IbO2ER^;W#NaO@9X6;Yx346w#qBa|O yEpp1DRhTwY+~(HgfIm0ZJ7Gm$;_3zaV;a&p6!H5)aas8>6QQw8|72WNams(vy%t^o delta 2245 zcmYk+ZEO@p9LMqhaitGj5!$m@`gB)X#R|oi7OBw6wbwhIM5?DCm0BwnAHWDUDm8{J zMv00s;E4eejfPMYgHm#dsTJ)TBY`))#-Ir?H6*-&M1#IkVp6}q-6iRy|9)n7=XPfP zGqck@quZUS;+&&K=_e|P&Y;=5xI34Bl*9REWq1S^;c2YI30#hU;5>{Lm~~(SF2w;X z#m}$=zr`p{_};)f%^WM5<277~5gK%15$-|#;7x48lURqp`UXN?yCqo6{WerbUD${_ zu?CO%&(EPIGJ%@FbzDgQmS5=oa1mDXpas>S8#B-isxyqdH2UGWaasjYm)e87m_H>hJ2)1;U>6?3cKi*Sv5IxnfKynFdr=v2(o{B48O2u2 zC9is693RFPaTSi^{df~Kz-Hd2`#W(9e(qoYg9)yi$g|!%=zAWQa$Q1t_5Kb|$97ZE zNIu5(_#G-mv!mV*>TosJTad}xho~2vMrGs|`8`ktP;k^xLo&pU`t;HSIELpnoF= z!YUZ$My$sNaS#XT-+rQ!z!<}A!h@)pjbSGS=#>p_N#vGo!{=}ax8pU`F-)@MsoGxD zDLRf@@jPk*5k_+myRi+gpwq4g{5p<(s18qI2VO^Irk=yCwd}?F@GCrwSCPrtD=h3X zJb`cE1>}(>8HFbFGCqdGsHOZ51GrA#f2Cq((T8Cz@hG8}D8(xY6}?28a1*ha(0VJ? z>O@8B%c{5=w-B|?a|o@!&iw{L8DxBJM(cFgl?oLGEi4c1VN8h+g7W znMD*0BHp diff --git a/pym/cl_builder.py b/pym/cl_builder.py index 95a0fd7..7e3cec2 100644 --- a/pym/cl_builder.py +++ b/pym/cl_builder.py @@ -38,6 +38,7 @@ from cl_kernel_utils import KernelConfig,InitRamFs from server.utils import dialogYesNo import cl_overriding +import hashlib from cl_lang import lang lang().setLanguage(sys.modules[__name__]) @@ -89,6 +90,7 @@ class cl_builder(color_print): self.clTempl = None self.force = False self.assembleIso = False + self.envFile = '/etc/calculate/assemble.env' def setNoColor(self): self.color = False @@ -325,6 +327,10 @@ class cl_builder(color_print): self.printMessageForTest(_("Creating squash image")) self.targetDistr.installFrom(self.sourceDistr) self.printByResult(True) + self.printMessageForTest(_("Creating installed package list")) + self.printByResult(self.createPackageList(sourceDirectory,isoFile+".list")) + self.printMessageForTest(_("Creating DIGESTS file")) + self.printByResult(self.createDigest(isoFile,isoFile+".DIGESTS")) #self.targetDistr = PartitionDistributive(rootPartdev,flagRemoveDir=False) #dd = DirectoryDistributive(mp,parent=self.targetDistr) @@ -469,13 +475,26 @@ class cl_builder(color_print): {'from':source,'to':target}) self.printByResult(True) - def setAssembleData(self): + def setAssembleData(self,shortname,march): """Get assemble data from assemble.env""" + envData = iniParser(self.envFile) + if shortname == None and march == None: + distros = self.clVars.Get('cl_builder_distro') + if len(distros) == 1: + section = distros[0].split(',') + var = 'os_assemble_linux_shortname' + shortname = \ + _toUNICODE(envData.getVar(section,var)).encode('utf-8') + var = 'os_assemble_arch_machine' + march = \ + _toUNICODE(envData.getVar(section,var)).encode('utf-8') + if shortname: + self.clVars.Set('os_builder_linux_shortname',shortname,True) + if march: + self.clVars.Set('os_builder_arch_machine',march,True) self.assembleIso = True section = (self.clVars.Get('os_builder_linux_shortname'), self.clVars.Get('os_builder_arch_machine')) - envFile = '/etc/calculate/assemble.env' - envData = iniParser(envFile) self.clVars.Set('cl_builder_path', _toUNICODE(envData.getVar(section, 'cl_assemble_path')).encode('utf-8'),True) linuxver = _toUNICODE(envData.getVar(section, @@ -484,3 +503,29 @@ class cl_builder(color_print): curdate = datetime.now() linuxver = "%04d%02d%02d"%(curdate.year,curdate.month,curdate.day) self.clVars.Set('os_builder_linux_ver',linuxver ,True) + + def createPackageList(self,chrootdir,filename): + """Create package list by chrootdir""" + pkgdir = path.join(chrootdir,'var/db/pkg') + if not path.exists(chrootdir): + return False + try: + packageList = sorted(reduce(lambda x,y:x+map(lambda x:path.join(y,x), + os.listdir(path.join(pkgdir,y))), os.listdir(pkgdir),[])) + open(filename,'w').writelines(packageList) + except (IOError,OSError),e: + return False + return True + + def createDigest(self,filename,digestfile): + """Create file with digest""" + template = """# %(alg)s HASH\n%(digest)s %(filename)s\n""" + try: + open(digestfile,'w').writelines(map(lambda x:template%{ + 'alg':x.upper(), + 'digest': \ + getattr(hashlib,x)(open(filename,'r').read()).hexdigest(), + 'filename':path.basename(filename)},["md5","sha1"])) + except (IOError,OSError),e: + return False + return True diff --git a/pym/cl_fill_builder.py b/pym/cl_fill_builder.py index 42886a5..da18a7e 100644 --- a/pym/cl_fill_builder.py +++ b/pym/cl_fill_builder.py @@ -22,7 +22,8 @@ from cl_kernel import cl_kernel from os import access, R_OK,W_OK from os import path from cl_distr import Distributive -from cl_utils import getTupleVersion,genpassword,pathJoin +from cl_utils import getTupleVersion,genpassword,pathJoin,_toUNICODE, \ + getFilesCount from operator import itemgetter from types import ListType from cl_datavars import iniParser @@ -284,3 +285,17 @@ class fillVars(object, varsShare): 'ver':self.Get('os_builder_linux_ver'), 'march':self.Get('os_builder_arch_machine')}) return "" + + def get_cl_builder_distro(self): + """Current assembling systems""" + envFile = '/etc/calculate/assemble.env' + envData = iniParser(envFile) + return filter(lambda x:envData.getVar(x.split(','), + 'os_assemble_root_dev'), + map(lambda x:_toUNICODE(x).encode('utf-8'), + envData.getAllSectionNames())) + + def get_cl_builder_filesnum(self): + """Get files num in assembled distro""" + #getFilesCount(self.Get('cl_builder_path')) + return "0" diff --git a/pym/cl_image_cmd.py b/pym/cl_image_cmd.py index 42604e7..a4fc37e 100644 --- a/pym/cl_image_cmd.py +++ b/pym/cl_image_cmd.py @@ -122,17 +122,13 @@ class image_cmd(share_cmd): if values.s: if self.isScratch(False): self.optobj.error(_("'-s' not used in scratch mode")) - self.logicObj.clVars.Set('os_builder_linux_shortname', - values.s.upper(),True) if values.march: if self.isScratch(False): self.optobj.error(_("'--march' not used in scratch mode")) - self.logicObj.clVars.Set('os_builder_arch_machine', - values.march.lower(),True) if not self.isScratch(False) \ - and path.exists(self.envFile): - self.logicObj.setAssembleData() + and self.logicObj.clVars.Get('cl_builder_distro'): + self.logicObj.setAssembleData(values.s,values.march) if args and args[0] == "squash": self.logicObj.clVars.Set('cl_builder_iso_path','/mnt/flash',True) diff --git a/pym/cl_vars_builder.py b/pym/cl_vars_builder.py index 0f72e51..4556945 100644 --- a/pym/cl_vars_builder.py +++ b/pym/cl_vars_builder.py @@ -118,6 +118,12 @@ class Data: # iso image full path cl_builder_image = {} + # distro created by assemble + cl_builder_distro = {} + + # count of files and directories in distributive + cl_builder_filesnum = {} + # path which contains images cl_builder_image_path = {'mode':'w', 'value':['/var/calculate/linux',