add perimitive argparse support
This commit is contained in:
parent
54a6c6eff9
commit
c048fda55a
21
esgd.py
21
esgd.py
|
@ -1,5 +1,6 @@
|
||||||
import socketserver
|
import socketserver
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import argparse
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import pwd
|
import pwd
|
||||||
|
@ -186,13 +187,23 @@ class GopherHandler(socketserver.BaseRequestHandler, GopherServerLogic):
|
||||||
self.serveFile(file[0], parsed[1], file[1])
|
self.serveFile(file[0], parsed[1], file[1])
|
||||||
|
|
||||||
log = Logger()
|
log = Logger()
|
||||||
host = "localhost"
|
|
||||||
port = 70
|
|
||||||
location = "/tmp/test"
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
switchgrp = grp.getgrnam("nobody").gr_gid
|
parse = argparse.ArgumentParser()
|
||||||
switchusr = pwd.getpwnam("nobody").pw_uid
|
parse.add_argument("-u", "--user", default="nobody", help="user to change to on startup")
|
||||||
|
parse.add_argument("-g", "--group", default="nobody", help="group to change to on startup")
|
||||||
|
parse.add_argument("-s", "--host", default="localhost", help="host to host on")
|
||||||
|
parse.add_argument("-p", "--port", default=70, type=int, help="port to host on")
|
||||||
|
parse.add_argument("-d", "--dir", default="/var/gopher", help="directory to host from")
|
||||||
|
args = parse.parse_args()
|
||||||
|
log.log("arguments parsed")
|
||||||
|
|
||||||
|
switchgrp = grp.getgrnam(args.group).gr_gid
|
||||||
|
switchusr = pwd.getpwnam(args.user).pw_uid
|
||||||
|
host = args.host
|
||||||
|
port = args.port
|
||||||
|
location = args.dir
|
||||||
|
log.log("arguments good")
|
||||||
try:
|
try:
|
||||||
with socketserver.TCPServer((host, port), GopherHandler) as server:
|
with socketserver.TCPServer((host, port), GopherHandler) as server:
|
||||||
os.setgid(switchgrp)
|
os.setgid(switchgrp)
|
||||||
|
|
Loading…
Reference in New Issue