[codeface] Re: [PATCH] Save configuration file to temp location

  • From: Wolfgang Mauerer <wm@xxxxxxxxxxxxxxxx>
  • To: codeface@xxxxxxxxxxxxx, Mitchell Joblin <joblin.m@xxxxxxxxx>, "Joblin, Mitchell (ext)" <mitchell.joblin.ext@xxxxxxxxxxx>
  • Date: Thu, 01 May 2014 10:27:12 -0700

Hi Mitchell,

Am 01/05/2014 04:53, schrieb Mitchell Joblin:
- In the case of manipulating configuration values after loading
   the configuration file we need to save the changes because
   other analysis phases again read the configuration file

- We now save the project configuration file to a temporary
   location since we don't want to overwrite the original

- The project file location variable is then changed to this new
   temp file so that future reads will be on the manipulated
   values, not the originals

Signed-off-by: Mitchell Joblin <mitchell.joblin.ext@xxxxxxxxxxx>
---
  codeface/configuration.py | 7 +++++++
  codeface/project.py       | 5 +++++
  2 files changed, 12 insertions(+)

diff --git a/codeface/configuration.py b/codeface/configuration.py
index 0307925..45bf0df 100644
--- a/codeface/configuration.py
+++ b/codeface/configuration.py
@@ -134,6 +134,13 @@ class Configuration(Mapping):
          for key in unknown_keys:
              log.warning("Unknown key '{}' in configuration.".format(key))

+    def write(self):
+      conf_file = "/tmp/" + self._conf["project"] + ".conf"
instead of fixing path and name of the configuration file, could
you please use tempfile.NamedTemporaryFile()? This avoids various
common problems with temporary files.

Thanks, Wolfgang
+      project_file = open(conf_file, 'w')
+      dic = self._conf
+      yaml.dump(dic, project_file)
+      project_file.close()
+
      # Function for the Configuration object to function as a dict
      def __getitem__(self, key):
          return self._conf[key]
diff --git a/codeface/project.py b/codeface/project.py
index e12d6eb..a6edf81 100644
--- a/codeface/project.py
+++ b/codeface/project.py
@@ -69,6 +69,11 @@ def project_analyse(resdir, gitdir, codeface_conf, 
project_conf,
          check4ctags()

      project_id, dbm, all_range_ids = project_setup(conf, recreate)
+
+    ## Save configuration file
+    conf.write()
+    project_conf = "/tmp/" + project + ".conf"
+
      # Analyse new revision ranges
      for i, range_id in enumerate(all_range_ids):
          start_rev, end_rev, rc_rev = dbm.get_release_range(project_id, 
range_id)


Other related posts: