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/ui | |
| parent | fdcf262672788e82d19a607298407330b947206f (diff) | |
| download | 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/ui')
| -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 e17d5559ff..c37e9175ea 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): | |||
| 207 | 207 | ||
| 208 | return "".join(layer_entry) | 208 | return "".join(layer_entry) |
| 209 | 209 | ||
| 210 | def writeConfFile(self, conffile, contents): | ||
| 211 | """ | ||
| 212 | Make a backup copy of conffile and write a new file in its stead with | ||
| 213 | the lines in the contents list. | ||
| 214 | """ | ||
| 215 | # Create a backup of the conf file | ||
| 216 | bkup = "%s~" % conffile | ||
| 217 | os.rename(conffile, bkup) | ||
| 218 | |||
| 219 | # Write the contents list object to the conf file | ||
| 220 | with open(conffile, "w") as new: | ||
| 221 | new.write("".join(contents)) | ||
| 222 | |||
| 210 | def writeLocalConf(self): | 223 | def writeLocalConf(self): |
| 211 | # Dictionary containing only new or modified variables | 224 | # Dictionary containing only new or modified variables |
| 212 | changed_values = {} | 225 | changed_values = {} |
| @@ -218,12 +231,8 @@ class Configurator(gobject.GObject): | |||
| 218 | if not len(changed_values): | 231 | if not len(changed_values): |
| 219 | return | 232 | return |
| 220 | 233 | ||
| 221 | # Create a backup of the local.conf | ||
| 222 | bkup = "%s~" % self.local | ||
| 223 | os.rename(self.local, bkup) | ||
| 224 | |||
| 225 | # read the original conf into a list | 234 | # read the original conf into a list |
| 226 | with open(bkup, 'r') as config: | 235 | with open(self.local, 'r') as config: |
| 227 | config_lines = config.readlines() | 236 | config_lines = config.readlines() |
| 228 | 237 | ||
| 229 | new_config_lines = ["\n"] | 238 | new_config_lines = ["\n"] |
| @@ -259,20 +268,14 @@ class Configurator(gobject.GObject): | |||
| 259 | # Add the modified variables | 268 | # Add the modified variables |
| 260 | config_lines.extend(new_config_lines) | 269 | config_lines.extend(new_config_lines) |
| 261 | 270 | ||
| 262 | # Write the updated lines list object to the local.conf | 271 | self.writeConfFile(self.local, config_lines) |
| 263 | with open(self.local, "w") as n: | ||
| 264 | n.write("".join(config_lines)) | ||
| 265 | 272 | ||
| 266 | del self.orig_config | 273 | del self.orig_config |
| 267 | self.orig_config = copy.deepcopy(self.config) | 274 | self.orig_config = copy.deepcopy(self.config) |
| 268 | 275 | ||
| 269 | def insertTempBBPath(self, bbpath, bbfiles): | 276 | def insertTempBBPath(self, bbpath, bbfiles): |
| 270 | # Create a backup of the local.conf | ||
| 271 | bkup = "%s~" % self.local | ||
| 272 | os.rename(self.local, bkup) | ||
| 273 | |||
| 274 | # read the original conf into a list | 277 | # read the original conf into a list |
| 275 | with open(bkup, 'r') as config: | 278 | with open(self.local, 'r') as config: |
| 276 | config_lines = config.readlines() | 279 | config_lines = config.readlines() |
| 277 | 280 | ||
| 278 | if bbpath: | 281 | if bbpath: |
| @@ -280,9 +283,7 @@ class Configurator(gobject.GObject): | |||
| 280 | if bbfiles: | 283 | if bbfiles: |
| 281 | config_lines.append("BBFILES := \"${BBFILES} %s\"\n" % bbfiles) | 284 | config_lines.append("BBFILES := \"${BBFILES} %s\"\n" % bbfiles) |
| 282 | 285 | ||
| 283 | # Write the updated lines list object to the local.conf | 286 | self.writeConfFile(self.local, config_lines) |
| 284 | with open(self.local, "w") as n: | ||
| 285 | n.write("".join(config_lines)) | ||
| 286 | 287 | ||
| 287 | def writeLayerConf(self): | 288 | def writeLayerConf(self): |
| 288 | # If we've not added/removed new layers don't write | 289 | # If we've not added/removed new layers don't write |
| @@ -292,23 +293,14 @@ class Configurator(gobject.GObject): | |||
| 292 | # This pattern should find the existing BBLAYERS | 293 | # This pattern should find the existing BBLAYERS |
| 293 | pattern = 'BBLAYERS\s=\s\".*\"' | 294 | pattern = 'BBLAYERS\s=\s\".*\"' |
| 294 | 295 | ||
| 295 | # Backup the users bblayers.conf | ||
| 296 | bkup = "%s~" % self.bblayers | ||
| 297 | os.rename(self.bblayers, bkup) | ||
| 298 | |||
| 299 | replacement = self._constructLayerEntry() | 296 | replacement = self._constructLayerEntry() |
| 300 | 297 | ||
| 301 | with open(bkup, "r") as f: | 298 | with open(self.bblayers, "r") as f: |
| 302 | contents = f.read() | 299 | contents = f.read() |
| 303 | p = re.compile(pattern, re.DOTALL) | 300 | p = re.compile(pattern, re.DOTALL) |
| 304 | new = p.sub(replacement, contents) | 301 | new = p.sub(replacement, contents) |
| 305 | 302 | ||
| 306 | with open(self.bblayers, "w") as n: | 303 | self.writeConfFile(self.bblayers, new) |
| 307 | n.write(new) | ||
| 308 | |||
| 309 | # At some stage we should remove the backup we've created | ||
| 310 | # though we should probably verify it first | ||
| 311 | #os.remove(bkup) | ||
| 312 | 304 | ||
| 313 | # set loaded_layers for dirtiness tracking | 305 | # set loaded_layers for dirtiness tracking |
| 314 | self.loaded_layers = copy.deepcopy(self.enabled_layers) | 306 | self.loaded_layers = copy.deepcopy(self.enabled_layers) |
