michael@0: #!/usr/bin/env python michael@0: michael@0: # Copyright (c) 2009 Giampaolo Rodola'. All rights reserved. michael@0: # Use of this source code is governed by a BSD-style license that can be michael@0: # found in the LICENSE file. michael@0: michael@0: import sys michael@0: import os michael@0: import shutil michael@0: import fnmatch michael@0: try: michael@0: from setuptools import setup, Extension michael@0: except ImportError: michael@0: from distutils.core import setup, Extension michael@0: michael@0: michael@0: def clean(): michael@0: """'python setup.py clean' custom command.""" michael@0: def rglob(path, pattern): michael@0: return [os.path.join(dirpath, f) michael@0: for dirpath, dirnames, files in os.walk(path) michael@0: for f in fnmatch.filter(files, pattern)] michael@0: michael@0: for dirname in ('build', 'dist'): michael@0: if os.path.isdir(dirname): michael@0: sys.stdout.write('removing directory: %s\n' % dirname) michael@0: shutil.rmtree(dirname) michael@0: michael@0: for dirpath, dirnames, files in os.walk('.'): michael@0: if dirpath.endswith(('__pycache__', '.egg-info')): michael@0: sys.stdout.write('removing directory %s\n' % dirpath) michael@0: shutil.rmtree(dirpath) michael@0: michael@0: for pattern in ['*.py[co]', '*.s[ol]', '*~', '*.orig', '*.rej', '*.swp']: michael@0: for x in rglob('.', pattern): michael@0: sys.stdout.write('removing file %s\n' % x) michael@0: os.remove(x) michael@0: michael@0: def get_version(): michael@0: INIT = os.path.abspath(os.path.join(os.path.dirname(__file__), michael@0: 'psutil', '__init__.py')) michael@0: f = open(INIT, 'r') michael@0: try: michael@0: for line in f: michael@0: if line.startswith('__version__'): michael@0: ret = eval(line.strip().split(' = ')[1]) michael@0: assert ret.count('.') == 2, ret michael@0: for num in ret.split('.'): michael@0: assert num.isdigit(), ret michael@0: return ret michael@0: else: michael@0: raise ValueError("couldn't find version string") michael@0: finally: michael@0: f.close() michael@0: michael@0: def get_description(): michael@0: README = os.path.abspath(os.path.join(os.path.dirname(__file__), 'README')) michael@0: f = open(README, 'r') michael@0: try: michael@0: return f.read() michael@0: finally: michael@0: f.close() michael@0: michael@0: VERSION = get_version() michael@0: michael@0: michael@0: # POSIX michael@0: if os.name == 'posix': michael@0: posix_extension = Extension('_psutil_posix', michael@0: sources = ['psutil/_psutil_posix.c']) michael@0: # Windows michael@0: if sys.platform.startswith("win32"): michael@0: michael@0: def get_winver(): michael@0: maj, min = sys.getwindowsversion()[0:2] michael@0: return '0x0%s' % ((maj * 100) + min) michael@0: michael@0: extensions = [Extension('_psutil_mswindows', michael@0: sources=['psutil/_psutil_mswindows.c', michael@0: 'psutil/_psutil_common.c', michael@0: 'psutil/arch/mswindows/process_info.c', michael@0: 'psutil/arch/mswindows/process_handles.c', michael@0: 'psutil/arch/mswindows/security.c'], michael@0: define_macros=[('_WIN32_WINNT', get_winver()), michael@0: ('_AVAIL_WINVER_', get_winver())], michael@0: libraries=["psapi", "kernel32", "advapi32", michael@0: "shell32", "netapi32", "iphlpapi", michael@0: "wtsapi32"], michael@0: #extra_compile_args=["/Z7"], michael@0: #extra_link_args=["/DEBUG"] michael@0: )] michael@0: # OS X michael@0: elif sys.platform.startswith("darwin"): michael@0: extensions = [Extension('_psutil_osx', michael@0: sources = ['psutil/_psutil_osx.c', michael@0: 'psutil/_psutil_common.c', michael@0: 'psutil/arch/osx/process_info.c'], michael@0: extra_link_args=['-framework', 'CoreFoundation', michael@0: '-framework', 'IOKit'] michael@0: ), michael@0: posix_extension] michael@0: # FreeBSD michael@0: elif sys.platform.startswith("freebsd"): michael@0: extensions = [Extension('_psutil_bsd', michael@0: sources = ['psutil/_psutil_bsd.c', michael@0: 'psutil/_psutil_common.c', michael@0: 'psutil/arch/bsd/process_info.c'], michael@0: libraries=["devstat"], michael@0: ), michael@0: posix_extension] michael@0: # Linux michael@0: elif sys.platform.startswith("linux"): michael@0: extensions = [Extension('_psutil_linux', michael@0: sources=['psutil/_psutil_linux.c'], michael@0: ), michael@0: posix_extension] michael@0: # Solaris michael@0: elif sys.platform.lower().startswith('sunos'): michael@0: extensions = [Extension('_psutil_sunos', michael@0: sources=['psutil/_psutil_sunos.c'], michael@0: libraries=['kstat', 'nsl'], michael@0: ), michael@0: posix_extension] michael@0: else: michael@0: sys.exit('platform %s is not supported' % sys.platform) michael@0: michael@0: michael@0: def main(): michael@0: # "python setup.py clean" custom command michael@0: if len(sys.argv) > 1 and sys.argv[1] == 'clean': michael@0: return clean() michael@0: michael@0: setup_args = dict( michael@0: name='psutil', michael@0: version=VERSION, michael@0: download_url="http://psutil.googlecode.com/files/psutil-%s.tar.gz" \ michael@0: % VERSION, michael@0: description='A process and system utilities module for Python', michael@0: long_description=get_description(), michael@0: keywords=['ps', 'top', 'kill', 'free', 'lsof', 'netstat', 'nice', michael@0: 'tty', 'ionice', 'uptime', 'taskmgr', 'process', 'df', michael@0: 'iotop', 'iostat', 'ifconfig', 'taskset', 'who', 'pidof', michael@0: 'pmap', 'smem', 'monitoring',], michael@0: author='Giampaolo Rodola', michael@0: author_email='psutil@googlegroups.com', michael@0: maintainer='Giampaolo Rodola', michael@0: maintainer_email='g.rodola gmail com', michael@0: url='http://code.google.com/p/psutil/', michael@0: platforms='Platform Independent', michael@0: license='License :: OSI Approved :: BSD License', michael@0: packages=['psutil'], michael@0: test_suite='test.test_psutil', michael@0: # see: python setup.py register --list-classifiers michael@0: classifiers=[ michael@0: 'Development Status :: 5 - Production/Stable', michael@0: 'Environment :: Console', michael@0: 'Operating System :: MacOS :: MacOS X', michael@0: 'Operating System :: Microsoft', michael@0: 'Operating System :: Microsoft :: Windows :: Windows NT/2000', michael@0: 'Operating System :: POSIX', michael@0: 'Operating System :: POSIX :: Linux', michael@0: 'Operating System :: POSIX :: BSD :: FreeBSD', michael@0: 'Operating System :: POSIX :: SunOS/Solaris', michael@0: 'Operating System :: OS Independent', michael@0: 'Programming Language :: C', michael@0: 'Programming Language :: Python', michael@0: 'Programming Language :: Python :: 2', michael@0: 'Programming Language :: Python :: 2.4', michael@0: 'Programming Language :: Python :: 2.5', michael@0: 'Programming Language :: Python :: 2.6', michael@0: 'Programming Language :: Python :: 2.7', michael@0: 'Programming Language :: Python :: 3', michael@0: 'Programming Language :: Python :: 3.0', michael@0: 'Programming Language :: Python :: 3.1', michael@0: 'Programming Language :: Python :: 3.2', michael@0: 'Programming Language :: Python :: 3.3', michael@0: 'Topic :: System :: Monitoring', michael@0: 'Topic :: System :: Networking', michael@0: 'Topic :: System :: Networking :: Monitoring', michael@0: 'Topic :: System :: Benchmark', michael@0: 'Topic :: System :: Hardware', michael@0: 'Topic :: System :: Systems Administration', michael@0: 'Topic :: Utilities', michael@0: 'Topic :: Software Development :: Libraries', michael@0: 'Topic :: Software Development :: Libraries :: Python Modules', michael@0: 'Intended Audience :: Developers', michael@0: 'Intended Audience :: System Administrators', michael@0: 'License :: OSI Approved :: BSD License', michael@0: ], michael@0: ) michael@0: if extensions is not None: michael@0: setup_args["ext_modules"] = extensions michael@0: setup(**setup_args) michael@0: michael@0: if __name__ == '__main__': michael@0: main()