summaryrefslogtreecommitdiff
path: root/setup.py
diff options
context:
space:
mode:
Diffstat (limited to 'setup.py')
-rwxr-xr-xsetup.py183
1 files changed, 113 insertions, 70 deletions
diff --git a/setup.py b/setup.py
index 4616599b..5c65c7fe 100755
--- a/setup.py
+++ b/setup.py
@@ -10,8 +10,11 @@
from glob import glob
+import atexit
import os
+import shutil
import sys
+import tempfile
import setuptools
from setuptools.command.install import install
@@ -53,47 +56,15 @@ def pkg_config_read(library, var):
cmd = ['pkg-config', '--variable=%s' % var, library]
try:
(path, err) = tiny_p(cmd)
+ path = path.strip()
except Exception:
- return fallbacks[library][var]
- return str(path).strip()
+ path = fallbacks[library][var]
+ if path.startswith("/"):
+ path = path[1:]
-
-INITSYS_FILES = {
- 'sysvinit': [f for f in glob('sysvinit/redhat/*') if is_f(f)],
- 'sysvinit_freebsd': [f for f in glob('sysvinit/freebsd/*') if is_f(f)],
- 'sysvinit_deb': [f for f in glob('sysvinit/debian/*') if is_f(f)],
- 'sysvinit_openrc': [f for f in glob('sysvinit/gentoo/*') if is_f(f)],
- 'systemd': [f for f in (glob('systemd/*.service') +
- glob('systemd/*.target')) if is_f(f)],
- 'systemd.generators': [f for f in glob('systemd/*-generator') if is_f(f)],
- 'upstart': [f for f in glob('upstart/*') if is_f(f)],
-}
-INITSYS_ROOTS = {
- 'sysvinit': '/etc/rc.d/init.d',
- 'sysvinit_freebsd': '/usr/local/etc/rc.d',
- 'sysvinit_deb': '/etc/init.d',
- 'sysvinit_openrc': '/etc/init.d',
- 'systemd': pkg_config_read('systemd', 'systemdsystemunitdir'),
- 'systemd.generators': pkg_config_read('systemd',
- 'systemdsystemgeneratordir'),
- 'upstart': '/etc/init/',
-}
-INITSYS_TYPES = sorted([f.partition(".")[0] for f in INITSYS_ROOTS.keys()])
-
-# Install everything in the right location and take care of Linux (default) and
-# FreeBSD systems.
-USR = "/usr"
-ETC = "/etc"
-USR_LIB_EXEC = "/usr/lib"
-LIB = "/lib"
-if os.uname()[0] == 'FreeBSD':
- USR = "/usr/local"
- USR_LIB_EXEC = "/usr/local/lib"
-elif os.path.isfile('/etc/redhat-release'):
- USR_LIB_EXEC = "/usr/libexec"
+ return path
-# Avoid having datafiles installed in a virtualenv...
def in_virtualenv():
try:
if sys.real_prefix == sys.prefix:
@@ -116,6 +87,77 @@ def read_requires():
return str(deps).splitlines()
+def render_tmpl(template):
+ """render template into a tmpdir under same dir as setup.py
+
+ This is rendered to a temporary directory under the top level
+ directory with the name 'cloud.cfg'. The reason for not just rendering
+ to config/cloud.cfg is for a.) don't want to write over contents
+ in that file if user had something there. b.) debuild will complain
+ that files are different outside of the debian directory."""
+
+ # older versions of tox use bdist (xenial), and then install from there.
+ # newer versions just use install.
+ if not (sys.argv[1] == 'install' or sys.argv[1].startswith('bdist*')):
+ return template
+
+ tmpl_ext = ".tmpl"
+ # we may get passed a non-template file, just pass it back
+ if not template.endswith(tmpl_ext):
+ return template
+
+ topdir = os.path.dirname(sys.argv[0])
+ tmpd = tempfile.mkdtemp(dir=topdir)
+ atexit.register(shutil.rmtree, tmpd)
+ bname = os.path.basename(template).rstrip(tmpl_ext)
+ fpath = os.path.join(tmpd, bname)
+ tiny_p([sys.executable, './tools/render-cloudcfg', template, fpath])
+ # return path relative to setup.py
+ return os.path.join(os.path.basename(tmpd), bname)
+
+
+INITSYS_FILES = {
+ 'sysvinit': [f for f in glob('sysvinit/redhat/*') if is_f(f)],
+ 'sysvinit_freebsd': [f for f in glob('sysvinit/freebsd/*') if is_f(f)],
+ 'sysvinit_deb': [f for f in glob('sysvinit/debian/*') if is_f(f)],
+ 'sysvinit_openrc': [f for f in glob('sysvinit/gentoo/*') if is_f(f)],
+ 'systemd': [render_tmpl(f)
+ for f in (glob('systemd/*.tmpl') +
+ glob('systemd/*.service') +
+ glob('systemd/*.target')) if is_f(f)],
+ 'systemd.fsck-dropin': ['systemd/systemd-fsck@.service.d/cloud-init.conf'],
+ 'systemd.generators': [f for f in glob('systemd/*-generator') if is_f(f)],
+ 'upstart': [f for f in glob('upstart/*') if is_f(f)],
+}
+INITSYS_ROOTS = {
+ 'sysvinit': 'etc/rc.d/init.d',
+ 'sysvinit_freebsd': 'usr/local/etc/rc.d',
+ 'sysvinit_deb': 'etc/init.d',
+ 'sysvinit_openrc': 'etc/init.d',
+ 'systemd': pkg_config_read('systemd', 'systemdsystemunitdir'),
+ 'systemd.fsck-dropin': (
+ os.path.sep.join([pkg_config_read('systemd', 'systemdsystemunitdir'),
+ 'systemd-fsck@.service.d'])),
+ 'systemd.generators': pkg_config_read('systemd',
+ 'systemdsystemgeneratordir'),
+ 'upstart': 'etc/init/',
+}
+INITSYS_TYPES = sorted([f.partition(".")[0] for f in INITSYS_ROOTS.keys()])
+
+
+# Install everything in the right location and take care of Linux (default) and
+# FreeBSD systems.
+USR = "usr"
+ETC = "etc"
+USR_LIB_EXEC = "usr/lib"
+LIB = "lib"
+if os.uname()[0] == 'FreeBSD':
+ USR = "usr/local"
+ USR_LIB_EXEC = "usr/local/lib"
+elif os.path.isfile('/etc/redhat-release'):
+ USR_LIB_EXEC = "usr/libexec"
+
+
# TODO: Is there a better way to do this??
class InitsysInstallData(install):
init_system = None
@@ -155,40 +197,41 @@ class InitsysInstallData(install):
self.distribution.reinitialize_command('install_data', True)
-if in_virtualenv():
- data_files = []
- cmdclass = {}
-else:
- data_files = [
- (ETC + '/cloud', glob('config/*.cfg')),
- (ETC + '/cloud/cloud.cfg.d', glob('config/cloud.cfg.d/*')),
- (ETC + '/cloud/templates', glob('templates/*')),
- (USR_LIB_EXEC + '/cloud-init', ['tools/ds-identify',
- 'tools/uncloud-init',
- 'tools/write-ssh-key-fingerprints']),
- (USR + '/share/doc/cloud-init', [f for f in glob('doc/*') if is_f(f)]),
- (USR + '/share/doc/cloud-init/examples',
- [f for f in glob('doc/examples/*') if is_f(f)]),
- (USR + '/share/doc/cloud-init/examples/seed',
- [f for f in glob('doc/examples/seed/*') if is_f(f)]),
- ]
- if os.uname()[0] != 'FreeBSD':
- data_files.extend([
- (ETC + '/NetworkManager/dispatcher.d/',
- ['tools/hook-network-manager']),
- (ETC + '/dhcp/dhclient-exit-hooks.d/', ['tools/hook-dhclient']),
- (LIB + '/udev/rules.d', [f for f in glob('udev/*.rules')])
- ])
- # Use a subclass for install that handles
- # adding on the right init system configuration files
- cmdclass = {
- 'install': InitsysInstallData,
- }
-
+if not in_virtualenv():
+ USR = "/" + USR
+ ETC = "/" + ETC
+ USR_LIB_EXEC = "/" + USR_LIB_EXEC
+ LIB = "/" + LIB
+ for k in INITSYS_ROOTS.keys():
+ INITSYS_ROOTS[k] = "/" + INITSYS_ROOTS[k]
+
+data_files = [
+ (ETC + '/cloud', [render_tmpl("config/cloud.cfg.tmpl")]),
+ (ETC + '/cloud/cloud.cfg.d', glob('config/cloud.cfg.d/*')),
+ (ETC + '/cloud/templates', glob('templates/*')),
+ (USR_LIB_EXEC + '/cloud-init', ['tools/ds-identify',
+ 'tools/uncloud-init',
+ 'tools/write-ssh-key-fingerprints']),
+ (USR + '/share/doc/cloud-init', [f for f in glob('doc/*') if is_f(f)]),
+ (USR + '/share/doc/cloud-init/examples',
+ [f for f in glob('doc/examples/*') if is_f(f)]),
+ (USR + '/share/doc/cloud-init/examples/seed',
+ [f for f in glob('doc/examples/seed/*') if is_f(f)]),
+]
+if os.uname()[0] != 'FreeBSD':
+ data_files.extend([
+ (ETC + '/NetworkManager/dispatcher.d/',
+ ['tools/hook-network-manager']),
+ (ETC + '/dhcp/dhclient-exit-hooks.d/', ['tools/hook-dhclient']),
+ (LIB + '/udev/rules.d', [f for f in glob('udev/*.rules')])
+ ])
+# Use a subclass for install that handles
+# adding on the right init system configuration files
+cmdclass = {
+ 'install': InitsysInstallData,
+}
requirements = read_requires()
-if sys.version_info < (3,):
- requirements.append('cheetah')
setuptools.setup(
name='cloud-init',
@@ -197,7 +240,7 @@ setuptools.setup(
author='Scott Moser',
author_email='scott.moser@canonical.com',
url='http://launchpad.net/cloud-init/',
- packages=setuptools.find_packages(exclude=['tests']),
+ packages=setuptools.find_packages(exclude=['tests.*', '*.tests', 'tests']),
scripts=['tools/cloud-init-per'],
license='Dual-licensed under GPLv3 or Apache 2.0',
data_files=data_files,