2013-05-03 08:14:14 +04:00
#!/usr/bin/env python
2014-01-02 20:51:43 +04:00
# Copyright (c) 2014 AnsibleWorks, Inc.
2013-05-22 02:20:26 +04:00
# All Rights Reserved.
2014-07-21 21:45:26 +04:00
import os , datetime , glob , sys , shutil
2013-06-26 03:46:12 +04:00
from distutils import log
2013-05-03 08:14:14 +04:00
from setuptools import setup , find_packages
2013-06-26 03:46:12 +04:00
from setuptools . command . sdist import sdist as _sdist
2013-06-23 21:21:02 +04:00
from awx import __version__
2013-05-03 08:14:14 +04:00
2014-10-17 17:01:45 +04:00
if os . getenv ( ' OFFICIAL ' , ' no ' ) == ' yes ' :
build_timestamp = ' '
else :
build_timestamp = ' - ' + os . getenv ( " BUILD " , datetime . datetime . now ( ) . strftime ( ' 0.git % Y % m %d % H % M ' ) )
2013-05-22 01:39:34 +04:00
2013-06-15 12:10:11 +04:00
# Paths we'll use later
2014-07-17 23:02:56 +04:00
etcpath = " /etc/tower "
2013-06-23 21:21:02 +04:00
homedir = " /var/lib/awx "
2014-04-15 23:41:13 +04:00
sharedir = " /usr/share/awx "
2014-07-29 19:44:36 +04:00
munin_plugin_path = " /etc/munin/plugins/ "
munin_plugin_conf_path = " /etc/munin/plugin-conf.d "
2013-06-15 12:10:11 +04:00
if os . path . exists ( " /etc/debian_version " ) :
2014-07-31 18:39:59 +04:00
sysinit = " /etc/init.d "
2013-06-15 12:10:11 +04:00
webconfig = " /etc/apache2/conf.d "
2014-07-21 21:45:26 +04:00
shutil . copy ( " config/awx-munin-ubuntu.conf " , " config/awx-munin.conf " )
2014-08-14 17:17:35 +04:00
# sosreport-3.1 (and newer) look in '/usr/share/sosreport/sos/plugins'
# sosreport-3.0 looks in '/usr/lib/python2.7/dist-packages/sos/plugins'
# debian/<package>.links will create symlinks to support both versions
sosconfig = " /usr/share/sosreport/sos/plugins "
2013-06-15 12:10:11 +04:00
else :
2014-07-31 18:39:59 +04:00
sysinit = " /etc/rc.d/init.d "
2013-06-15 12:10:11 +04:00
webconfig = " /etc/httpd/conf.d "
2014-07-21 21:45:26 +04:00
shutil . copy ( " config/awx-munin-el.conf " , " config/awx-munin.conf " )
2014-08-14 17:17:35 +04:00
# The .spec will create symlinks to support multiple versions of sosreport
sosconfig = " /usr/share/sosreport/sos/plugins "
2013-06-15 12:10:11 +04:00
#####################################################################
# Helper Functions
def explode_glob_path ( path ) :
""" Take a glob and hand back the full recursive expansion,
ignoring links .
"""
result = [ ]
includes = glob . glob ( path )
for item in includes :
if os . path . isdir ( item ) and not os . path . islink ( item ) :
result . extend ( explode_glob_path ( os . path . join ( item , " * " ) ) )
else :
result . append ( item )
return result
def proc_data_files ( data_files ) :
""" Because data_files doesn ' t natively support globs...
let ' s add them.
"""
result = [ ]
2013-06-23 00:27:09 +04:00
2013-06-23 00:30:17 +04:00
# If running in a virtualenv, don't return data files that would install to
2013-06-23 00:27:09 +04:00
# system paths (mainly useful for running tests via tox).
if hasattr ( sys , ' real_prefix ' ) :
return result
2014-04-15 23:41:13 +04:00
2013-06-15 12:10:11 +04:00
for dir , files in data_files :
includes = [ ]
for item in files :
includes . extend ( explode_glob_path ( item ) )
result . append ( ( dir , includes ) )
return result
#####################################################################
2014-10-17 17:01:45 +04:00
class sdist_pyc_only ( _sdist , object ) :
2013-06-26 03:46:12 +04:00
'''
Custom sdist command to distribute some files as . pyc only .
'''
def make_release_tree ( self , base_dir , files ) :
for f in files [ : ] :
if f . endswith ( ' .egg-info/SOURCES.txt ' ) :
files . remove ( f )
sources_txt_path = f
2014-10-17 17:01:45 +04:00
super ( sdist_pyc_only , self ) . make_release_tree ( base_dir , files )
2013-06-26 03:46:12 +04:00
new_sources_path = os . path . join ( base_dir , sources_txt_path )
if os . path . isfile ( new_sources_path ) :
log . warn ( ' unlinking previous %s ' , new_sources_path )
os . unlink ( new_sources_path )
log . info ( ' writing new %s ' , new_sources_path )
new_sources = file ( new_sources_path , ' w ' )
for line in file ( sources_txt_path , ' r ' ) :
line = line . strip ( )
if line in self . pyc_only_files :
2014-05-22 19:25:50 +04:00
line = line + ' c '
2013-06-26 03:46:12 +04:00
new_sources . write ( line + ' \n ' )
def make_distribution ( self ) :
self . pyc_only_files = [ ]
import py_compile
for n , f in enumerate ( self . filelist . files [ : ] ) :
if not f . startswith ( ' awx/ ' ) :
continue
if f . startswith ( ' awx/lib/site-packages ' ) :
continue
if f . startswith ( ' awx/scripts ' ) :
continue
if f . startswith ( ' awx/plugins ' ) :
continue
2013-12-19 01:35:32 +04:00
if f . startswith ( ' awx/main/tests/data ' ) :
continue
2013-06-26 03:46:12 +04:00
if f . endswith ( ' .py ' ) :
log . info ( ' using pyc for: %s ' , f )
2014-05-14 20:20:23 +04:00
# Byte compile to create .pyc file
2013-06-26 03:46:12 +04:00
py_compile . compile ( f , doraise = True )
2014-05-14 20:20:23 +04:00
# Replace .py with .pyc file
2013-06-26 03:46:12 +04:00
self . filelist . files [ n ] = f + ' c '
self . pyc_only_files . append ( f )
2014-10-17 17:01:45 +04:00
super ( sdist_pyc_only , self ) . make_distribution ( )
2013-06-26 03:46:12 +04:00
2014-05-12 22:21:51 +04:00
#####################################################################
from distutils . command . install_lib import install_lib as _install_lib
class install_lib ( _install_lib , object ) :
'''
Custom install_lib command to distribute some files as . pyc only .
'''
def run ( self ) :
'''
Overload the run method and remove all . py files after compilation
'''
super ( install_lib , self ) . run ( )
for f in self . install ( ) :
if not f . startswith ( self . install_dir + ' awx/ ' ) :
log . debug ( ' install_lib skipping: %s ' , f )
continue
if f . startswith ( self . install_dir + ' awx/lib/site-packages ' ) :
log . debug ( ' install_lib skipping: %s ' , f )
continue
if f . startswith ( self . install_dir + ' awx/scripts ' ) :
log . debug ( ' install_lib skipping: %s ' , f )
continue
if f . startswith ( self . install_dir + ' awx/plugins ' ) :
log . debug ( ' install_lib skipping: %s ' , f )
continue
if f . startswith ( self . install_dir + ' awx/main/tests/data ' ) :
log . debug ( ' install_lib skipping: %s ' , f )
continue
if f . endswith ( ' .py ' ) :
2014-10-18 22:40:43 +04:00
log . info ( ' install_lib removing: %s ' , f )
2014-05-12 22:21:51 +04:00
os . unlink ( f )
def get_outputs ( self ) :
'''
Overload the get_outputs method and remove any . py entries in the file
list
'''
filenames = super ( install_lib , self ) . get_outputs ( )
return [ filename for filename in filenames
if not filename . endswith ( ' .py ' ) ]
#####################################################################
2013-05-03 08:14:14 +04:00
setup (
2014-01-29 21:30:12 +04:00
name = ' ansible-tower ' ,
2013-06-20 12:20:48 +04:00
version = __version__ . split ( " - " ) [ 0 ] , # FIXME: Should keep full version here?
2014-01-29 21:30:12 +04:00
author = ' Ansible, Inc. ' ,
author_email = ' support@ansible.com ' ,
description = ' ansible-tower: API, UI and Task Engine for Ansible ' ,
2013-06-23 21:21:02 +04:00
long_description = ' AWX provides a web-based user interface, REST API and '
' task engine built on top of Ansible ' ,
2013-05-03 08:14:14 +04:00
license = ' Proprietary ' ,
keywords = ' ansible ' ,
url = ' http://github.com/ansible/ansible-commander ' ,
2013-06-23 21:21:02 +04:00
packages = [ ' awx ' ] ,
2013-05-03 08:14:14 +04:00
include_package_data = True ,
zip_safe = False ,
setup_requires = [ ] ,
classifiers = [
2013-09-25 05:40:53 +04:00
' Development Status :: 5 - Production/Stable ' ,
2013-05-03 08:14:14 +04:00
' Environment :: Web Environment ' ,
' Framework :: Django ' ,
' Intended Audience :: Developers ' ,
' Intended Audience :: Information Technology ' ,
' Intended Audience :: System Administrators '
' License :: Other/Proprietary License ' ,
' Natural Language :: English ' ,
' Operating System :: OS Independent ' ,
' Operating System :: POSIX ' ,
' Programming Language :: Python ' ,
' Topic :: System :: Installation/Setup ' ,
' Topic :: System :: Systems Administration ' ,
] ,
entry_points = {
' console_scripts ' : [
2013-06-23 21:21:02 +04:00
' awx-manage = awx:manage ' ,
2014-07-30 20:56:58 +04:00
' tower-manage = awx:manage ' ,
2013-05-03 08:14:14 +04:00
] ,
} ,
2013-06-15 12:10:11 +04:00
data_files = proc_data_files ( [
2013-06-24 21:03:33 +04:00
( " %s " % homedir , [ " config/wsgi.py " ,
2013-06-23 21:21:02 +04:00
" awx/static/favicon.ico " ,
2013-06-15 12:10:11 +04:00
] ) ,
2014-03-10 20:08:37 +04:00
( " %s " % webconfig , [ " config/awx-httpd-80.conf " ,
" config/awx-httpd-443.conf " ,
2014-07-21 21:45:26 +04:00
" config/awx-munin.conf " ,
2014-03-10 20:08:37 +04:00
] ) ,
2014-07-29 20:37:51 +04:00
( " %s " % sharedir , [ " tools/scripts/request_tower_configuration.sh " , ] ) ,
2014-07-31 00:57:43 +04:00
( " %s " % munin_plugin_path , [ " tools/munin_monitors/tower_jobs " ,
" tools/munin_monitors/callbackr_alive " ,
" tools/munin_monitors/celery_alive " ,
" tools/munin_monitors/postgres_alive " ,
" tools/munin_monitors/rabbit_alive " ,
" tools/munin_monitors/socketio_alive " ,
" tools/munin_monitors/taskmanager_alive " ] ) ,
2014-07-29 19:44:36 +04:00
( " %s " % munin_plugin_conf_path , [ " config/awx_munin_tower_jobs " ] ) ,
2014-07-30 21:18:42 +04:00
( " %s " % sysinit , [ " tools/scripts/ansible-tower " ] ) ,
2014-08-13 16:48:40 +04:00
( " %s " % sosconfig , [ " tools/sosreport/tower.py " ] ) ,
2013-06-15 12:10:11 +04:00
]
) ,
2013-06-26 03:46:12 +04:00
options = {
2013-05-03 08:14:14 +04:00
' egg_info ' : {
2014-10-17 17:01:45 +04:00
' tag_build ' : build_timestamp ,
2013-05-03 08:14:14 +04:00
} ,
' aliases ' : {
2014-10-17 17:01:45 +04:00
' dev_build ' : ' clean --all egg_info sdist ' ,
' release_build ' : ' clean --all egg_info -b " " sdist ' ,
2013-05-03 08:14:14 +04:00
} ,
} ,
2013-06-26 03:46:12 +04:00
cmdclass = {
2014-10-17 17:01:45 +04:00
' sdist ' : os . getenv ( ' BYTE_COMPILE ' , False ) in ( True , 1 , ' True ' , ' 1 ' ) and sdist_pyc_only or _sdist ,
2014-05-12 22:21:51 +04:00
' install_lib ' : install_lib ,
2013-06-26 03:46:12 +04:00
} ,
2013-05-03 08:14:14 +04:00
)