Commits

Anonymous committed 0fb32c1

fixed issues with multiline values and special characters

  • Participants
  • Parent commits c4f77ca

Comments (0)

Files changed (3)

 ----------
 
 type:
->python setup.py INSTALL
+>python setup.py install
 
 LICENCE
 -------

File confpatcher/confpatcher.py

        param: value 
     or param=value
     """
+    regular_line_re = re.compile(r'([^=]+)=([^#]+)#?')
+    multiline_value_re = re.compile(r'([^=#]+)')
     data_file = open(data_file_name, 'r')
-    data = None
-    if patch_file:
-        data = data_file.read()
-        data = yaml.load(data.replace("=", ": "))
-        data_file.close()
+    if not patch_file:
+        return None
+    data = data_file.read()
+    data_file.close()
+    converted_data = ''
+    for line in data.split('\n'):
+        m = regular_line_re.search(line)
+        if m:
+            parameter_name = m.groups(0)[0].strip()
+            value = m.groups(0)[1].strip()
+            if '"' in value:
+                converted_data += "%(parameter_name)s : r'%(value)s'\n"%vars()
+            else:
+                converted_data += '%(parameter_name)s : r"%(value)s"\n'%vars()
+        else:
+            m = multiline_value_re.match(line)
+            if m and m.groups(0)[0].strip() != "":
+                converted_data = converted_data[:-2] + ' '+ m.groups(0)[0].strip().replace('"', '\"') +'"\n'
+            else:
+                converted_data += line + "\n"
+    data = yaml.load(converted_data)
+    data = dict((key, eval(value)) for key, value in data.items())
+    data = dict((key, value.replace('\"', '"')) for key, value in data.items())
     return data
     
     

File tests/run_tests.py

     
     # load patch data
     patch_data = confpatcher.config_from_file('pre-rendered_patch_data.yaml')
-    
+
     # launch test
     confpatcher.patch_file(destination_name, patch_data)