Browse Source

rename utils module into shell

Since utils is ambiguous, we want to give the module a more
clear role.
master
clowwindy 10 years ago
parent
commit
d774286dc0
  1. 4
      shadowsocks/asyncdns.py
  2. 10
      shadowsocks/daemon.py
  3. 4
      shadowsocks/eventloop.py
  4. 8
      shadowsocks/local.py
  5. 8
      shadowsocks/server.py
  6. 0
      shadowsocks/shell.py
  7. 16
      shadowsocks/tcprelay.py
  8. 4
      shadowsocks/udprelay.py

4
shadowsocks/asyncdns.py

@ -25,7 +25,7 @@ import struct
import re
import logging
from shadowsocks import common, lru_cache, eventloop, utils
from shadowsocks import common, lru_cache, eventloop, shell
CACHE_SWEEP_INTERVAL = 30
@ -221,7 +221,7 @@ def parse_response(data):
response.answers.append((an[1], an[2], an[3]))
return response
except Exception as e:
utils.print_exception(e)
shell.print_exception(e)
return None

10
shadowsocks/daemon.py

@ -23,7 +23,7 @@ import sys
import logging
import signal
import time
from shadowsocks import common, utils
from shadowsocks import common, shell
# this module is ported from ShadowVPN daemon.c
@ -58,7 +58,7 @@ def write_pid_file(pid_file, pid):
fd = os.open(pid_file, os.O_RDWR | os.O_CREAT,
stat.S_IRUSR | stat.S_IWUSR)
except OSError as e:
utils.print_exception(e)
shell.print_exception(e)
return -1
flags = fcntl.fcntl(fd, fcntl.F_GETFD)
assert flags != -1
@ -127,7 +127,7 @@ def daemon_start(pid_file, log_file):
freopen(log_file, 'a', sys.stdout)
freopen(log_file, 'a', sys.stderr)
except IOError as e:
utils.print_exception(e)
shell.print_exception(e)
sys.exit(1)
@ -140,7 +140,7 @@ def daemon_stop(pid_file):
if not buf:
logging.error('not running')
except IOError as e:
utils.print_exception(e)
shell.print_exception(e)
if e.errno == errno.ENOENT:
# always exit 0 if we are sure daemon is not running
logging.error('not running')
@ -155,7 +155,7 @@ def daemon_stop(pid_file):
logging.error('not running')
# always exit 0 if we are sure daemon is not running
return
utils.print_exception(e)
shell.print_exception(e)
sys.exit(1)
else:
logging.error('pid is not positive: %d', pid)

4
shadowsocks/eventloop.py

