Made it prettier

class_based_refactor
Nicholas Hope 2022-10-02 12:12:55 -04:00
parent f0dac0d1a1
commit f483beb0bd
1 changed files with 10 additions and 8 deletions

View File

@ -1,15 +1,15 @@
""" This has only one function. It mostly exists to allow imports of things like tftypes """
from copy import deepcopy
from tfscript.tftypes import double
from tfscript.tftypes import Double
def makeCFG(bindList, default=False):
if default:
# Write to defaultDict instead of condDict
double.condDict = double.defaultDict
Double.condDict = Double.defaultDict
else:
double.condDict = deepcopy(double.defaultDict)
Double.condDict = deepcopy(Double.defaultDict)
ret = ''
@ -18,14 +18,16 @@ def makeCFG(bindList, default=False):
# Doubles are weird. All of the toggles got put into a dictionary.
# This takes all of the nested dictionaries and turns them into the right string
if default or double.condDict != double.defaultDict:
if default or Double.condDict != Double.defaultDict:
# ==, and by extension !=, does in fact check
# for dictionary equality in keys and values
for key, toggles in double.condDict.items():
for key, toggles in Double.condDict.items():
onCondPress = ';'.join(toggles["change_keys"])
onCondRelease = ';'.join(toggles["restore_keys"])
ret += f'alias +{key}_toggles "{onCondPress}"\n' +\
f'alias -{key}_toggles "{onCondRelease}"\n' +\
f'bind {key} "+{key}_toggles"\n'
ret += (
f'alias +{key}_toggles "{onCondPress}"\n'
+ f'alias -{key}_toggles "{onCondRelease}"\n'
+ f'bind {key} "+{key}_toggles"\n'
)
return ret