From dda832659250ddd440e7830e187c4f8ccdeb4678 Mon Sep 17 00:00:00 2001 From: yegle Date: Mon, 10 Dec 2012 00:52:51 -0500 Subject: [PATCH] Refactoring the names used in config file --- config.json | 6 +++--- local.py | 19 +++++++------------ server.py | 14 ++++++-------- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/config.json b/config.json index 62a3a65..47e7219 100644 --- a/config.json +++ b/config.json @@ -1,7 +1,7 @@ { "server":"localhost", - "server_port":8388, - "local_port":1080, + "port":8388, + "localport":1080, "password":"barfoo!", "timeout":60 -} \ No newline at end of file +} diff --git a/local.py b/local.py index 45937f0..1f71b28 100755 --- a/local.py +++ b/local.py @@ -125,10 +125,6 @@ if __name__ == '__main__': with open('config.json', 'rb') as f: config = json.load(f) - SERVER = config['server'] - REMOTE_PORT = config['server_port'] - PORT = config['local_port'] - KEY = config['password'] parser = argparse.ArgumentParser( description='ShadowSocks Client' @@ -142,15 +138,14 @@ if __name__ == '__main__': sys.exit(1) 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 = args.server - if args.port: - REMOTE_PORT = args.port - if args.key: - KEY = args.key - if args.localport: - PORT = args.localport + SERVER = config['server'] + REMOTE_PORT = config['port'] + PORT = config['localport'] + KEY = config['password'] logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', filemode='a+') diff --git a/server.py b/server.py index faaeae2..6a8e45c 100755 --- a/server.py +++ b/server.py @@ -102,10 +102,6 @@ if __name__ == '__main__': with open('config.json', 'rb') as f: config = json.load(f) - SERVER = config['server'] - PORT = config['server_port'] - KEY = config['password'] - parser = argparse.ArgumentParser( description='ShadowSocks Server' ) @@ -116,12 +112,14 @@ if __name__ == '__main__': sys.exit(1) args = parser.parse_args() + d = vars(args) + _config = dict((k,d[k]) for k in d if d[k]) - if args.key: - KEY = args.key + config.update(_config) - if args.port: - PORT = args.port + SERVER = config['server'] + PORT = config['port'] + KEY = config['password'] logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', filemode='a+')