@ -28,7 +28,7 @@ import errno
import logging
from collections import defaultdict
from shadowsocks import utils
from shadowsocks import shell
__all__ = ['EventLoop', 'POLL_NULL', 'POLL_IN', 'POLL_OUT', 'POLL_ERR',
@ -225,7 +225,7 @@ class EventLoop(object):
try:
handler(events)
except (OSError, IOError) as e:
utils.print_exception(e)
shell.print_exception(e)
if self._handlers_to_remove:
for handler in self._handlers_to_remove:
self._handlers.remove(handler)

8
shadowsocks/local.py

@ -24,11 +24,11 @@ import logging
import signal
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../'))
from shadowsocks import utils, daemon, eventloop, tcprelay, udprelay, asyncdns
from shadowsocks import shell, daemon, eventloop, tcprelay, udprelay, asyncdns
def main():
utils.check_python()
shell.check_python()
# fix py2exe
if hasattr(sys, "frozen") and sys.frozen in \
@ -36,7 +36,7 @@ def main():
p = os.path.dirname(os.path.abspath(sys.executable))
os.chdir(p)
config = utils.get_config(True)
config = shell.get_config(True)
daemon.daemon_exec(config)
@ -65,7 +65,7 @@ def main():
daemon.set_user(config.get('user', None))
loop.run()
except Exception as e:
utils.print_exception(e)
shell.print_exception(e)
sys.exit(1)
if __name__ == '__main__':

8
shadowsocks/server.py

@ -24,13 +24,13 @@ import logging
import signal
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../'))
from shadowsocks import utils, daemon, eventloop, tcprelay, udprelay, asyncdns
from shadowsocks import shell, daemon, eventloop, tcprelay, udprelay, asyncdns
def main():
utils.check_python()
shell.check_python()
config = utils.get_config(False)
config = shell.get_config(False)
daemon.daemon_exec(config)
@ -80,7 +80,7 @@ def main():
daemon.set_user(config.get('user', None))
loop.run()
except Exception as e:
utils.print_exception(e)
shell.print_exception(e)
sys.exit(1)
if int(config['workers']) > 1:

0
shadowsocks/utils.py → shadowsocks/shell.py

16
shadowsocks/tcprelay.py

@ -26,7 +26,7 @@ import logging
import traceback
import random
from shadowsocks import encrypt, eventloop, utils, common
from shadowsocks import encrypt, eventloop, shell, common
from shadowsocks.common import parse_header
# we clear at most TIMEOUTS_CLEAN_SIZE timeouts each time
@ -203,7 +203,7 @@ class TCPRelayHandler(object):
errno.EWOULDBLOCK):
uncomplete = True
else:
utils.print_exception(e)
shell.print_exception(e)
self.destroy()
return False
if uncomplete:
@ -257,7 +257,7 @@ class TCPRelayHandler(object):
self._config['fast_open'] = False
self.destroy()
else:
utils.print_exception(e)
shell.print_exception(e)
if self._config['verbose']:
traceback.print_exc()
self.destroy()
@ -381,7 +381,7 @@ class TCPRelayHandler(object):
self._update_stream(STREAM_DOWN, WAIT_STATUS_READING)
return
except Exception as e:
utils.print_exception(e)
shell.print_exception(e)
if self._config['verbose']:
traceback.print_exc()
self.destroy()
@ -443,7 +443,7 @@ class TCPRelayHandler(object):
try:
self._write_to_sock(data, self._local_sock)
except Exception as e:
utils.print_exception(e)
shell.print_exception(e)
if self._config['verbose']:
traceback.print_exc()
# TODO use logging when debug completed
@ -630,7 +630,7 @@ class TCPRelay(object):
# we just need a sorted last_activity queue and it's faster than heapq
# in fact we can do O(1) insertion/remove so we invent our own
if self._timeouts:
logging.log(utils.VERBOSE_LEVEL, 'sweeping timeouts')
logging.log(shell.VERBOSE_LEVEL, 'sweeping timeouts')
now = time.time()
length = len(self._timeouts)
pos = self._timeout_offset
@ -663,7 +663,7 @@ class TCPRelay(object):
# handle events and dispatch to handlers
for sock, fd, event in events:
if sock:
logging.log(utils.VERBOSE_LEVEL, 'fd %d %s', fd,
logging.log(shell.VERBOSE_LEVEL, 'fd %d %s', fd,
eventloop.EVENT_NAMES.get(event, event))
if sock == self._server_socket:
if event & eventloop.POLL_ERR:
@ -681,7 +681,7 @@ class TCPRelay(object):
errno.EWOULDBLOCK):
continue
else:
utils.print_exception(e)
shell.print_exception(e)
if self._config['verbose']:
traceback.print_exc()
else:

4
shadowsocks/udprelay.py

@ -69,7 +69,7 @@ import struct
import errno
import random
from shadowsocks import encrypt, eventloop, lru_cache, common, utils
from shadowsocks import encrypt, eventloop, lru_cache, common, shell
from shadowsocks.common import parse_header, pack_addr
@ -208,7 +208,7 @@ class UDPRelay(object):
if err in (errno.EINPROGRESS, errno.EAGAIN):
pass
else:
utils.print_exception(e)
shell.print_exception(e)
def _handle_client(self, sock):
data, r_addr = sock.recvfrom(BUF_SIZE)

Loading…
Cancel
Save