Skip to content

Commit

Permalink
rename utils module into shell
Browse files Browse the repository at this point in the history
Since utils is ambiguous, we want to give the module a more
clear role.
  • Loading branch information
clowwindy committed Feb 10, 2015
1 parent cb7062e commit d774286
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions shadowsocks/asyncdns.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import re
import logging

from shadowsocks import common, lru_cache, eventloop, utils
from shadowsocks import common, lru_cache, eventloop, shell


CACHE_SWEEP_INTERVAL = 30
Expand Down Expand Up @@ -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


Expand Down
10 changes: 5 additions & 5 deletions shadowsocks/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import logging
import signal
import time
from shadowsocks import common, utils
from shadowsocks import common, shell

# this module is ported from ShadowVPN daemon.c

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -127,7 +127,7 @@ def handle_exit(signum, _):
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)


Expand All @@ -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')
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions shadowsocks/eventloop.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import logging
from collections import defaultdict

from shadowsocks import utils
from shadowsocks import shell


__all__ = ['EventLoop', 'POLL_NULL', 'POLL_IN', 'POLL_OUT', 'POLL_ERR',
Expand Down Expand Up @@ -225,7 +225,7 @@ def run(self):
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)
Expand Down
8 changes: 4 additions & 4 deletions shadowsocks/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@
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 \
("windows_exe", "console_exe"):
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)

Expand Down Expand Up @@ -65,7 +65,7 @@ def int_handler(signum, _):
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__':
Expand Down
8 changes: 4 additions & 4 deletions shadowsocks/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
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)

Expand Down Expand Up @@ -80,7 +80,7 @@ def int_handler(signum, _):
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:
Expand Down
File renamed without changes.
16 changes: 8 additions & 8 deletions shadowsocks/tcprelay.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
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
Expand Down Expand Up @@ -203,7 +203,7 @@ def _write_to_sock(self, data, sock):
errno.EWOULDBLOCK):
uncomplete = True
else:
utils.print_exception(e)
shell.print_exception(e)
self.destroy()
return False
if uncomplete:
Expand Down Expand Up @@ -257,7 +257,7 @@ def _handle_stage_connecting(self, data):
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()
Expand Down Expand Up @@ -381,7 +381,7 @@ def _handle_dns_resolved(self, result, error):
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()
Expand Down Expand Up @@ -443,7 +443,7 @@ def _on_remote_read(self):
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
Expand Down Expand Up @@ -630,7 +630,7 @@ def _sweep_timeout(self):
# 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
Expand Down Expand Up @@ -663,7 +663,7 @@ def _handle_events(self, events):
# 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:
Expand All @@ -681,7 +681,7 @@ def _handle_events(self, events):
errno.EWOULDBLOCK):
continue
else:
utils.print_exception(e)
shell.print_exception(e)
if self._config['verbose']:
traceback.print_exc()
else:
Expand Down
4 changes: 2 additions & 2 deletions shadowsocks/udprelay.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
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


Expand Down Expand Up @@ -208,7 +208,7 @@ def _handle_server(self):
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)
Expand Down

0 comments on commit d774286

Please sign in to comment.