ding client with -c <CONFIGFILE> option
This commit is contained in:
parent
4622833ff5
commit
63e52b8c3e
32
ding
32
ding
@ -3,7 +3,7 @@
|
|||||||
# Author: Bandie Canis
|
# Author: Bandie Canis
|
||||||
# License: 2-Clause BSD License
|
# License: 2-Clause BSD License
|
||||||
|
|
||||||
import sys, ssl, socket, os
|
import sys, ssl, socket, os, getopt
|
||||||
import configparser
|
import configparser
|
||||||
|
|
||||||
|
|
||||||
@ -14,12 +14,15 @@ certfile = None
|
|||||||
keyfile = None
|
keyfile = None
|
||||||
exitcode = 1
|
exitcode = 1
|
||||||
|
|
||||||
def readConfig():
|
def init(conf):
|
||||||
|
|
||||||
if(os.name == 'nt'):
|
if(conf == None):
|
||||||
CONFIG = "ding.win.cfg"
|
if(os.name == 'nt'):
|
||||||
|
CONFIG = "ding.win.cfg"
|
||||||
|
else:
|
||||||
|
CONFIG = "ding.cfg"
|
||||||
else:
|
else:
|
||||||
CONFIG = "ding.cfg"
|
CONFIG = conf
|
||||||
|
|
||||||
cfg = configparser.ConfigParser()
|
cfg = configparser.ConfigParser()
|
||||||
try:
|
try:
|
||||||
@ -67,7 +70,7 @@ def send(conn, cmd):
|
|||||||
quit(exitcode)
|
quit(exitcode)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main(arg):
|
||||||
try:
|
try:
|
||||||
context = ssl.SSLContext(ssl.PROTOCOL_TLS)
|
context = ssl.SSLContext(ssl.PROTOCOL_TLS)
|
||||||
context.verify_mode = ssl.CERT_REQUIRED
|
context.verify_mode = ssl.CERT_REQUIRED
|
||||||
@ -85,7 +88,7 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
send(conn, bytes(sys.argv[1], sys.stdin.encoding))
|
send(conn, bytes(arg[0], sys.stdin.encoding))
|
||||||
except IndexError:
|
except IndexError:
|
||||||
print(sys.argv[0], ": Missing argument.\nSyntax: ", sys.argv[0], " <COMMAND>", file=sys.stderr)
|
print(sys.argv[0], ": Missing argument.\nSyntax: ", sys.argv[0], " <COMMAND>", file=sys.stderr)
|
||||||
except ConnectionRefusedError:
|
except ConnectionRefusedError:
|
||||||
@ -98,7 +101,16 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
if(__name__ == "__main__"):
|
if(__name__ == "__main__"):
|
||||||
readConfig()
|
try:
|
||||||
main()
|
conf = None
|
||||||
quit(exitcode)
|
opts, args = getopt.getopt(sys.argv[1:], "c:")
|
||||||
|
for o, a in opts:
|
||||||
|
if o == "-c":
|
||||||
|
conf = a
|
||||||
|
init(conf)
|
||||||
|
main(args)
|
||||||
|
except getopt.GetoptError as e:
|
||||||
|
print("Error using options. Allowed options:\n-c [FILE] - Config file\n")
|
||||||
|
quit(2)
|
||||||
|
|
||||||
|
quit(exitcode)
|
||||||
|
Loading…
Reference in New Issue
Block a user