mirror of
https://github.com/ansible/awx.git
synced 2026-03-18 17:37:30 -02:30
clean up boilerplate for reading preset data
This commit is contained in:
@@ -1,34 +1,26 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
|
preset = 'medium'
|
||||||
|
|
||||||
presets_filename = os.path.abspath(os.path.join(
|
presets_filename = os.path.abspath(os.path.join(
|
||||||
os.path.dirname(os.path.abspath(__file__)),
|
os.path.dirname(os.path.abspath(__file__)),
|
||||||
'presets.tsv'))
|
'presets.tsv'))
|
||||||
|
|
||||||
with open(presets_filename) as f:
|
with open(presets_filename) as f:
|
||||||
r = f.read()
|
text = f.read()
|
||||||
|
|
||||||
print r
|
split_lines = [line.split('\t') for line in text.split('\n')]
|
||||||
|
keys = split_lines[0][1:]
|
||||||
|
|
||||||
lines = r.split('\n')
|
try:
|
||||||
keys = lines[0].split('\t')[1:]
|
col = keys.index(preset)
|
||||||
|
except ValueError:
|
||||||
preset = 'medium'
|
|
||||||
|
|
||||||
col = None
|
|
||||||
for i, key in enumerate(keys):
|
|
||||||
if key == preset:
|
|
||||||
col = i
|
|
||||||
break
|
|
||||||
|
|
||||||
if col is None:
|
|
||||||
raise Exception('Preset %s data set not found, options are %s' % (preset, keys))
|
raise Exception('Preset %s data set not found, options are %s' % (preset, keys))
|
||||||
|
|
||||||
|
options = {cols[0]: cols[col+1] for cols in split_lines}
|
||||||
|
|
||||||
options = {}
|
print ' text '
|
||||||
|
print text
|
||||||
for line in lines[1:]:
|
|
||||||
cols = line.split('\t')
|
|
||||||
options[cols[0]] = cols[i+1]
|
|
||||||
|
|
||||||
print ' options '
|
print ' options '
|
||||||
print options
|
print options
|
||||||
|
|||||||
Reference in New Issue
Block a user