Skip to content

Commit

Permalink
Merge pull request #34668 from andras-tim/fix-ini-line-ending
Browse files Browse the repository at this point in the history
INI uses proper line endings - fix #34667
  • Loading branch information
Mike Place committed Jul 14, 2016
2 parents 1962661 + c211cfa commit aa4a37a
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions salt/modules/ini_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# Import Python libs
from __future__ import print_function
from __future__ import absolute_import
import os
import re
import json
from salt.utils.odict import OrderedDict
Expand Down Expand Up @@ -210,13 +211,13 @@ def refresh(self, inicontents=None):
unknown_count = 1
curr_indent = ''
inicontents = inicontents or self.inicontents
inicontents = inicontents.strip('\n')
inicontents = inicontents.strip(os.linesep)

if not inicontents:
return
for opt in self:
self.pop(opt)
for opt_str in inicontents.split('\n'):
for opt_str in inicontents.split(os.linesep):
# Match comments
com_match = com_regx.match(opt_str)
if com_match:
Expand All @@ -234,7 +235,7 @@ def refresh(self, inicontents=None):
if options:
prev_opt = options[-1]
value = self.get(prev_opt)
self.update({prev_opt: '\n'.join((value, opt_str))})
self.update({prev_opt: os.linesep.join((value, opt_str))})
continue
# Match normal key+value lines.
opt_match = self.opt_regx.match(opt_str)
Expand Down Expand Up @@ -311,21 +312,22 @@ def update(self, update_dict):
return changes

def gen_ini(self):
yield '\n[{0}]\n'.format(self.name)
yield '{0}[{1}]{0}'.format(os.linesep, self.name)
sections_dict = OrderedDict()
for name, value in self.iteritems():
if com_regx.match(name):
yield '{0}\n'.format(value)
yield '{0}{1}'.format(value, os.linesep)
elif isinstance(value, _Section):
sections_dict.update({name: value})
else:
yield '{0}{1}{2}\n'.format(
yield '{0}{1}{2}{3}'.format(
name,
(
' {0} '.format(self.sep) if self.sep != ' '
else self.sep
),
value
value,
os.linesep
)
for name, value in sections_dict.iteritems():
for line in value.gen_ini():
Expand All @@ -343,7 +345,7 @@ def dump(self):
def __repr__(self, _repr_running=None):
_repr_running = _repr_running or {}
super_repr = super(_Section, self).__repr__(_repr_running)
return '\n'.join((super_repr, json.dumps(self, indent=4)))
return os.linesep.join((super_repr, json.dumps(self, indent=4)))

def __str__(self):
return json.dumps(self, indent=4)
Expand Down

0 comments on commit aa4a37a

Please sign in to comment.