mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
removed with
Signed-off-by: Brian Coca <briancoca+dev@gmail.com>
This commit is contained in:
parent
8880819395
commit
310b23ee8d
1 changed files with 19 additions and 19 deletions
|
@ -178,10 +178,10 @@ class SourcesList(object):
|
||||||
|
|
||||||
def load(self, file):
|
def load(self, file):
|
||||||
group = []
|
group = []
|
||||||
with open(file, 'r') as f:
|
f = open(file, 'r')
|
||||||
for n, line in enumerate(f):
|
for n, line in enumerate(f):
|
||||||
valid, enabled, source, comment = self._parse(line)
|
valid, enabled, source, comment = self._parse(line)
|
||||||
group.append((n, valid, enabled, source, comment))
|
group.append((n, valid, enabled, source, comment))
|
||||||
self.files[file] = group
|
self.files[file] = group
|
||||||
|
|
||||||
def save(self, module):
|
def save(self, module):
|
||||||
|
@ -191,22 +191,22 @@ class SourcesList(object):
|
||||||
fd, tmp_path = tempfile.mkstemp(prefix=".%s-" % fn, dir=d)
|
fd, tmp_path = tempfile.mkstemp(prefix=".%s-" % fn, dir=d)
|
||||||
os.chmod(os.path.join(fd, tmp_path), 0644)
|
os.chmod(os.path.join(fd, tmp_path), 0644)
|
||||||
|
|
||||||
with os.fdopen(fd, 'w') as f:
|
f = os.fdopen(fd, 'w')
|
||||||
for n, valid, enabled, source, comment in sources:
|
for n, valid, enabled, source, comment in sources:
|
||||||
chunks = []
|
chunks = []
|
||||||
if not enabled:
|
if not enabled:
|
||||||
chunks.append('# ')
|
chunks.append('# ')
|
||||||
chunks.append(source)
|
chunks.append(source)
|
||||||
if comment:
|
if comment:
|
||||||
chunks.append(' # ')
|
chunks.append(' # ')
|
||||||
chunks.append(comment)
|
chunks.append(comment)
|
||||||
chunks.append('\n')
|
chunks.append('\n')
|
||||||
line = ''.join(chunks)
|
line = ''.join(chunks)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
f.write(line)
|
f.write(line)
|
||||||
except IOError, err:
|
except IOError, err:
|
||||||
module.fail_json(msg="Failed to write to file %s: %s" % (tmp_path, unicode(err)))
|
module.fail_json(msg="Failed to write to file %s: %s" % (tmp_path, unicode(err)))
|
||||||
module.atomic_move(tmp_path, filename)
|
module.atomic_move(tmp_path, filename)
|
||||||
else:
|
else:
|
||||||
del self.files[filename]
|
del self.files[filename]
|
||||||
|
|
Loading…
Reference in a new issue