示例#1
0
def install(package, dst_dir, params, run=None, profile=None):
    """Installs the services.
    """
    _LOGGER.info('install: %s - %s, profile: %s', package, dst_dir, profile)

    packages = [package]

    module = plugin_manager.load('treadmill.bootstrap', package)
    extension_module = None
    if profile:
        _LOGGER.info('Installing profile: %s', profile)
        extension_name = '{}.{}'.format(package, profile)
        packages.append(extension_name)

        try:
            extension_module = plugin_manager.load('treadmill.bootstrap',
                                                   extension_name)
        except KeyError:
            _LOGGER.info('Extension not defined: %s, profile: %s', package,
                         profile)

    subproc.load_packages(packages, lazy=False)

    # Store resolved aliases
    aliases_path = os.path.join(dst_dir, '.aliases.json')
    aliases = subproc.get_aliases()
    with io.open(aliases_path, 'w') as f_aliases:
        f_aliases.write(json.dumps(aliases))

    defaults = {}
    defaults.update(getattr(module, 'DEFAULTS', {}))

    if extension_module:
        defaults.update(getattr(extension_module, 'DEFAULTS', {}))

    # TODO: this is ugly, error prone and should go away.
    #       aliases should be in default scope, everything else in _args.
    defaults['_alias'] = aliases
    defaults.update(aliases)
    defaults.update(params)

    defaults['aliases_path'] = aliases_path
    os.environ['TREADMILL_ALIASES_PATH'] = defaults['aliases_path']

    interpolated = _interpolate(defaults, defaults)

    fs.mkdir_safe(dst_dir)
    with io.open(os.path.join(dst_dir, '.install'), 'w') as rec:

        _install(module, PLATFORM, dst_dir, interpolated, rec=rec)

        if extension_module:
            _install(extension_module,
                     '.'.join([profile, PLATFORM]),
                     dst_dir,
                     interpolated,
                     rec=rec)

    if run:
        _run(run)
示例#2
0
 def check(aliases):
     """Check aliases."""
     subproc.load_packages(aliases.split(':'))
     for exe in subproc.get_aliases():
         success = True
         fullpath = subproc.resolve(exe)
         if fullpath:
             print('{:<30}{:<10}{}'.format(exe, 'ok', fullpath))
         else:
             print('{:<30}{:<10}'.format(exe, 'fail'))
示例#3
0
def init_profile():
    """Initailize profile.
    """
    if 'TREADMILL_ALIASES_PATH' in os.environ:
        subproc.load_aliases(os.environ['TREADMILL_ALIASES_PATH'])
    else:
        packages = ['aliases']
        profile = context.GLOBAL.get_profile_name()
        if profile:
            packages.append('aliases.{}'.format(profile))
        subproc.load_packages(packages)
示例#4
0
 def setUpClass(cls):
     subproc.load_packages(['node'])