Allow packaging salt-ssh as a package.

This works by passing `--ssh-packaging` to the `sdist` command

```
python setup.py sdist --ssh-packaging
```
This commit is contained in:
Pedro Algarvio 2014-10-01 20:47:03 +01:00
parent de50067a91
commit ec09c5b837

213
setup.py
View file

@ -101,6 +101,10 @@ SALT_CLOUD_REQS = os.path.join(os.path.abspath(SETUP_DIRNAME), 'cloud-requiremen
SALT_RAET_REQS = os.path.join(os.path.abspath(SETUP_DIRNAME), 'raet-requirements.txt') SALT_RAET_REQS = os.path.join(os.path.abspath(SETUP_DIRNAME), 'raet-requirements.txt')
SALT_SYSPATHS = os.path.join(os.path.abspath(SETUP_DIRNAME), 'salt', 'syspaths.py') SALT_SYSPATHS = os.path.join(os.path.abspath(SETUP_DIRNAME), 'salt', 'syspaths.py')
# Salt SSH Packaging Detection
PACKAGED_FOR_SALT_SSH_FILE = os.path.join(os.path.abspath(SETUP_DIRNAME), '.salt-ssh-package')
PACKAGED_FOR_SALT_SSH = os.path.isfile(PACKAGED_FOR_SALT_SSH_FILE)
# pylint: disable=W0122 # pylint: disable=W0122
exec(compile(open(SALT_VERSION).read(), SALT_VERSION, 'exec')) exec(compile(open(SALT_VERSION).read(), SALT_VERSION, 'exec'))
exec(compile(open(SALT_SYSPATHS).read(), SALT_SYSPATHS, 'exec')) exec(compile(open(SALT_SYSPATHS).read(), SALT_SYSPATHS, 'exec'))
@ -150,8 +154,49 @@ class WriteSaltVersion(Command):
# pylint: enable=E0602 # pylint: enable=E0602
class WriteSaltSshPackaingFile(Command):
description = 'Write salt\'s ssh packaging file'
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
if not os.path.exists(PACKAGED_FOR_SALT_SSH_FILE):
# Write the salt-ssh packaging file
if getattr(self.distribution, 'salt_ssh_packaging_file', None) is None:
print 'This command is not meant to be called on it\'s own'
exit(1)
# pylint: disable=E0602
open(self.distribution.salt_ssh_packaging_file, 'w').write('Packaged for Salt-SSH\n')
# pylint: enable=E0602
class Sdist(sdist): class Sdist(sdist):
user_options = sdist.user_options + [
('ssh-packaging', None, 'Prepare the salt-ssh packaging')
]
boolean_options = sdist.boolean_options + [
'ssh-packaging'
]
def initialize_options(self):
sdist.initialize_options(self)
self.ssh_packaging = PACKAGED_FOR_SALT_SSH
def finalize_options(self):
sdist.finalize_options(self)
self.distribution.packaged_for_salt_ssh = self.ssh_packaging
def make_release_tree(self, base_dir, files): def make_release_tree(self, base_dir, files):
if self.ssh_packaging:
self.distribution.salt_ssh_packaging_file = PACKAGED_FOR_SALT_SSH_FILE
self.run_command('write-salt-ssh-packaging-file')
self.distribution.package_data.pop('salt.daemons.flo', None)
sdist.make_release_tree(self, base_dir, files) sdist.make_release_tree(self, base_dir, files)
# Let's generate salt/_version.py to include in the sdist tarball # Let's generate salt/_version.py to include in the sdist tarball
@ -161,16 +206,33 @@ class Sdist(sdist):
) )
self.run_command('write-salt-version') self.run_command('write-salt-version')
def write_manifest(self):
if self.ssh_packaging:
self.filelist.files.append(os.path.basename(PACKAGED_FOR_SALT_SSH_FILE))
self.distribution.metadata.name = 'salt-ssh'
# Only Salt or Salt-SSH must be installed at a time
self.distribution.package_data.pop('salt.daemons.flo')
self.distribution.data_files = [('share/man/man1',
['doc/man/salt-ssh.1',
'doc/man/salt-cloud.1']),
('share/man/man7', ['doc/man/salt.7'])]
sdist.write_manifest(self)
def make_distribution(self):
sdist.make_distribution(self)
if self.ssh_packaging:
os.unlink(PACKAGED_FOR_SALT_SSH_FILE)
class CloudSdist(Sdist): class CloudSdist(Sdist):
user_options = sdist.user_options + [ user_options = Sdist.user_options + [
('download-bootstrap-script', None, ('download-bootstrap-script', None,
'Download the latest stable bootstrap-salt.sh script. This ' 'Download the latest stable bootstrap-salt.sh script. This '
'can also be triggered by having `DOWNLOAD_BOOTSTRAP_SCRIPT=1` as an ' 'can also be triggered by having `DOWNLOAD_BOOTSTRAP_SCRIPT=1` as an '
'environment variable.') 'environment variable.')
] ]
boolean_options = sdist.boolean_options + [ boolean_options = Sdist.boolean_options + [
'download-bootstrap-script' 'download-bootstrap-script'
] ]
@ -268,6 +330,16 @@ class CloudSdist(Sdist):
self.filelist.files.pop( self.filelist.files.pop(
self.filelist.files.index(filename) self.filelist.files.index(filename)
) )
elif self.distribution.packaged_for_salt_ssh:
# Remove un-necessary script from Salt-SSH package
for filename in self.filelist.files[:]:
if not filename.startswith('scripts/'):
continue
if filename not in ('scripts/salt-ssh',
'scripts/salt-cloud'):
self.filelist.files.pop(
self.filelist.files.index(filename)
)
return Sdist.write_manifest(self) return Sdist.write_manifest(self)
@ -405,7 +477,10 @@ class Install(install):
# Non setuptools installation # Non setuptools installation
self.distribution.install_requires = _parse_requirements_file(SALT_REQS) self.distribution.install_requires = _parse_requirements_file(SALT_REQS)
# pylint: disable=E0602 # pylint: disable=E0602
self.salt_transport = 'zeromq' if PACKAGED_FOR_SALT_SSH:
self.salt_transport = 'ssh'
else:
self.salt_transport = 'zeromq'
self.salt_root_dir = ROOT_DIR self.salt_root_dir = ROOT_DIR
self.salt_config_dir = CONFIG_DIR self.salt_config_dir = CONFIG_DIR
self.salt_cache_dir = CACHE_DIR self.salt_cache_dir = CACHE_DIR
@ -420,6 +495,9 @@ class Install(install):
def finalize_options(self): def finalize_options(self):
install.finalize_options(self) install.finalize_options(self)
if PACKAGED_FOR_SALT_SSH and self.salt_transport != 'ssh':
raise DistutilsArgError('The only available transport for salt-ssh is \'ssh\'')
for optname in ('root_dir', 'config_dir', 'cache_dir', 'sock_dir', for optname in ('root_dir', 'config_dir', 'cache_dir', 'sock_dir',
'srv_root_dir', 'base_file_roots_dir', 'srv_root_dir', 'base_file_roots_dir',
'base_pillar_roots_dir', 'base_master_roots_dir', 'base_pillar_roots_dir', 'base_master_roots_dir',
@ -433,19 +511,18 @@ class Install(install):
) )
setattr(self.distribution, 'salt_{0}'.format(optname), optvalue) setattr(self.distribution, 'salt_{0}'.format(optname), optvalue)
if self.salt_transport not in ('zeromq', 'raet', 'both', 'none'): if self.salt_transport not in ('zeromq', 'raet', 'both', 'ssh', 'none'):
raise DistutilsArgError( raise DistutilsArgError(
'The value of --salt-transport needs be \'zeromq\', ' 'The value of --salt-transport needs be \'zeromq\', '
'\'raet\', \'both\' or \'none\' not {0!r}'.format( '\'raet\', \'both\' \'ssh\' or \'none\' not {0!r}'.format(
self.salt_transport self.salt_transport
) )
) )
elif self.salt_transport == 'none': elif self.salt_transport in ('ssh', 'none'):
for requirement in _parse_requirements_file(SALT_ZEROMQ_REQS): for requirement in _parse_requirements_file(SALT_ZEROMQ_REQS):
if requirement not in self.distribution.install_requires: if requirement not in self.distribution.install_requires:
continue continue
self.distribution.install_requires.remove(requirement) self.distribution.install_requires.remove(requirement)
elif self.salt_transport in ('raet', 'both'): elif self.salt_transport in ('raet', 'both'):
self.distribution.install_requires.extend( self.distribution.install_requires.extend(
_parse_requirements_file(SALT_RAET_REQS) _parse_requirements_file(SALT_RAET_REQS)
@ -459,6 +536,7 @@ class Install(install):
def run(self): def run(self):
# Let's set the running_salt_install attribute so we can add # Let's set the running_salt_install attribute so we can add
# _version.py in the build command # _version.py in the build command
print 444, self.salt_transport
self.distribution.running_salt_install = True self.distribution.running_salt_install = True
self.distribution.salt_version_hardcoded_path = os.path.join( self.distribution.salt_version_hardcoded_path = os.path.join(
self.build_lib, 'salt', '_version.py' self.build_lib, 'salt', '_version.py'
@ -489,8 +567,11 @@ class InstallLib(install_lib):
os.chmod(filename, 0755) os.chmod(filename, 0755)
# <---- Custom Distutils/Setuptools Commands ------------------------------------------------------------------------- # <---- Custom Distutils/Setuptools Commands -------------------------------------------------------------------------
if PACKAGED_FOR_SALT_SSH:
NAME = 'salt-ssh'
else:
NAME = 'salt'
NAME = 'salt'
VER = __version__ # pylint: disable=E0602 VER = __version__ # pylint: disable=E0602
DESC = 'Portable, distributed, remote execution and configuration management system' DESC = 'Portable, distributed, remote execution and configuration management system'
@ -506,7 +587,8 @@ SETUP_KWARGS = {'name': NAME,
'build': Build, 'build': Build,
'sdist': Sdist, 'sdist': Sdist,
'install': Install, 'install': Install,
'write-salt-version': WriteSaltVersion 'write-salt-version': WriteSaltVersion,
'write-salt-ssh-packaging-file': WriteSaltSshPackaingFile
}, },
'classifiers': ['Programming Language :: Python', 'classifiers': ['Programming Language :: Python',
'Programming Language :: Cython', 'Programming Language :: Cython',
@ -604,17 +686,23 @@ if IS_WINDOWS_PLATFORM is False:
# SETUP_KWARGS['packages'].extend(['salt.cloud', # SETUP_KWARGS['packages'].extend(['salt.cloud',
# 'salt.cloud.clouds']) # 'salt.cloud.clouds'])
SETUP_KWARGS['package_data']['salt.cloud'] = ['deploy/*.sh'] SETUP_KWARGS['package_data']['salt.cloud'] = ['deploy/*.sh']
SETUP_KWARGS['data_files'][0][1].extend([ if PACKAGED_FOR_SALT_SSH:
'doc/man/salt-master.1', SETUP_KWARGS['data_files'][0][1].extend([
'doc/man/salt-key.1', 'doc/man/salt-ssh.1',
'doc/man/salt.1', 'doc/man/salt-cloud.1',
'doc/man/salt-api.1', ])
'doc/man/salt-syndic.1', else:
'doc/man/salt-run.1', SETUP_KWARGS['data_files'][0][1].extend([
'doc/man/salt-ssh.1', 'doc/man/salt-master.1',
'doc/man/salt-cloud.1', 'doc/man/salt-key.1',
'doc/man/salt-unity.1', 'doc/man/salt.1',
]) 'doc/man/salt-api.1',
'doc/man/salt-syndic.1',
'doc/man/salt-run.1',
'doc/man/salt-ssh.1',
'doc/man/salt-cloud.1',
'doc/man/salt-unity.1',
])
# bbfreeze explicit includes # bbfreeze explicit includes
@ -714,23 +802,30 @@ if HAS_ESKY:
SETUP_KWARGS['options'] = OPTIONS SETUP_KWARGS['options'] = OPTIONS
if WITH_SETUPTOOLS: if WITH_SETUPTOOLS:
SETUP_KWARGS['entry_points'] = { if PACKAGED_FOR_SALT_SSH is False:
'console_scripts': ['salt-call = salt.scripts:salt_call', SETUP_KWARGS['entry_points'] = {
'salt-cp = salt.scripts:salt_cp', 'console_scripts': ['salt-call = salt.scripts:salt_call',
'salt-minion = salt.scripts:salt_minion', 'salt-cp = salt.scripts:salt_cp',
] 'salt-minion = salt.scripts:salt_minion',
} ]
}
if IS_WINDOWS_PLATFORM is False: if IS_WINDOWS_PLATFORM is False:
SETUP_KWARGS['entry_points']['console_scripts'].extend([ if PACKAGED_FOR_SALT_SSH:
'salt = salt.scripts:salt_main', SETUP_KWARGS['entry_points'] = {'console_scripts': [
'salt-api = salt.scripts:salt_api', 'salt-cloud = salt.scripts:salt_cloud',
'salt-cloud = salt.scripts:salt_cloud', 'salt-ssh = salt.scripts:salt_ssh'
'salt-key = salt.scripts:salt_key', ]}
'salt-master = salt.scripts:salt_master', else:
'salt-run = salt.scripts:salt_run', SETUP_KWARGS['entry_points']['console_scripts'].extend([
'salt-ssh = salt.scripts:salt_ssh', 'salt = salt.scripts:salt_main',
'salt-syndic = salt.scripts:salt_syndic', 'salt-api = salt.scripts:salt_api',
]) 'salt-cloud = salt.scripts:salt_cloud',
'salt-key = salt.scripts:salt_key',
'salt-master = salt.scripts:salt_master',
'salt-run = salt.scripts:salt_run',
'salt-ssh = salt.scripts:salt_ssh',
'salt-syndic = salt.scripts:salt_syndic',
])
# Required for running the tests suite # Required for running the tests suite
SETUP_KWARGS['dependency_links'] = [ SETUP_KWARGS['dependency_links'] = [
@ -741,23 +836,39 @@ if WITH_SETUPTOOLS:
# When WITH_SETUPTOOLS is True, esky builds would fail to include the scripts, # When WITH_SETUPTOOLS is True, esky builds would fail to include the scripts,
# and, if WITH_SETUPTOOLS is True, having scripts and console_scripts defined # and, if WITH_SETUPTOOLS is True, having scripts and console_scripts defined
# does not, apparently, break the build, so, let's have both # does not, apparently, break the build, so, let's have both
SETUP_KWARGS['scripts'] = ['scripts/salt-call', if PACKAGED_FOR_SALT_SSH is False:
'scripts/salt-cp', SETUP_KWARGS['scripts'] = ['scripts/salt-call',
'scripts/salt-minion', 'scripts/salt-cp',
'scripts/salt-unity', 'scripts/salt-minion',
] 'scripts/salt-unity',
]
if IS_WINDOWS_PLATFORM is False: if IS_WINDOWS_PLATFORM is False:
SETUP_KWARGS['scripts'].extend([ if PACKAGED_FOR_SALT_SSH:
'scripts/salt', SETUP_KWARGS['scripts'] = [
'scripts/salt-api', 'scripts/salt-ssh',
'scripts/salt-cloud', 'scripts/salt-cloud'
'scripts/salt-key', ]
'scripts/salt-master', else:
'scripts/salt-run', SETUP_KWARGS['scripts'].extend([
'scripts/salt-ssh', 'scripts/salt',
'scripts/salt-syndic', 'scripts/salt-api',
]) 'scripts/salt-cloud',
'scripts/salt-key',
'scripts/salt-master',
'scripts/salt-run',
'scripts/salt-ssh',
'scripts/salt-syndic',
])
if PACKAGED_FOR_SALT_SSH:
SETUP_KWARGS.pop('extras_require')
for requirement in _parse_requirements_file(SALT_ZEROMQ_REQS):
if requirement not in SETUP_KWARGS['install_requires']:
continue
SETUP_KWARGS['install_requires'].remove(requirement)
if __name__ == '__main__': if __name__ == '__main__':
setup(**SETUP_KWARGS) setup(**SETUP_KWARGS)