From 8c4598a532991424eba401d8b7711ea8b45c27f3 Mon Sep 17 00:00:00 2001 From: Joshua Lock Date: Sat, 30 Jul 2011 12:19:15 -0700 Subject: hob: remove temporary directory on program shutdown Move temp directory handling into the HobEventHandler and clean up the temporary files on program close. Fixes [YOCTO #1307] (Bitbake rev: 1009ca570a750a00b0e60afcc30ead070c7b310a) Signed-off-by: Joshua Lock Signed-off-by: Richard Purdie --- bitbake/lib/bb/ui/crumbs/hobeventhandler.py | 26 +++++++++++++++++++++----- bitbake/lib/bb/ui/hob.py | 15 +++++++-------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/bitbake/lib/bb/ui/crumbs/hobeventhandler.py b/bitbake/lib/bb/ui/crumbs/hobeventhandler.py index 0b5b31808c..e8265f1136 100644 --- a/bitbake/lib/bb/ui/crumbs/hobeventhandler.py +++ b/bitbake/lib/bb/ui/crumbs/hobeventhandler.py @@ -20,6 +20,8 @@ import gobject import logging +import tempfile +import datetime progress_total = 0 @@ -75,6 +77,7 @@ class HobHandler(gobject.GObject): self.generating = False self.build_queue = [] self.current_phase = None + self.image_dir = None self.model = taskmodel self.server = server @@ -237,7 +240,7 @@ class HobHandler(gobject.GObject): pmake = "-j %s" % threads self.server.runCommand(["setVariable", "BB_NUMBER_THREADS", pmake]) - def build_image(self, image, image_path, configurator): + def build_image(self, image, configurator): targets = [] targets.append(image) if self.build_toolchain and self.build_toolchain_headers: @@ -248,24 +251,24 @@ class HobHandler(gobject.GObject): bbpath_ok = False bbpath = self.server.runCommand(["getVariable", "BBPATH"]) - if image_path in bbpath.split(":"): + if self.image_dir in bbpath.split(":"): bbpath_ok = True bbfiles_ok = False bbfiles = self.server.runCommand(["getVariable", "BBFILES"]).split(" ") for files in bbfiles: import re - pattern = "%s/\*.bb" % image_path + pattern = "%s/\*.bb" % self.image_dir if re.match(pattern, files): bbfiles_ok = True if not bbpath_ok: - nbbp = image_path + nbbp = self.image_dir else: nbbp = None if not bbfiles_ok: - nbbf = "%s/*.bb" % image_path + nbbf = "%s/*.bb" % self.image_dir else: nbbf = None @@ -319,3 +322,16 @@ class HobHandler(gobject.GObject): def get_image_deploy_dir(self): return self.server.runCommand(["getVariable", "DEPLOY_DIR_IMAGE"]) + + def make_temp_dir(self): + self.image_dir = os.path.join(tempfile.gettempdir(), 'hob-images') + bb.utils.mkdirhier(self.image_dir) + + def remove_temp_dir(self): + bb.utils.remove(self.image_dir, True) + + def get_temp_recipe_path(self, name): + timestamp = datetime.date.today().isoformat() + image_file = "hob-%s-variant-%s.bb" % (name, timestamp) + recipepath = os.path.join(self.image_dir, image_file) + return recipepath diff --git a/bitbake/lib/bb/ui/hob.py b/bitbake/lib/bb/ui/hob.py index 919c06e151..b5c2342ce2 100644 --- a/bitbake/lib/bb/ui/hob.py +++ b/bitbake/lib/bb/ui/hob.py @@ -114,6 +114,8 @@ class MainWindow (gtk.Window): # whilst the busy cursor is set self.set_busy_cursor(False) + self.handler.remove_temp_dir() + gtk.main_quit() """ @@ -418,13 +420,10 @@ class MainWindow (gtk.Window): rep.base_image = "empty" if build_image: - import tempfile, datetime - - image_name = "hob-%s-variant-%s" % (rep.base_image, datetime.date.today().isoformat()) - image_file = "%s.bb" % (image_name) - image_dir = os.path.join(tempfile.gettempdir(), 'hob-images') - bb.utils.mkdirhier(image_dir) - recipepath = os.path.join(image_dir, image_file) + self.handler.make_temp_dir() + recipepath = self.handler.get_temp_recipe_path(rep.base_image) + image_name = recipepath.rstrip(".bb") + path, sep, image_name = image_name.rpartition("/") rep.writeRecipe(recipepath, self.model) # In the case where we saved the file for the purpose of building @@ -433,7 +432,7 @@ class MainWindow (gtk.Window): if not self.save_path: self.files_to_clean.append(recipepath) - self.handler.build_image(image_name, image_dir, self.configurator) + self.handler.build_image(image_name, self.configurator) else: self.handler.build_packages(rep.allpkgs.split(" ")) -- cgit v1.2.3-54-g00ecf