Browse Source

support --version

master
clowwindy 10 years ago
parent
commit
dfd81af844
  1. 2
      .jenkins.sh
  2. 2
      shadowsocks/local.py
  3. 2
      shadowsocks/server.py
  4. 2
      shadowsocks/tcprelay.py
  5. 16
      shadowsocks/utils.py
  6. 3
      tests/test_command.sh

2
.jenkins.sh

@ -27,7 +27,7 @@ function run_test {
python --version python --version
coverage erase coverage erase
mkdir tmp mkdir tmp
run_test pep8 . run_test pep8 --ignore=E402 .
run_test pyflakes . run_test pyflakes .
run_test coverage run tests/nose_plugin.py -v run_test coverage run tests/nose_plugin.py -v
run_test python setup.py sdist run_test python setup.py sdist

2
shadowsocks/local.py

@ -40,8 +40,6 @@ def main():
daemon.daemon_exec(config) daemon.daemon_exec(config)
utils.print_shadowsocks()
try: try:
logging.info("starting local at %s:%d" % logging.info("starting local at %s:%d" %
(config['local_address'], config['local_port'])) (config['local_address'], config['local_port']))

2
shadowsocks/server.py

@ -34,8 +34,6 @@ def main():
daemon.daemon_exec(config) daemon.daemon_exec(config)
utils.print_shadowsocks()
if config['port_password']: if config['port_password']:
if config['password']: if config['password']:
logging.warn('warning: port_password should not be used with ' logging.warn('warning: port_password should not be used with '

2
shadowsocks/tcprelay.py

@ -328,7 +328,7 @@ class TCPRelayHandler(object):
addrs = socket.getaddrinfo(ip, port, 0, socket.SOCK_STREAM, addrs = socket.getaddrinfo(ip, port, 0, socket.SOCK_STREAM,
socket.SOL_TCP) socket.SOL_TCP)
if len(addrs) == 0: if len(addrs) == 0:
raise Exception("getaddrinfo failed for %s:%d" % (ip, port)) raise Exception("getaddrinfo failed for %s:%d" % (ip, port))
af, socktype, proto, canonname, sa = addrs[0] af, socktype, proto, canonname, sa = addrs[0]
if self._forbidden_iplist: if self._forbidden_iplist:
if common.to_str(sa[0]) in self._forbidden_iplist: if common.to_str(sa[0]) in self._forbidden_iplist:

16
shadowsocks/utils.py

@ -50,7 +50,7 @@ def print_shadowsocks():
version = pkg_resources.get_distribution('shadowsocks').version version = pkg_resources.get_distribution('shadowsocks').version
except Exception: except Exception:
pass pass
print('shadowsocks %s' % version) print('Shadowsocks %s' % version)
def find_config(): def find_config():
@ -119,11 +119,12 @@ def get_config(is_local):
format='%(levelname)-s: %(message)s') format='%(levelname)-s: %(message)s')
if is_local: if is_local:
shortopts = 'hd:s:b:p:k:l:m:c:t:vq' shortopts = 'hd:s:b:p:k:l:m:c:t:vq'
longopts = ['help', 'fast-open', 'pid-file=', 'log-file=', 'user='] longopts = ['help', 'fast-open', 'pid-file=', 'log-file=', 'user=',
'version']
else: else:
shortopts = 'hd:s:p:k:m:c:t:vq' shortopts = 'hd:s:p:k:m:c:t:vq'
longopts = ['help', 'fast-open', 'pid-file=', 'log-file=', 'workers=', longopts = ['help', 'fast-open', 'pid-file=', 'log-file=', 'workers=',
'forbidden-ip=', 'user='] 'forbidden-ip=', 'user=', 'version']
try: try:
config_path = find_config() config_path = find_config()
optlist, args = getopt.getopt(sys.argv[1:], shortopts, longopts) optlist, args = getopt.getopt(sys.argv[1:], shortopts, longopts)
@ -179,6 +180,9 @@ def get_config(is_local):
else: else:
print_server_help() print_server_help()
sys.exit(0) sys.exit(0)
elif key == '--version':
print_shadowsocks()
sys.exit(0)
elif key == '-d': elif key == '-d':
config['daemon'] = to_str(value) config['daemon'] = to_str(value)
elif key == '--pid-file': elif key == '--pid-file':
@ -262,7 +266,6 @@ A fast tunnel proxy that helps you bypass firewalls.
You can supply configurations via either config file or command line arguments. You can supply configurations via either config file or command line arguments.
Proxy options: Proxy options:
-h, --help show this help message and exit
-c CONFIG path to config file -c CONFIG path to config file
-s SERVER_ADDR server address -s SERVER_ADDR server address
-p SERVER_PORT server port, default: 8388 -p SERVER_PORT server port, default: 8388
@ -274,12 +277,14 @@ Proxy options:
--fast-open use TCP_FASTOPEN, requires Linux 3.7+ --fast-open use TCP_FASTOPEN, requires Linux 3.7+
General options: General options:
-h, --help show this help message and exit
-d start/stop/restart daemon mode -d start/stop/restart daemon mode
--pid-file PID_FILE pid file for daemon mode --pid-file PID_FILE pid file for daemon mode
--log-file LOG_FILE log file for daemon mode --log-file LOG_FILE log file for daemon mode
--user USER username to run as --user USER username to run as
-v, -vv verbose mode -v, -vv verbose mode
-q, -qq quiet mode, only show warnings/errors -q, -qq quiet mode, only show warnings/errors
--version show version information
Online help: <https://github.com/shadowsocks/shadowsocks> Online help: <https://github.com/shadowsocks/shadowsocks>
''') ''')
@ -292,7 +297,6 @@ A fast tunnel proxy that helps you bypass firewalls.
You can supply configurations via either config file or command line arguments. You can supply configurations via either config file or command line arguments.
Proxy options: Proxy options:
-h, --help show this help message and exit
-c CONFIG path to config file -c CONFIG path to config file
-s SERVER_ADDR server address, default: 0.0.0.0 -s SERVER_ADDR server address, default: 0.0.0.0
-p SERVER_PORT server port, default: 8388 -p SERVER_PORT server port, default: 8388
@ -304,12 +308,14 @@ Proxy options:
--forbidden-ip IPLIST comma seperated IP list forbidden to connect --forbidden-ip IPLIST comma seperated IP list forbidden to connect
General options: General options:
-h, --help show this help message and exit
-d start/stop/restart daemon mode -d start/stop/restart daemon mode
--pid-file PID_FILE pid file for daemon mode --pid-file PID_FILE pid file for daemon mode
--log-file LOG_FILE log file for daemon mode --log-file LOG_FILE log file for daemon mode
--user USER username to run as --user USER username to run as
-v, -vv verbose mode -v, -vv verbose mode
-q, -qq quiet mode, only show warnings/errors -q, -qq quiet mode, only show warnings/errors
--version show version information
Online help: <https://github.com/shadowsocks/shadowsocks> Online help: <https://github.com/shadowsocks/shadowsocks>
''') ''')

3
tests/test_command.sh

@ -6,6 +6,9 @@ PYTHON="coverage run -a -p"
LOCAL="$PYTHON shadowsocks/local.py" LOCAL="$PYTHON shadowsocks/local.py"
SERVER="$PYTHON shadowsocks/server.py" SERVER="$PYTHON shadowsocks/server.py"
assert "$LOCAL --version 2>&1 | grep Shadowsocks | awk -F\" \" '{print \$1}'" "Shadowsocks"
assert "$SERVER --version 2>&1 | grep Shadowsocks | awk -F\" \" '{print \$1}'" "Shadowsocks"
assert "$LOCAL 2>&1 | grep ERROR" "ERROR: config not specified" assert "$LOCAL 2>&1 | grep ERROR" "ERROR: config not specified"
assert "$LOCAL 2>&1 | grep usage | cut -d: -f1" "usage" assert "$LOCAL 2>&1 | grep usage | cut -d: -f1" "usage"

Loading…
Cancel
Save