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:
94
setup.py
94
setup.py
@@ -6,9 +6,7 @@ import shutil
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from setuptools import setup, find_packages
|
from setuptools import setup, find_packages, Command
|
||||||
from setuptools.command.install import install
|
|
||||||
from setuptools.command.develop import develop
|
|
||||||
|
|
||||||
from packstack import version
|
from packstack import version
|
||||||
|
|
||||||
@@ -20,56 +18,51 @@ MODULES_REPO = ('https://github.com/redhat-openstack/'
|
|||||||
MODULES_BRANCH = 'master'
|
MODULES_BRANCH = 'master'
|
||||||
|
|
||||||
|
|
||||||
def install_modules(repo, branch, destination):
|
class InstallModulesCommand(Command):
|
||||||
basedir = os.path.dirname(destination.rstrip(' /'))
|
description = 'install Puppet modules required to run Packstack'
|
||||||
repodir = os.path.basename(destination)
|
user_options = [
|
||||||
# install third-party modules from openstack-puppet-modules repo
|
('destination=', None, 'Directory where to install modules'),
|
||||||
if not os.path.exists(destination):
|
('branch=', None, 'Branch which should be used'),
|
||||||
os.makedirs(basedir, 0755)
|
]
|
||||||
|
|
||||||
print 'Cloning %(repo)s to %(destination)s' % locals()
|
def initialize_options(self):
|
||||||
cmd = ('cd %(basedir)s; git clone %(repo)s %(repodir)s; '
|
self.destination = None
|
||||||
'cd %(repodir)s; git checkout %(branch)s; '
|
self.branch = None
|
||||||
'git submodule update --init' % locals())
|
self.repo = MODULES_REPO
|
||||||
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
|
|
||||||
stderr=subprocess.PIPE)
|
|
||||||
out, err = proc.communicate()
|
|
||||||
if proc.returncode:
|
|
||||||
raise RuntimeError('Failed:\n%s' % err)
|
|
||||||
# install Packstack module
|
|
||||||
packstack_path = os.path.join(destination, 'packstack')
|
|
||||||
print 'Copying Packstack module to %(packstack_path)s' % locals()
|
|
||||||
source = os.path.join(os.path.dirname(__file__),
|
|
||||||
'packstack/puppet/modules/packstack')
|
|
||||||
shutil.rmtree(packstack_path, ignore_errors=True)
|
|
||||||
shutil.copytree(source, packstack_path)
|
|
||||||
|
|
||||||
|
def finalize_options(self):
|
||||||
|
self.destination = self.destination or MODULES_DIR
|
||||||
|
self.branch = self.branch or MODULES_BRANCH
|
||||||
|
|
||||||
class WithModulesInstall(install):
|
|
||||||
def run(self):
|
def run(self):
|
||||||
# Code below is from setuptools to make command work exactly
|
destination = self.destination
|
||||||
# as original
|
basedir = os.path.dirname(self.destination.rstrip(' /'))
|
||||||
caller = sys._getframe(2)
|
repodir = os.path.basename(self.destination.rstrip(' /'))
|
||||||
caller_module = caller.f_globals.get('__name__', '')
|
repo = self.repo
|
||||||
caller_name = caller.f_code.co_name
|
branch = self.branch
|
||||||
if caller_module != 'distutils.dist' or caller_name != 'run_commands':
|
# install third-party modules from openstack-puppet-modules repo
|
||||||
install.run(self)
|
if not os.path.exists(self.destination):
|
||||||
else:
|
try:
|
||||||
install.do_egg_install(self)
|
os.makedirs(basedir, 0755)
|
||||||
|
except OSError:
|
||||||
# install Puppet modules if they don't exist
|
# base directory exists
|
||||||
if hasattr(sys.stdout, 'isatty') and sys.stdout.isatty():
|
pass
|
||||||
install_modules(MODULES_REPO, MODULES_BRANCH, MODULES_DIR)
|
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; '
|
||||||
class WithModulesDevelop(develop):
|
'git submodule update --init' % locals())
|
||||||
def run(self):
|
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
|
||||||
# super doesn't work here because distutils.cmd.Command
|
stderr=subprocess.PIPE)
|
||||||
# is old-style class
|
out, err = proc.communicate()
|
||||||
develop.run(self)
|
if proc.returncode:
|
||||||
# install Puppet modules if they don't exist
|
raise RuntimeError('Failed:\n%s' % err)
|
||||||
if hasattr(sys.stdout, 'isatty') and sys.stdout.isatty():
|
# install Packstack module
|
||||||
install_modules(MODULES_REPO, MODULES_BRANCH, MODULES_DIR)
|
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')
|
||||||
|
shutil.rmtree(packstack_path, ignore_errors=True)
|
||||||
|
shutil.copytree(source, packstack_path)
|
||||||
|
|
||||||
|
|
||||||
# Utility function to read the README file.
|
# Utility function to read the README file.
|
||||||
@@ -81,8 +74,6 @@ def read(fname):
|
|||||||
|
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
cmdclass={'install': WithModulesInstall, 'develop': WithModulesDevelop},
|
|
||||||
|
|
||||||
name="packstack",
|
name="packstack",
|
||||||
version=version.version_string(),
|
version=version.version_string(),
|
||||||
author="Derek Higgins",
|
author="Derek Higgins",
|
||||||
@@ -102,4 +93,5 @@ setup(
|
|||||||
"License :: OSI Approved :: Apache Software License",
|
"License :: OSI Approved :: Apache Software License",
|
||||||
],
|
],
|
||||||
scripts=["bin/packstack"],
|
scripts=["bin/packstack"],
|
||||||
|
cmdclass={'install_puppet_modules': InstallModulesCommand}
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user