Esempio n. 1
0
def get_bootstrap(host_url, bootstrap_token=None):
    """Returns the mangled version of the utility script bootstrap.py.

  Try to find the content in the following order:
  - get the file from luci-config
  - return the default version

  Returns:
    File instance.
  """
    # Calculate the header to inject at the top of the file.
    if bootstrap_token:
        quoted = urllib.quote_plus(bootstrap_token)
        assert bootstrap_token == quoted, bootstrap_token
    header = ('#!/usr/bin/env python\n'
              '# coding: utf-8\n'
              'host_url = %r\n'
              'bootstrap_token = %r\n') % (host_url or '', bootstrap_token
                                           or '')

    # Check in luci-config imported file if present.
    rev, cfg = config.get_self_config('scripts/bootstrap.py',
                                      store_last_good=True)
    if cfg:
        return File(header + cfg, config.config_service_hostname(), None, rev)

    # Fallback to the one embedded in the tree.
    path = os.path.join(ROOT_DIR, 'swarming_bot', 'config', 'bootstrap.py')
    with open(path, 'rb') as f:
        return File(header + f.read(), None, None, None)
Esempio n. 2
0
def settings_info():
    """Returns information about the settings file.

  Returns a dict with keys:
    'cfg': parsed SettingsCfg message
    'rev': revision of cfg
    'rev_url': URL of a human-consumable page that displays the config
    'config_service_url': URL of the config_service.
  """
    GlobalConfig.clear_cache()
    ds_cfg = GlobalConfig.cached()
    rev, cfg = _get_settings_with_defaults()
    rev_url = _gitiles_url(_get_configs_url(), rev, _SETTINGS_CFG_FILENAME)
    cfg_service_hostname = config.config_service_hostname()
    return {
        'cfg':
        ds_cfg,
        'config_service_url':
        'https://%s' % cfg_service_hostname if cfg_service_hostname else '',
        'luci_cfg':
        cfg,
        'rev':
        rev,
        'rev_url':
        rev_url,
    }
Esempio n. 3
0
def get_bot_config():
    """Returns the current version of bot_config.py.

  Try to find the content in the following order:
  - get the file from luci-config
  - return the default version

  Returns:
    File instance.
  """
    # Check in luci-config imported file if present.
    rev, cfg = config.get_self_config('scripts/bot_config.py',
                                      store_last_good=True)
    if cfg:
        return File(cfg, config.config_service_hostname(), None, rev)

    # Fallback to the one embedded in the tree.
    path = os.path.join(ROOT_DIR, 'swarming_bot', 'config', 'bot_config.py')
    with open(path, 'rb') as f:
        return File(f.read(), None, None, None)