groups, sorted display, sorted write
This commit is contained in:
@@ -4,14 +4,31 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
def main(config_filename):
|
||||
import urwid
|
||||
def read_config_file(config_filename):
|
||||
import ConfigParser
|
||||
|
||||
config = ConfigParser.SafeConfigParser()
|
||||
config.read(config_filename)
|
||||
#print config_filename
|
||||
#config.write(sys.stdout)
|
||||
return config
|
||||
|
||||
def write_config_file(config, config_filename):
|
||||
for idx in range(8, 0, -1):
|
||||
if os.path.exists(config_filename + "." + str(idx)):
|
||||
os.rename(config_filename + "." + str(idx),
|
||||
config_filename + "." + str(idx + 1))
|
||||
if os.path.exists(config_filename):
|
||||
os.rename(config_filename, config_filename + ".1")
|
||||
with open(config_filename, "wb") as configfile:
|
||||
for section in sorted(config.sections()):
|
||||
configfile.write("[%s]\n" % section)
|
||||
for option in sorted(config.options(section)):
|
||||
configfile.write("%s = %s\n" % (option, config.get(section, option)))
|
||||
configfile.write("\n")
|
||||
#config.write(configfile)
|
||||
|
||||
def main(config_filename):
|
||||
import urwid
|
||||
|
||||
config = read_config_file(config_filename)
|
||||
text_header = (
|
||||
u"SICS Config Editor! w/W/F12 Saves & Exits\n"
|
||||
u"UP / DOWN / PAGE UP / PAGE DOWN scroll. q/Q/F8 Exits.")
|
||||
@@ -30,8 +47,21 @@ def main(config_filename):
|
||||
cb.set_state(new_state)
|
||||
|
||||
text_cb_list = list(config.sections())
|
||||
cb_list = []
|
||||
cb_map = {}
|
||||
for txt in sorted(text_cb_list):
|
||||
if 'group' in config.options(txt):
|
||||
group = config.get(txt, 'group').lower()
|
||||
else:
|
||||
group = ""
|
||||
if group not in cb_map:
|
||||
cb_map[group] = []
|
||||
cb_map[group].append(txt)
|
||||
sorted_text_cb_list = []
|
||||
for key in sorted(cb_map.keys()):
|
||||
for val in sorted(cb_map[key]):
|
||||
sorted_text_cb_list.append(val)
|
||||
cb_list = []
|
||||
for txt in sorted_text_cb_list:
|
||||
state = False
|
||||
if 'enabled' in config.options(txt):
|
||||
if config.get(txt, 'enabled').lower() in ['1', 'yes', 'true']:
|
||||
@@ -91,14 +121,7 @@ def main(config_filename):
|
||||
|
||||
def unhandled(key):
|
||||
if key in ['w', 'W', 'f12']:
|
||||
for idx in range(8, 0, -1):
|
||||
if os.path.exists(config_filename + "." + str(idx)):
|
||||
os.rename(config_filename + "." + str(idx),
|
||||
config_filename + "." + str(idx - 1))
|
||||
if os.path.exists(config_filename):
|
||||
os.rename(config_filename, config_filename + ".1")
|
||||
with open(config_filename, "wb") as configfile:
|
||||
config.write(configfile)
|
||||
write_config_file(config, config_filename)
|
||||
raise urwid.ExitMainLoop()
|
||||
elif key in ['e', 'E', 'f4']:
|
||||
f = sflw.get_focus()
|
||||
|
||||
Reference in New Issue
Block a user