Use own command for modules
With this patch we will use separate command to install Puppet modules. Subclassing setuptools commands breaks behaviour and IMHO it's impossible to make it work both for build system and from-source-installations Additional fix for rhbz#1063982 Change-Id: Id7eb1c8357339b44ebf72cbfed46265db0dfec33
This commit is contained in:
70
setup.py
70
setup.py
@@ -6,9 +6,7 @@ import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
from setuptools import setup, find_packages
|
||||
from setuptools.command.install import install
|
||||
from setuptools.command.develop import develop
|
||||
from setuptools import setup, find_packages, Command
|
||||
|
||||
from packstack import version
|
||||
|
||||
@@ -20,13 +18,35 @@ MODULES_REPO = ('https://github.com/redhat-openstack/'
|
||||
MODULES_BRANCH = 'master'
|
||||
|
||||
|
||||
def install_modules(repo, branch, destination):
|
||||
basedir = os.path.dirname(destination.rstrip(' /'))
|
||||
repodir = os.path.basename(destination)
|
||||
# install third-party modules from openstack-puppet-modules repo
|
||||
if not os.path.exists(destination):
|
||||
os.makedirs(basedir, 0755)
|
||||
class InstallModulesCommand(Command):
|
||||
description = 'install Puppet modules required to run Packstack'
|
||||
user_options = [
|
||||
('destination=', None, 'Directory where to install modules'),
|
||||
('branch=', None, 'Branch which should be used'),
|
||||
]
|
||||
|
||||
def initialize_options(self):
|
||||
self.destination = None
|
||||
self.branch = None
|
||||
self.repo = MODULES_REPO
|
||||
|
||||
def finalize_options(self):
|
||||
self.destination = self.destination or MODULES_DIR
|
||||
self.branch = self.branch or MODULES_BRANCH
|
||||
|
||||
def run(self):
|
||||
destination = self.destination
|
||||
basedir = os.path.dirname(self.destination.rstrip(' /'))
|
||||
repodir = os.path.basename(self.destination.rstrip(' /'))
|
||||
repo = self.repo
|
||||
branch = self.branch
|
||||
# install third-party modules from openstack-puppet-modules repo
|
||||
if not os.path.exists(self.destination):
|
||||
try:
|
||||
os.makedirs(basedir, 0755)
|
||||
except OSError:
|
||||
# base directory exists
|
||||
pass
|
||||
print 'Cloning %(repo)s to %(destination)s' % locals()
|
||||
cmd = ('cd %(basedir)s; git clone %(repo)s %(repodir)s; '
|
||||
'cd %(repodir)s; git checkout %(branch)s; '
|
||||
@@ -37,7 +57,7 @@ def install_modules(repo, branch, destination):
|
||||
if proc.returncode:
|
||||
raise RuntimeError('Failed:\n%s' % err)
|
||||
# install Packstack module
|
||||
packstack_path = os.path.join(destination, 'packstack')
|
||||
packstack_path = os.path.join(self.destination, 'packstack')
|
||||
print 'Copying Packstack module to %(packstack_path)s' % locals()
|
||||
source = os.path.join(os.path.dirname(__file__),
|
||||
'packstack/puppet/modules/packstack')
|
||||
@@ -45,33 +65,6 @@ def install_modules(repo, branch, destination):
|
||||
shutil.copytree(source, packstack_path)
|
||||
|
||||
|
||||
class WithModulesInstall(install):
|
||||
def run(self):
|
||||
# Code below is from setuptools to make command work exactly
|
||||
# as original
|
||||
caller = sys._getframe(2)
|
||||
caller_module = caller.f_globals.get('__name__', '')
|
||||
caller_name = caller.f_code.co_name
|
||||
if caller_module != 'distutils.dist' or caller_name != 'run_commands':
|
||||
install.run(self)
|
||||
else:
|
||||
install.do_egg_install(self)
|
||||
|
||||
# install Puppet modules if they don't exist
|
||||
if hasattr(sys.stdout, 'isatty') and sys.stdout.isatty():
|
||||
install_modules(MODULES_REPO, MODULES_BRANCH, MODULES_DIR)
|
||||
|
||||
|
||||
class WithModulesDevelop(develop):
|
||||
def run(self):
|
||||
# super doesn't work here because distutils.cmd.Command
|
||||
# is old-style class
|
||||
develop.run(self)
|
||||
# install Puppet modules if they don't exist
|
||||
if hasattr(sys.stdout, 'isatty') and sys.stdout.isatty():
|
||||
install_modules(MODULES_REPO, MODULES_BRANCH, MODULES_DIR)
|
||||
|
||||
|
||||
# Utility function to read the README file.
|
||||
# Used for the long_description. It's nice, because now 1) we have a top level
|
||||
# README file and 2) it's easier to type in the README file than to put a raw
|
||||
@@ -81,8 +74,6 @@ def read(fname):
|
||||
|
||||
|
||||
setup(
|
||||
cmdclass={'install': WithModulesInstall, 'develop': WithModulesDevelop},
|
||||
|
||||
name="packstack",
|
||||
version=version.version_string(),
|
||||
author="Derek Higgins",
|
||||
@@ -102,4 +93,5 @@ setup(
|
||||
"License :: OSI Approved :: Apache Software License",
|
||||
],
|
||||
scripts=["bin/packstack"],
|
||||
cmdclass={'install_puppet_modules': InstallModulesCommand}
|
||||
)
|
||||
|
Reference in New Issue
Block a user