Using actual ConfigParser call; dingd has -c for config file
This commit is contained in:
parent
3e7f23ccd1
commit
57fb2f7b99
2
ding
2
ding
@ -21,7 +21,7 @@ def readConfig():
|
|||||||
else:
|
else:
|
||||||
CONFIG = "ding.cfg"
|
CONFIG = "ding.cfg"
|
||||||
|
|
||||||
cfg = configparser.SafeConfigParser()
|
cfg = configparser.ConfigParser()
|
||||||
try:
|
try:
|
||||||
cfg.read(CONFIG)
|
cfg.read(CONFIG)
|
||||||
|
|
||||||
|
28
dingd
28
dingd
@ -3,7 +3,7 @@
|
|||||||
# Author: Bandie Canis
|
# Author: Bandie Canis
|
||||||
# License: 2-Clause BSD license
|
# License: 2-Clause BSD license
|
||||||
|
|
||||||
import ssl, socket, subprocess, time, os, sys
|
import ssl, socket, subprocess, time, os, sys, getopt
|
||||||
import configparser
|
import configparser
|
||||||
|
|
||||||
CONFIG = None
|
CONFIG = None
|
||||||
@ -26,7 +26,7 @@ def getTimestamp():
|
|||||||
return t
|
return t
|
||||||
|
|
||||||
def execFromConfig(option, pw=False):
|
def execFromConfig(option, pw=False):
|
||||||
cfg = configparser.SafeConfigParser()
|
cfg = configparser.ConfigParser()
|
||||||
cfg.read(CONFIG)
|
cfg.read(CONFIG)
|
||||||
|
|
||||||
if(pw):
|
if(pw):
|
||||||
@ -107,16 +107,19 @@ def main():
|
|||||||
except EOFError:
|
except EOFError:
|
||||||
print(getTimestamp(), "EOF")
|
print(getTimestamp(), "EOF")
|
||||||
|
|
||||||
def init():
|
def init(cfg=None):
|
||||||
|
|
||||||
global CONFIG, host, port, cafile, certfile, keyfile, pw_on, password, pwtimeout, tmppw_on, context, bindsocket
|
global CONFIG, host, port, cafile, certfile, keyfile, pw_on, password, pwtimeout, tmppw_on, context, bindsocket
|
||||||
|
|
||||||
if(os.name == 'nt'):
|
if(cfg==None):
|
||||||
CONFIG = "dingd.win.cfg"
|
if(os.name == 'nt'):
|
||||||
|
CONFIG = "dingd.win.cfg"
|
||||||
|
else:
|
||||||
|
CONFIG = "dingd.cfg"
|
||||||
else:
|
else:
|
||||||
CONFIG = "dingd.cfg"
|
CONFIG = cfg
|
||||||
|
|
||||||
cfg = configparser.SafeConfigParser()
|
cfg = configparser.ConfigParser()
|
||||||
cfg.read(CONFIG)
|
cfg.read(CONFIG)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -176,10 +179,17 @@ def init():
|
|||||||
|
|
||||||
|
|
||||||
if(__name__ == "__main__"):
|
if(__name__ == "__main__"):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
init()
|
conf = None
|
||||||
|
opts, args = getopt.getopt(sys.argv[1:], "c:")
|
||||||
|
for o, a in opts:
|
||||||
|
if o == "-c":
|
||||||
|
conf = a
|
||||||
|
init(conf)
|
||||||
main()
|
main()
|
||||||
|
except getopt.GetoptError as e:
|
||||||
|
print("Error using options. Allowed options:\n-c [FILE] - Config file\n")
|
||||||
|
quit(2)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("\r\rServer stopped.")
|
print("\r\rServer stopped.")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user