From f18d6cd2f884297e30e0ec5d17f0ebcebd8afb7c Mon Sep 17 00:00:00 2001 From: clowwindy Date: Thu, 13 Jun 2013 01:01:33 +0800 Subject: [PATCH] compatible with py2exe; lint code --- local.py | 12 ++++++++++-- packaging/py2exe/setup.py | 19 +++++++++++++++++++ server.py | 6 ++++-- 3 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 packaging/py2exe/setup.py diff --git a/local.py b/local.py index 7f385fa..79d1d74 100755 --- a/local.py +++ b/local.py @@ -143,7 +143,14 @@ class Socks5Server(SocketServer.StreamRequestHandler): if __name__ == '__main__': - os.chdir(os.path.dirname(__file__) or '.') + try: + os.chdir(os.path.dirname(__file__) or '.') + except NameError: + # 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) print 'shadowsocks v1.2.2' with open('config.json', 'rb') as f: @@ -170,7 +177,8 @@ if __name__ == '__main__': elif key == '-6': IPv6 = True - logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s', + logging.basicConfig(level=logging.DEBUG, + format='%(asctime)s %(levelname)-8s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', filemode='a+') encrypt.init_table(KEY, METHOD) diff --git a/packaging/py2exe/setup.py b/packaging/py2exe/setup.py new file mode 100644 index 0000000..94ffcb8 --- /dev/null +++ b/packaging/py2exe/setup.py @@ -0,0 +1,19 @@ +from distutils.core import setup +# NOTICE!! +# This setup.py is written for py2exe +# Don't make a python package using this file! + +try: + import py2exe +except ImportError: + pass + +setup(name='shadowsocks', + version='1.2.2', + description='a lightweight tunnel proxy which can help you get through firewalls', + author='clowwindy', + author_email='clowwindy42@gmail.com', + url='https://github.com/clowwindy/shadowsocks', + options = {'py2exe': {'bundle_files': 1, 'compressed': True}}, + windows = [{"script":"local.py", "dest_base": "shadowsocks_local",}], + zipfile = None) diff --git a/server.py b/server.py index 9bf05c4..8c1c564 100755 --- a/server.py +++ b/server.py @@ -105,7 +105,8 @@ class Socks5Server(SocketServer.StreamRequestHandler): addr = self.decrypt( self.rfile.read(ord(self.decrypt(sock.recv(1))))) elif addrtype == 4: - addr = socket.inet_ntop(socket.AF_INET6, self.decrypt(self.rfile.read(16))) + addr = socket.inet_ntop(socket.AF_INET6, + self.decrypt(self.rfile.read(16))) else: # not support logging.warn('addr_type not support') @@ -147,7 +148,8 @@ if __name__ == '__main__': elif key == '-6': IPv6 = True - logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s', + logging.basicConfig(level=logging.DEBUG, + format='%(asctime)s %(levelname)-8s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', filemode='a+') encrypt.init_table(KEY, METHOD)