Allow salt's paths to be configurable at build time.

This commit is contained in:
Pedro Algarvio 2013-08-23 23:58:26 +01:00
parent 10e635c4d2
commit 0288ae6046
2 changed files with 138 additions and 3 deletions

45
salt/syspaths.py Normal file
View file

@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
'''
salt.syspaths
~~~~~~~~~~~~~
Salt's defaults system paths
:codeauthor: :email:`Pedro Algarvio (pedro@algarvio.me)`
:copyright: © 2013 by the SaltStack Team, see AUTHORS for more details.
:license: Apache 2.0, see LICENSE for more details.
'''
# Import python libs
import sys
import os.path
try:
# Let's try loading the system paths from the generated module at
# installation time.
from salt._syspaths import (
ROOT_DIR,
CONFIG_DIR,
CACHE_DIR,
SOCK_DIR,
BASE_FILE_ROOTS_DIR,
BASE_PILLAR_ROOTS_DIR,
BASE_MASTER_ROOTS_DIR,
LOGS_DIR,
PIDFILE_DIR,
)
except ImportError:
# The installation time was not generated, let's define the default values
if sys.platform.startswith('win'):
ROOT_DIR = r'c:\salt' or '/'
CONFIG_DIR = os.path.join(ROOT_DIR, 'conf')
else:
ROOT_DIR = '/'
CONFIG_DIR = os.path.join(ROOT_DIR, 'etc', 'salt')
CACHE_DIR = os.path.join(ROOT_DIR, 'var', 'cache', 'salt')
SOCK_DIR = os.path.join(ROOT_DIR, 'var', 'run', 'salt')
BASE_FILE_ROOTS_DIR = os.path.join(ROOT_DIR, 'srv', 'salt')
BASE_PILLAR_ROOTS_DIR = os.path.join(ROOT_DIR, 'srv', 'pillar')
BASE_MASTER_ROOTS_DIR = os.path.join(ROOT_DIR, 'srv', 'salt-master')
LOGS_DIR = os.path.join(ROOT_DIR, 'var', 'logs', 'salt')
PIDFILE_DIR = os.path.join(ROOT_DIR, 'var', 'run')

View file

@ -24,6 +24,9 @@ except NameError:
if SETUP_DIRNAME != '':
os.chdir(SETUP_DIRNAME)
# Store a reference to the executing platform
IS_WINDOWS_PLATFORM = sys.platform.startswith('win')
# Use setuptools only if the user opts-in by setting the USE_SETUPTOOLS env var
# Or if setuptools was previously imported (which is the case when using
# 'distribute')
@ -67,7 +70,12 @@ SALT_REQS = os.path.join(
os.path.abspath(SETUP_DIRNAME), 'requirements.txt'
)
SALT_SYSPATHS = os.path.join(
os.path.abspath(SETUP_DIRNAME), 'salt', 'syspaths.py'
)
exec(compile(open(SALT_VERSION).read(), SALT_VERSION, 'exec'))
exec(compile(open(SALT_SYSPATHS).read(), SALT_SYSPATHS, 'exec'))
class TestCommand(Command):
@ -125,13 +133,31 @@ __version_info__ = {version_info!r}
'''
install_syspaths_template = '''\
# This file was auto-generated by salt's setup on \
{date:%A, %d %B %Y @ %H:%m:%S UTC}.
ROOT_DIR = {root_dir!r}
CONFIG_DIR = {config_dir!r}
CACHE_DIR = {cache_dir!r}
SOCK_DIR = {sock_dir!r}
BASE_FILE_ROOTS_DIR = {base_file_roots_dir!r}
BASE_PILLAR_ROOTS_DIR = {base_pillar_roots_dir!r}
BASE_MASTER_ROOTS_DIR = {base_master_roots_dir!r}
LOGS_DIR = {logs_dir!r}
PIDFILE_DIR = {pidfile_dir!r}
'''
class Build(build):
def run(self):
# Run build.run function
build.run(self)
# If our install attribute is present and set to True, we'll go ahead
# and write our install time _version.py file.
if getattr(self.distribution, 'running_salt_install', False):
# If our install attribute is present and set to True, we'll go
# ahead and write our install time python modules.
# Write the version file
version_file_path = os.path.join(
self.build_lib, 'salt', '_version.py'
)
@ -143,8 +169,72 @@ class Build(build):
)
)
# Write the system paths file
system_paths_file_path = os.path.join(
self.build_lib, 'salt', '_syspaths.py'
)
open(system_paths_file_path, 'w').write(
install_syspaths_template.format(
date=datetime.utcnow(),
root_dir=self.salt_root_dir,
config_dir=self.salt_config_dir,
cache_dir=self.salt_cache_dir,
sock_dir=self.salt_sock_dir,
base_file_roots_dir=self.salt_base_file_roots_dir,
base_pillar_roots_dir=self.salt_base_pillar_roots_dir,
base_master_roots_dir=self.salt_base_master_roots_dir,
logs_dir=self.salt_logs_dir,
pidfile_dir=self.salt_pidfile_dir,
)
)
class Install(install):
user_options = install.user_options + [
('salt-root-dir=', None,
'Salt\'s pre-configured root directory'),
('salt-config-dir=', None,
'Salt\'s pre-configured configuration directory'),
('salt-cache-dir=', None,
'Salt\'s pre-configured cache directory'),
('salt-sock-dir=', None,
'Salt\'s pre-configured socket directory'),
('salt-base-file-roots-dir=', None,
'Salt\'s pre-configured file roots directory'),
('salt-base-pillar-roots-dir=', None,
'Salt\'s pre-configured pillar roots directory'),
('salt-base-master-roots-dir=', None,
'Salt\'s pre-configured master roots directory'),
('salt-logs-dir=', None,
'Salt\'s pre-configured logs directory'),
('salt-pidfile-dir=', None,
'Salt\'s pre-configured pidfiles directory'),
]
def initialize_options(self):
install.initialize_options(self)
self.salt_root_dir = ROOT_DIR
self.salt_config_dir = CONFIG_DIR
self.salt_cache_dir = CACHE_DIR
self.salt_sock_dir = SOCK_DIR
self.salt_base_file_roots_dir = BASE_FILE_ROOTS_DIR
self.salt_base_pillar_roots_dir = BASE_PILLAR_ROOTS_DIR
self.salt_base_master_roots_dir = BASE_MASTER_ROOTS_DIR
self.salt_logs_dir = LOGS_DIR
self.salt_pidfile_dir = PIDFILE_DIR
def finalize_options(self):
install.finalize_options(self)
for optname in ('root_dir', 'config_dir', 'cache_dir', 'sock_dir',
'base_file_roots_dir', 'base_pillar_roots_dir',
'base_master_roots_dir', 'logs_dir', 'pidfile_dir'):
if not getattr(self, 'salt_{0}'.format(optname)):
raise RuntimeError(
'The value of --salt-{0} needs a proper path value'.format(
optname.replace('_', '-')
)
)
def run(self):
# Let's set the running_salt_install attribute so we can add
# _version.py in the build command
@ -248,7 +338,7 @@ FREEZER_INCLUDES = [
'json',
]
if sys.platform.startswith('win'):
if IS_WINDOWS_PLATFORM:
FREEZER_INCLUDES.extend([
'win32api',
'win32file',