Initial commit of working config write code

This commit is contained in:
2022-08-06 00:49:01 +01:00
commit 816824a0c7
7 changed files with 81 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true
}
]
}
+55
View File
@@ -0,0 +1,55 @@
from dis import dis
class ConfigWriter:
def __init__(self):
self._config_file = 'C:\\Program Files\\EqualizerAPO\\config\\config.txt'
self._config_output = None
self.headphone_mode_enabled = False
self.active_headphone = None
self.inactive_headphones = list()
# Read current config.
with open(self._config_file, 'r') as c:
self._config_output = c.readlines()
c.close()
# Extract spec name from text output.
for spec in self._config_output:
if spec.startswith('# '):
_spec = spec.replace('# ', '').removesuffix('\n').removesuffix('.txt').removeprefix('Include:')
self.inactive_headphones.append(_spec.strip())
else:
_spec = spec.removesuffix('\n').removesuffix('.txt').removeprefix('Include:')
self.active_headphone = _spec.strip()
if self.active_headphone is not None:
self.headphone_mode_enabled = True
def write_specs(self, disabled_specs, enabled_spec):
formatted_disabled_specs = list()
formatted_enabled_spec = self._format_spec(enabled_spec, False)
if disabled_specs is not None:
for s in disabled_specs:
formatted_disabled_specs.append(self._format_spec(s, True))
with open(self._config_file, 'w+') as c:
for i in formatted_disabled_specs:
c.write(i + '\n')
if enabled_spec is not None:
c.write(formatted_enabled_spec)
c.close()
def _format_spec(self, entry: str, disable: bool):
_entry = None
if disable:
_entry = '# Include: {}.txt'.format(entry)
else:
_entry = 'Include: {}.txt'.format(entry)
return _entry
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

+10
View File
@@ -0,0 +1,10 @@
from config_writer import ConfigWriter
cw = ConfigWriter()
lis = cw.inactive_headphones
if cw.active_headphone is not None:
lis.append(cw.active_headphone)
#cw.write_specs(lis, None)
cw.write_specs(cw.active_headphone, cw.inactive_headphones[0])