60 lines
1.4 KiB
Python
Executable File
60 lines
1.4 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
import os
|
|
import sys
|
|
|
|
from Window import *
|
|
|
|
def get_config(fname):
|
|
conf = {}
|
|
if os.path.isfile(fname):
|
|
try:
|
|
f = open(fname, 'r')
|
|
contents = f.read()
|
|
f.close()
|
|
exec(contents, conf)
|
|
except:
|
|
pass
|
|
return conf
|
|
|
|
def save_config(fname, conf):
|
|
if os.path.isfile(fname):
|
|
fh = open(fname, 'r')
|
|
old_config = fh.read()
|
|
fh.close()
|
|
else:
|
|
old_config = ''
|
|
new_config = ''
|
|
conf_ents = filter(lambda x: not x.startswith('_'), conf)
|
|
for s in map(lambda x: x + ' = ' + repr(conf[x]) + '\n', conf_ents):
|
|
new_config += s
|
|
if old_config != new_config:
|
|
fh = open(fname, 'w')
|
|
fh.write(new_config)
|
|
fh.close()
|
|
|
|
def main(argv):
|
|
if len(argv) < 2:
|
|
sys.stderr.write('Specify config file as an argument\n')
|
|
return 2
|
|
|
|
config_fname = argv[1]
|
|
|
|
conf = get_config(config_fname)
|
|
if not ('server' in conf
|
|
and 'port' in conf
|
|
and 'user' in conf
|
|
and 'password' in conf):
|
|
sys.stderr.write(
|
|
'Must specify server, port, user, and password'
|
|
' in configuration file\n')
|
|
return 1
|
|
|
|
window = Window(conf)
|
|
window.run()
|
|
|
|
save_config(config_fname, window.conf)
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main(sys.argv))
|