[tor-commits] [stem/master] Have Config's save() make directories it needs

atagar at torproject.org atagar at torproject.org
Fri Jan 22 17:30:35 UTC 2016


commit bb74233dd633e4bf3c90e3ab09efe3063b48cd30
Author: Damian Johnson <atagar at torproject.org>
Date:   Fri Jan 22 09:01:34 2016 -0800

    Have Config's save() make directories it needs
    
    Honestly it's always bugged me that write functions don't do this. Oh,
    directory foo doesn't exist? Then... umm, make it? I understand you gotta
    treat computers like a brain damaged infant but come on. It's 2016. Why
    don't standard libs have a reasonable default.
    
    </rant>
    
    Anyway, having our save() method do the sane thing.
---
 stem/util/conf.py |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/stem/util/conf.py b/stem/util/conf.py
index 18226d8..134766c 100644
--- a/stem/util/conf.py
+++ b/stem/util/conf.py
@@ -552,6 +552,9 @@ class Config(object):
       raise ValueError('Unable to save configuration: no path provided')
 
     with self._contents_lock:
+      if not os.path.exists(os.path.dirname(self._path)):
+        os.makedirs(os.path.dirname(self._path))
+
       with open(self._path, 'w') as output_file:
         for entry_key in self.keys():
           for entry_value in self.get_value(entry_key, multiple = True):



More information about the tor-commits mailing list