Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | #!/usr/bin/env python |
michael@0 | 2 | |
michael@0 | 3 | # Copyright (c) 2009 Giampaolo Rodola'. All rights reserved. |
michael@0 | 4 | # Use of this source code is governed by a BSD-style license that can be |
michael@0 | 5 | # found in the LICENSE file. |
michael@0 | 6 | |
michael@0 | 7 | import sys |
michael@0 | 8 | import os |
michael@0 | 9 | import shutil |
michael@0 | 10 | import fnmatch |
michael@0 | 11 | try: |
michael@0 | 12 | from setuptools import setup, Extension |
michael@0 | 13 | except ImportError: |
michael@0 | 14 | from distutils.core import setup, Extension |
michael@0 | 15 | |
michael@0 | 16 | |
michael@0 | 17 | def clean(): |
michael@0 | 18 | """'python setup.py clean' custom command.""" |
michael@0 | 19 | def rglob(path, pattern): |
michael@0 | 20 | return [os.path.join(dirpath, f) |
michael@0 | 21 | for dirpath, dirnames, files in os.walk(path) |
michael@0 | 22 | for f in fnmatch.filter(files, pattern)] |
michael@0 | 23 | |
michael@0 | 24 | for dirname in ('build', 'dist'): |
michael@0 | 25 | if os.path.isdir(dirname): |
michael@0 | 26 | sys.stdout.write('removing directory: %s\n' % dirname) |
michael@0 | 27 | shutil.rmtree(dirname) |
michael@0 | 28 | |
michael@0 | 29 | for dirpath, dirnames, files in os.walk('.'): |
michael@0 | 30 | if dirpath.endswith(('__pycache__', '.egg-info')): |
michael@0 | 31 | sys.stdout.write('removing directory %s\n' % dirpath) |
michael@0 | 32 | shutil.rmtree(dirpath) |
michael@0 | 33 | |
michael@0 | 34 | for pattern in ['*.py[co]', '*.s[ol]', '*~', '*.orig', '*.rej', '*.swp']: |
michael@0 | 35 | for x in rglob('.', pattern): |
michael@0 | 36 | sys.stdout.write('removing file %s\n' % x) |
michael@0 | 37 | os.remove(x) |
michael@0 | 38 | |
michael@0 | 39 | def get_version(): |
michael@0 | 40 | INIT = os.path.abspath(os.path.join(os.path.dirname(__file__), |
michael@0 | 41 | 'psutil', '__init__.py')) |
michael@0 | 42 | f = open(INIT, 'r') |
michael@0 | 43 | try: |
michael@0 | 44 | for line in f: |
michael@0 | 45 | if line.startswith('__version__'): |
michael@0 | 46 | ret = eval(line.strip().split(' = ')[1]) |
michael@0 | 47 | assert ret.count('.') == 2, ret |
michael@0 | 48 | for num in ret.split('.'): |
michael@0 | 49 | assert num.isdigit(), ret |
michael@0 | 50 | return ret |
michael@0 | 51 | else: |
michael@0 | 52 | raise ValueError("couldn't find version string") |
michael@0 | 53 | finally: |
michael@0 | 54 | f.close() |
michael@0 | 55 | |
michael@0 | 56 | def get_description(): |
michael@0 | 57 | README = os.path.abspath(os.path.join(os.path.dirname(__file__), 'README')) |
michael@0 | 58 | f = open(README, 'r') |
michael@0 | 59 | try: |
michael@0 | 60 | return f.read() |
michael@0 | 61 | finally: |
michael@0 | 62 | f.close() |
michael@0 | 63 | |
michael@0 | 64 | VERSION = get_version() |
michael@0 | 65 | |
michael@0 | 66 | |
michael@0 | 67 | # POSIX |
michael@0 | 68 | if os.name == 'posix': |
michael@0 | 69 | posix_extension = Extension('_psutil_posix', |
michael@0 | 70 | sources = ['psutil/_psutil_posix.c']) |
michael@0 | 71 | # Windows |
michael@0 | 72 | if sys.platform.startswith("win32"): |
michael@0 | 73 | |
michael@0 | 74 | def get_winver(): |
michael@0 | 75 | maj, min = sys.getwindowsversion()[0:2] |
michael@0 | 76 | return '0x0%s' % ((maj * 100) + min) |
michael@0 | 77 | |
michael@0 | 78 | extensions = [Extension('_psutil_mswindows', |
michael@0 | 79 | sources=['psutil/_psutil_mswindows.c', |
michael@0 | 80 | 'psutil/_psutil_common.c', |
michael@0 | 81 | 'psutil/arch/mswindows/process_info.c', |
michael@0 | 82 | 'psutil/arch/mswindows/process_handles.c', |
michael@0 | 83 | 'psutil/arch/mswindows/security.c'], |
michael@0 | 84 | define_macros=[('_WIN32_WINNT', get_winver()), |
michael@0 | 85 | ('_AVAIL_WINVER_', get_winver())], |
michael@0 | 86 | libraries=["psapi", "kernel32", "advapi32", |
michael@0 | 87 | "shell32", "netapi32", "iphlpapi", |
michael@0 | 88 | "wtsapi32"], |
michael@0 | 89 | #extra_compile_args=["/Z7"], |
michael@0 | 90 | #extra_link_args=["/DEBUG"] |
michael@0 | 91 | )] |
michael@0 | 92 | # OS X |
michael@0 | 93 | elif sys.platform.startswith("darwin"): |
michael@0 | 94 | extensions = [Extension('_psutil_osx', |
michael@0 | 95 | sources = ['psutil/_psutil_osx.c', |
michael@0 | 96 | 'psutil/_psutil_common.c', |
michael@0 | 97 | 'psutil/arch/osx/process_info.c'], |
michael@0 | 98 | extra_link_args=['-framework', 'CoreFoundation', |
michael@0 | 99 | '-framework', 'IOKit'] |
michael@0 | 100 | ), |
michael@0 | 101 | posix_extension] |
michael@0 | 102 | # FreeBSD |
michael@0 | 103 | elif sys.platform.startswith("freebsd"): |
michael@0 | 104 | extensions = [Extension('_psutil_bsd', |
michael@0 | 105 | sources = ['psutil/_psutil_bsd.c', |
michael@0 | 106 | 'psutil/_psutil_common.c', |
michael@0 | 107 | 'psutil/arch/bsd/process_info.c'], |
michael@0 | 108 | libraries=["devstat"], |
michael@0 | 109 | ), |
michael@0 | 110 | posix_extension] |
michael@0 | 111 | # Linux |
michael@0 | 112 | elif sys.platform.startswith("linux"): |
michael@0 | 113 | extensions = [Extension('_psutil_linux', |
michael@0 | 114 | sources=['psutil/_psutil_linux.c'], |
michael@0 | 115 | ), |
michael@0 | 116 | posix_extension] |
michael@0 | 117 | # Solaris |
michael@0 | 118 | elif sys.platform.lower().startswith('sunos'): |
michael@0 | 119 | extensions = [Extension('_psutil_sunos', |
michael@0 | 120 | sources=['psutil/_psutil_sunos.c'], |
michael@0 | 121 | libraries=['kstat', 'nsl'], |
michael@0 | 122 | ), |
michael@0 | 123 | posix_extension] |
michael@0 | 124 | else: |
michael@0 | 125 | sys.exit('platform %s is not supported' % sys.platform) |
michael@0 | 126 | |
michael@0 | 127 | |
michael@0 | 128 | def main(): |
michael@0 | 129 | # "python setup.py clean" custom command |
michael@0 | 130 | if len(sys.argv) > 1 and sys.argv[1] == 'clean': |
michael@0 | 131 | return clean() |
michael@0 | 132 | |
michael@0 | 133 | setup_args = dict( |
michael@0 | 134 | name='psutil', |
michael@0 | 135 | version=VERSION, |
michael@0 | 136 | download_url="http://psutil.googlecode.com/files/psutil-%s.tar.gz" \ |
michael@0 | 137 | % VERSION, |
michael@0 | 138 | description='A process and system utilities module for Python', |
michael@0 | 139 | long_description=get_description(), |
michael@0 | 140 | keywords=['ps', 'top', 'kill', 'free', 'lsof', 'netstat', 'nice', |
michael@0 | 141 | 'tty', 'ionice', 'uptime', 'taskmgr', 'process', 'df', |
michael@0 | 142 | 'iotop', 'iostat', 'ifconfig', 'taskset', 'who', 'pidof', |
michael@0 | 143 | 'pmap', 'smem', 'monitoring',], |
michael@0 | 144 | author='Giampaolo Rodola', |
michael@0 | 145 | author_email='psutil@googlegroups.com', |
michael@0 | 146 | maintainer='Giampaolo Rodola', |
michael@0 | 147 | maintainer_email='g.rodola <at> gmail <dot> com', |
michael@0 | 148 | url='http://code.google.com/p/psutil/', |
michael@0 | 149 | platforms='Platform Independent', |
michael@0 | 150 | license='License :: OSI Approved :: BSD License', |
michael@0 | 151 | packages=['psutil'], |
michael@0 | 152 | test_suite='test.test_psutil', |
michael@0 | 153 | # see: python setup.py register --list-classifiers |
michael@0 | 154 | classifiers=[ |
michael@0 | 155 | 'Development Status :: 5 - Production/Stable', |
michael@0 | 156 | 'Environment :: Console', |
michael@0 | 157 | 'Operating System :: MacOS :: MacOS X', |
michael@0 | 158 | 'Operating System :: Microsoft', |
michael@0 | 159 | 'Operating System :: Microsoft :: Windows :: Windows NT/2000', |
michael@0 | 160 | 'Operating System :: POSIX', |
michael@0 | 161 | 'Operating System :: POSIX :: Linux', |
michael@0 | 162 | 'Operating System :: POSIX :: BSD :: FreeBSD', |
michael@0 | 163 | 'Operating System :: POSIX :: SunOS/Solaris', |
michael@0 | 164 | 'Operating System :: OS Independent', |
michael@0 | 165 | 'Programming Language :: C', |
michael@0 | 166 | 'Programming Language :: Python', |
michael@0 | 167 | 'Programming Language :: Python :: 2', |
michael@0 | 168 | 'Programming Language :: Python :: 2.4', |
michael@0 | 169 | 'Programming Language :: Python :: 2.5', |
michael@0 | 170 | 'Programming Language :: Python :: 2.6', |
michael@0 | 171 | 'Programming Language :: Python :: 2.7', |
michael@0 | 172 | 'Programming Language :: Python :: 3', |
michael@0 | 173 | 'Programming Language :: Python :: 3.0', |
michael@0 | 174 | 'Programming Language :: Python :: 3.1', |
michael@0 | 175 | 'Programming Language :: Python :: 3.2', |
michael@0 | 176 | 'Programming Language :: Python :: 3.3', |
michael@0 | 177 | 'Topic :: System :: Monitoring', |
michael@0 | 178 | 'Topic :: System :: Networking', |
michael@0 | 179 | 'Topic :: System :: Networking :: Monitoring', |
michael@0 | 180 | 'Topic :: System :: Benchmark', |
michael@0 | 181 | 'Topic :: System :: Hardware', |
michael@0 | 182 | 'Topic :: System :: Systems Administration', |
michael@0 | 183 | 'Topic :: Utilities', |
michael@0 | 184 | 'Topic :: Software Development :: Libraries', |
michael@0 | 185 | 'Topic :: Software Development :: Libraries :: Python Modules', |
michael@0 | 186 | 'Intended Audience :: Developers', |
michael@0 | 187 | 'Intended Audience :: System Administrators', |
michael@0 | 188 | 'License :: OSI Approved :: BSD License', |
michael@0 | 189 | ], |
michael@0 | 190 | ) |
michael@0 | 191 | if extensions is not None: |
michael@0 | 192 | setup_args["ext_modules"] = extensions |
michael@0 | 193 | setup(**setup_args) |
michael@0 | 194 | |
michael@0 | 195 | if __name__ == '__main__': |
michael@0 | 196 | main() |