Refactoring the names used in config file

This commit is contained in:
yegle 2012-12-10 00:52:51 -05:00
parent a61c718a33
commit dda8326592
3 changed files with 16 additions and 23 deletions

View file

@ -1,7 +1,7 @@
{ {
"server":"localhost", "server":"localhost",
"server_port":8388, "port":8388,
"local_port":1080, "localport":1080,
"password":"barfoo!", "password":"barfoo!",
"timeout":60 "timeout":60
} }

View file

@ -125,10 +125,6 @@ if __name__ == '__main__':
with open('config.json', 'rb') as f: with open('config.json', 'rb') as f:
config = json.load(f) config = json.load(f)
SERVER = config['server']
REMOTE_PORT = config['server_port']
PORT = config['local_port']
KEY = config['password']
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description='ShadowSocks Client' description='ShadowSocks Client'
@ -142,15 +138,14 @@ if __name__ == '__main__':
sys.exit(1) sys.exit(1)
args = parser.parse_args() args = parser.parse_args()
d = vars(args)
_config = dict((k,d[k]) for k in d if d[k])
config.update(_config)
if args.server: SERVER = config['server']
SERVER = args.server REMOTE_PORT = config['port']
if args.port: PORT = config['localport']
REMOTE_PORT = args.port KEY = config['password']
if args.key:
KEY = args.key
if args.localport:
PORT = args.localport
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s', logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s',
datefmt='%Y-%m-%d %H:%M:%S', filemode='a+') datefmt='%Y-%m-%d %H:%M:%S', filemode='a+')

View file

@ -102,10 +102,6 @@ if __name__ == '__main__':
with open('config.json', 'rb') as f: with open('config.json', 'rb') as f:
config = json.load(f) config = json.load(f)
SERVER = config['server']
PORT = config['server_port']
KEY = config['password']
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description='ShadowSocks Server' description='ShadowSocks Server'
) )
@ -116,12 +112,14 @@ if __name__ == '__main__':
sys.exit(1) sys.exit(1)
args = parser.parse_args() args = parser.parse_args()
d = vars(args)
_config = dict((k,d[k]) for k in d if d[k])
if args.key: config.update(_config)
KEY = args.key
if args.port: SERVER = config['server']
PORT = args.port PORT = config['port']
KEY = config['password']
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s', logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s',
datefmt='%Y-%m-%d %H:%M:%S', filemode='a+') datefmt='%Y-%m-%d %H:%M:%S', filemode='a+')