diff options
author | Joshua Lock <josh@linux.intel.com> | 2011-08-10 18:07:23 -0700 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2011-08-12 21:07:00 +0100 |
commit | b829654a5a72840013f0929d2574e0a6bb6d8533 (patch) | |
tree | 9561174142e394e9c4c250c7c4fb00964f322349 /bitbake/lib/bb | |
parent | fdcf262672788e82d19a607298407330b947206f (diff) | |
download | ast2050-yocto-poky-b829654a5a72840013f0929d2574e0a6bb6d8533.zip ast2050-yocto-poky-b829654a5a72840013f0929d2574e0a6bb6d8533.tar.gz |
bb/ui/crumbs/configurator: introduce writeConfFile method for all writes
Configuration files are written in several places, this refactors the code
to use a common method.
(Bitbake rev: 2843645755abb736220d7404dc6e853929093ff9)
Signed-off-by: Joshua Lock <josh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb')
-rw-r--r-- | bitbake/lib/bb/ui/crumbs/configurator.py | 46 |
1 files changed, 19 insertions, 27 deletions
diff --git a/bitbake/lib/bb/ui/crumbs/configurator.py b/bitbake/lib/bb/ui/crumbs/configurator.py index e17d555..c37e917 100644 --- a/bitbake/lib/bb/ui/crumbs/configurator.py +++ b/bitbake/lib/bb/ui/crumbs/configurator.py @@ -207,6 +207,19 @@ class Configurator(gobject.GObject): return "".join(layer_entry) + def writeConfFile(self, conffile, contents): + """ + Make a backup copy of conffile and write a new file in its stead with + the lines in the contents list. + """ + # Create a backup of the conf file + bkup = "%s~" % conffile + os.rename(conffile, bkup) + + # Write the contents list object to the conf file + with open(conffile, "w") as new: + new.write("".join(contents)) + def writeLocalConf(self): # Dictionary containing only new or modified variables changed_values = {} @@ -218,12 +231,8 @@ class Configurator(gobject.GObject): if not len(changed_values): return - # Create a backup of the local.conf - bkup = "%s~" % self.local - os.rename(self.local, bkup) - # read the original conf into a list - with open(bkup, 'r') as config: + with open(self.local, 'r') as config: config_lines = config.readlines() new_config_lines = ["\n"] @@ -259,20 +268,14 @@ class Configurator(gobject.GObject): # Add the modified variables config_lines.extend(new_config_lines) - # Write the updated lines list object to the local.conf - with open(self.local, "w") as n: - n.write("".join(config_lines)) + self.writeConfFile(self.local, config_lines) del self.orig_config self.orig_config = copy.deepcopy(self.config) def insertTempBBPath(self, bbpath, bbfiles): - # Create a backup of the local.conf - bkup = "%s~" % self.local - os.rename(self.local, bkup) - # read the original conf into a list - with open(bkup, 'r') as config: + with open(self.local, 'r') as config: config_lines = config.readlines() if bbpath: @@ -280,9 +283,7 @@ class Configurator(gobject.GObject): if bbfiles: config_lines.append("BBFILES := \"${BBFILES} %s\"\n" % bbfiles) - # Write the updated lines list object to the local.conf - with open(self.local, "w") as n: - n.write("".join(config_lines)) + self.writeConfFile(self.local, config_lines) def writeLayerConf(self): # If we've not added/removed new layers don't write @@ -292,23 +293,14 @@ class Configurator(gobject.GObject): # This pattern should find the existing BBLAYERS pattern = 'BBLAYERS\s=\s\".*\"' - # Backup the users bblayers.conf - bkup = "%s~" % self.bblayers - os.rename(self.bblayers, bkup) - replacement = self._constructLayerEntry() - with open(bkup, "r") as f: + with open(self.bblayers, "r") as f: contents = f.read() p = re.compile(pattern, re.DOTALL) new = p.sub(replacement, contents) - with open(self.bblayers, "w") as n: - n.write(new) - - # At some stage we should remove the backup we've created - # though we should probably verify it first - #os.remove(bkup) + self.writeConfFile(self.bblayers, new) # set loaded_layers for dirtiness tracking self.loaded_layers = copy.deepcopy(self.enabled_layers) |