From ac1e7669045a711b298fecbc2766966667dfb380 Mon Sep 17 00:00:00 2001 From: Mike Hiretsky Date: Wed, 29 Sep 2010 12:50:18 +0400 Subject: [PATCH] Added display free disk information. Add removing old squash images. --- pym/cl_builder.py | 38 +++++++++++++++++++++++++++++++++++--- pym/cl_image_cmd.py | 3 ++- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/pym/cl_builder.py b/pym/cl_builder.py index f48ec91..4776dc3 100644 --- a/pym/cl_builder.py +++ b/pym/cl_builder.py @@ -173,6 +173,16 @@ class cl_builder(color_print): self.sourceDistr.close() self.sourceDistr = None + def getFreeFor(self,pathname): + """Get free for pathname""" + dfProcess = process("/bin/df","-h",pathname) + data = filter(lambda x:x.startswith('/dev'),dfProcess) + if data: + data = filter(lambda x:x,data[0].split()) + if len(data)>3: + return data[3] + return "Unknown" + def printInfo(self): self.printSUCCESS(_("Creating image of") + " Calculate Linux") self.defaultPrint("%s\n"%_("System information")) @@ -184,11 +194,17 @@ class cl_builder(color_print): self.clVars.Get('os_builder_linux_ver')) self.printSUCCESS(_("Machine hardware name")+": %s"% self.clVars.Get('os_builder_arch_machine')) + self.printSUCCESS(_("Free disk space for iso building: %s")% + self.getFreeFor(path.dirname(path.normpath( + self.clVars.Get('cl_builder_iso_path'))))) + self.printSUCCESS(_("Free disk space for iso image: %s")% + self.getFreeFor(self.clVars.Get('cl_builder_image'))) self.defaultPrint("%s\n"%_("Perform pre-install checkups")) if self.clVars.Get('cl_builder_image'): self.printSUCCESS(_("Image will be created at: %s\n")% self.clVars.Get('cl_builder_image')) + else: self.printWARNING("No path for image creating.") @@ -205,8 +221,10 @@ class cl_builder(color_print): self.clVars.Get('os_builder_arch_machine')) self.defaultPrint("%s\n"%_("Perform pre-install checkups")) - self.printSUCCESS(_("Image will be created in: %s\n")% + self.printSUCCESS(_("Image will be created in: %s")% self.clVars.Get('cl_builder_iso_path')) + self.printSUCCESS(_("Follow squash images will be removed: %s\n")% + ", ".join(self.clVars.Get('cl_builder_remove_squash'))) def checkVariables(self,rescratch=False): """Check values of variables""" @@ -257,6 +275,7 @@ class cl_builder(color_print): def _rescratchLogic(self,force=False): self.clVars.Set('cl_builder_iso_path','/mnt/flash',True) + self.clVars.Get('cl_builder_remove_squash') buildDirectory = self.clVars.Get('cl_builder_iso_path') sourceDirectory = self.clVars.Get('cl_builder_path') bindDirectory = pathJoin(buildDirectory, @@ -281,6 +300,19 @@ class cl_builder(color_print): self.printMessageForTest(_("Creating squash image")) self.targetDistr.installFrom(self.sourceDistr) self.printByResult(True) + + self.printMessageForTest(_("Removing old images")) + oldImages = map(lambda x:pathJoin(buildDirectory,x), + self.clVars.Get('cl_builder_remove_squash')) + try: + map(lambda x:os.unlink(x),oldImages) + except (Exception,KeyboardInterrupt),e: + raise BuilderError(_("Can not remove old files")+":\n%s"%str(e)) + self.printByResult(True) + + self.printMessageForTest(_("Performing syncronization")) + processSync = process("/bin/sync") + self.printByResult(processSync.success()) return True def makeIsoImage(self,force=False): @@ -331,7 +363,7 @@ class cl_builder(color_print): if error: for line in filter(lambda x: x,str(error).split('\n')): self.printERROR(line) - self.printERROR(_("Iso building failed")) + self.printERROR(_("System building failed")) return False - self.printSUCCESS(_("Iso has built successfully")) + self.printSUCCESS(_("System has built successfully")) return True diff --git a/pym/cl_image_cmd.py b/pym/cl_image_cmd.py index 7ece301..a73c3e7 100644 --- a/pym/cl_image_cmd.py +++ b/pym/cl_image_cmd.py @@ -62,7 +62,8 @@ class image_cmd(share_cmd): if args: self.logicObj.clVars.Set('cl_action',args[0],True) - self.logicObj.clVars.Set('cl_builder_iso_path','/mnt/flash',True) + if args and args[0] == "squash": + self.logicObj.clVars.Set('cl_builder_iso_path','/mnt/flash',True) self.optobj.checkVarSyntax(values) return (values, args)