added getopts to tupkg

This commit is contained in:
jchu 2004-09-03 20:46:03 +00:00
parent 47b7a53460
commit 90473a79d3

View file

@ -20,6 +20,7 @@ import os.path
import cgi import cgi
import urllib import urllib
import md5 import md5
import getopt
class ClientFile: class ClientFile:
def __init__(self, pathname): def __init__(self, pathname):
@ -111,18 +112,45 @@ class ClientSocket:
self.sendMsg("ack") self.sendMsg("ack")
def usage(): def usage():
print "usage: tupkg <package file>" print "usage: tupkg [options] <package file>"
print "options:"
print " -u, --user Connect with username"
print " -P, --password Connect with password"
print " -h, --host Connect to host"
print " -p, --port Connect to host on port (default 1034)"
def main(argv=None): def main(argv=None):
if argv is None: if argv is None:
argv = sys.argv argv = sys.argv
confdict = {}
confdict['user'] = ""
confdict['password'] = ""
confdict['host'] = ''
confdict['port'] = 1034
if len(argv) == 1: if len(argv) == 1:
usage() usage()
return 1 return 1
try:
optlist, args = getopt.getopt(argv[1:], "u:P:h:p:", ["user=", "password=", "host=", "port="])
except getopt.GetoptError:
usage()
return 1
for i, k in optlist:
if i in ('-u', '--user'):
confdict['user'] = k
if i in ('-P', '--password'):
confdict['password'] = k
if i in ('-h', '--host'):
confdict['host'] = k
if i in ('-p', '--port'):
confdict['port'] = int(k)
files = [] files = []
for i in argv[1:]: for i in args:
try: try:
files.append(ClientFile(i)) files.append(ClientFile(i))
except IOError, err: except IOError, err:
@ -130,7 +158,7 @@ def main(argv=None):
usage() usage()
return 1 return 1
cs = ClientSocket(files, 'localhost', 1034, "tu", "tu") cs = ClientSocket(files, confdict['host'], confdict['port'], confdict['user'], confdict['password'])
cs.connect() cs.connect()
if not cs.auth(): if not cs.auth():