1# Copyright (C) 2007 Giampaolo Rodola' <g.rodola@gmail.com>. 2# Use of this source code is governed by MIT license that can be 3# found in the LICENSE file. 4 5"""pyftpdlib installer. 6 7$ python setup.py install 8""" 9 10from __future__ import print_function 11import os 12import sys 13import textwrap 14try: 15 from setuptools import setup 16except ImportError: 17 from distutils.core import setup 18 19 20def get_version(): 21 INIT = os.path.abspath(os.path.join(os.path.dirname(__file__), 22 'pyftpdlib', '__init__.py')) 23 with open(INIT, 'r') as f: 24 for line in f: 25 if line.startswith('__ver__'): 26 ret = eval(line.strip().split(' = ')[1]) 27 assert ret.count('.') == 2, ret 28 for num in ret.split('.'): 29 assert num.isdigit(), ret 30 return ret 31 raise ValueError("couldn't find version string") 32 33 34def term_supports_colors(): 35 try: 36 import curses 37 assert sys.stderr.isatty() 38 curses.setupterm() 39 assert curses.tigetnum("colors") > 0 40 except Exception: 41 return False 42 else: 43 return True 44 45 46def hilite(s, ok=True, bold=False): 47 """Return an highlighted version of 's'.""" 48 if not term_supports_colors(): 49 return s 50 else: 51 attr = [] 52 if ok is None: # no color 53 pass 54 elif ok: 55 attr.append('32') # green 56 else: 57 attr.append('31') # red 58 if bold: 59 attr.append('1') 60 return '\x1b[%sm%s\x1b[0m' % (';'.join(attr), s) 61 62 63if sys.version_info < (2, 6): 64 sys.exit('python version not supported (< 2.6)') 65 66require_pysendfile = (os.name == 'posix' and sys.version_info < (3, 3)) 67 68extras_require = {'ssl': ["PyOpenSSL"]} 69if require_pysendfile: 70 extras_require.update({'sendfile': ['pysendfile']}) 71 72VERSION = get_version() 73 74 75def main(): 76 setup( 77 name='pyftpdlib', 78 version=get_version(), 79 description='Very fast asynchronous FTP server library', 80 long_description=open('README.rst').read(), 81 license='MIT', 82 platforms='Platform Independent', 83 author="Giampaolo Rodola'", 84 author_email='g.rodola@gmail.com', 85 url='https://github.com/giampaolo/pyftpdlib/', 86 packages=['pyftpdlib', 'pyftpdlib.test'], 87 scripts=['scripts/ftpbench'], 88 package_data={ 89 "pyftpdlib.test": [ 90 "README", 91 'keycert.pem', 92 ], 93 }, 94 keywords=['ftp', 'ftps', 'server', 'ftpd', 'daemon', 'python', 'ssl', 95 'sendfile', 'asynchronous', 'nonblocking', 'eventdriven', 96 'rfc959', 'rfc1123', 'rfc2228', 'rfc2428', 'rfc2640', 97 'rfc3659'], 98 extras_require=extras_require, 99 classifiers=[ 100 'Development Status :: 5 - Production/Stable', 101 'Environment :: Console', 102 'Intended Audience :: Developers', 103 'Intended Audience :: System Administrators', 104 'License :: OSI Approved :: MIT License', 105 'Operating System :: OS Independent', 106 'Programming Language :: Python', 107 'Topic :: Internet :: File Transfer Protocol (FTP)', 108 'Topic :: Software Development :: Libraries :: Python Modules', 109 'Topic :: System :: Filesystems', 110 'Programming Language :: Python', 111 'Programming Language :: Python :: 2', 112 'Programming Language :: Python :: 2.6', 113 'Programming Language :: Python :: 2.7', 114 'Programming Language :: Python :: 3', 115 'Programming Language :: Python :: 3.4', 116 'Programming Language :: Python :: 3.5', 117 'Programming Language :: Python :: 3.6', 118 ], 119 ) 120 121 # suggest to install pysendfile 122 if require_pysendfile: 123 try: 124 # os.sendfile() appeared in python 3.3 125 # http://bugs.python.org/issue10882 126 if not hasattr(os, 'sendfile'): 127 # fallback on using third-party pysendfile module 128 # https://github.com/giampaolo/pysendfile/ 129 import sendfile 130 if hasattr(sendfile, 'has_sf_hdtr'): # old 1.2.4 version 131 raise ImportError 132 except ImportError: 133 msg = textwrap.dedent(""" 134 'pysendfile' third-party module is not installed. This is not 135 essential but it considerably speeds up file transfers. 136 You can install it with 'pip install pysendfile'. 137 More at: https://github.com/giampaolo/pysendfile""") 138 print(hilite(msg, ok=False), file=sys.stderr) 139 140 try: 141 from OpenSSL import SSL # NOQA 142 except ImportError: 143 msg = textwrap.dedent(""" 144 'pyopenssl' third-party module is not installed. This means 145 FTPS support will be disabled. You can install it with: 146 'pip install pyopenssl'.""") 147 print(hilite(msg, ok=False), file=sys.stderr) 148 149 150if __name__ == '__main__': 151 main() 152