From 72fe18212e8ba6c0d880bdb66e07270a489001d9 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Sat, 26 Jul 2014 16:14:48 +0800 Subject: [PATCH] add quiet mode; close #164 --- CHANGES | 4 ++++ setup.py | 2 +- shadowsocks/utils.py | 26 ++++++++++++++++++-------- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/CHANGES b/CHANGES index 68e75bd..0e6c2b4 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +2.0.12 2014-07-26 +- Support -q quiet mode +- Exit 0 when showing help with -h + 2.0.11 2014-07-12 - Prefers IP addresses over hostnames, more friendly with socksify and openvpn diff --git a/setup.py b/setup.py index 2bf1d1f..b59b3df 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ with open('README.rst') as f: setup( name="shadowsocks", - version="2.0.11", + version="2.0.12", license='MIT', description="A fast tunnel proxy that help you get through firewalls", author='clowwindy', diff --git a/shadowsocks/utils.py b/shadowsocks/utils.py index 7724594..d570435 100644 --- a/shadowsocks/utils.py +++ b/shadowsocks/utils.py @@ -84,10 +84,10 @@ def check_config(config): def get_config(is_local): if is_local: - shortopts = 'hs:b:p:k:l:m:c:t:v' + shortopts = 'hs:b:p:k:l:m:c:t:vq' longopts = ['fast-open'] else: - shortopts = 'hs:p:k:m:c:t:v' + shortopts = 'hs:p:k:m:c:t:vq' longopts = ['fast-open', 'workers:'] try: config_path = find_config() @@ -139,6 +139,9 @@ def get_config(is_local): else: print_server_help() sys.exit(0) + elif key == '-q': + v_count -= 1 + config['verbose'] = v_count except getopt.GetoptError as e: print >>sys.stderr, e if is_local: @@ -162,10 +165,14 @@ def get_config(is_local): logging.getLogger('').handlers = [] logging.addLevelName(VERBOSE_LEVEL, 'VERBOSE') - if config['verbose'] == 2: + if config['verbose'] >= 2: level = VERBOSE_LEVEL - elif config['verbose']: + elif config['verbose'] == 1: level = logging.DEBUG + elif config['verbose'] == -1: + level = logging.WARN + elif config['verbose'] <= -2: + level = logging.ERROR else: level = logging.INFO logging.basicConfig(level=level, @@ -180,7 +187,7 @@ def get_config(is_local): def print_local_help(): print '''usage: sslocal [-h] -s SERVER_ADDR -p SERVER_PORT [-b LOCAL_ADDR] -l LOCAL_PORT -k PASSWORD -m METHOD [-t TIMEOUT] [-c CONFIG] - [--fast-open] [-v] + [--fast-open] [-v] [-q] optional arguments: -h, --help show this help message and exit @@ -193,7 +200,8 @@ optional arguments: -t TIMEOUT timeout in seconds -c CONFIG path to config file --fast-open use TCP_FASTOPEN, requires Linux 3.7+ - -v verbose mode + -v, -vv verbose mode + -q, -qq quiet mode, only show warnings/errors Online help: ''' @@ -201,7 +209,8 @@ Online help: def print_server_help(): print '''usage: ssserver [-h] -s SERVER_ADDR -p SERVER_PORT -k PASSWORD - -m METHOD [-t TIMEOUT] [-c CONFIG] [--fast-open] [-v] + -m METHOD [-t TIMEOUT] [-c CONFIG] [--fast-open] [--workders] + [-v] [-q] optional arguments: -h, --help show this help message and exit @@ -213,7 +222,8 @@ optional arguments: -c CONFIG path to config file --fast-open use TCP_FASTOPEN, requires Linux 3.7+ --workers WORKERS number of workers, available on Unix/Linux - -v verbose mode + -v, -vv verbose mode + -q, -qq quiet mode, only show warnings/errors Online help: '''