Exemplo n.º 1
0
def _load_status_file(path):
    """ Open status file and parse it """
    data = {}
    if not os.path.isfile(path):
        return data
    with open(path, 'r') as f:
        try:
            data = yaml.safe_load(f)
        except yaml.YAMLError as exc:
            raise BadConfigException(
                "Error reading releases file:\n{}".format(exc))
    if not isinstance(data, dict):
        raise BadConfigException(
            "Releases file has wrong format ({}).".format(data))
    return data
Exemplo n.º 2
0
 def load(self, stream):
     """Load Scrapinghub configuration from stream."""
     try:
         yaml_cfg = yaml.safe_load(stream)
         if not yaml_cfg:
             return
         for option, shortcut in self.SHORTCUTS.items():
             option_conf = getattr(self, option)
             yaml_option_conf = yaml_cfg.get(option, {})
             option_conf.update(yaml_option_conf)
             if shortcut in yaml_cfg:
                 # We explicitly check yaml_option_conf and not option_conf.
                 # It is okay to set conflicting defaults if they are in
                 # different files (b/c then one of these will have
                 # priority)
                 if 'default' in yaml_option_conf:
                     raise BadConfigException(
                         "You cannot specify both '%s' and a 'default' key "
                         "for '%s' in the same file" % (shortcut, option))
                 option_conf['default'] = yaml_cfg[shortcut]
         self.version = yaml_cfg.get('version', self.version)
         self.requirements_file = yaml_cfg.get('requirements_file',
                                               self.requirements_file)
         self.requirements_file = yaml_cfg.get('requirements', {}).get(
             'file', self.requirements_file)
         self.eggs = yaml_cfg.get('requirements', {}).get('eggs', self.eggs)
     except (yaml.YAMLError, AttributeError):
         # AttributeError: stream is valid YAML but not dictionary-like
         raise ConfigParseException
     self._check_endpoints()
Exemplo n.º 3
0
def get_project_dir():
    """ A helper to get project root dir.
        Used by init/build command to locate Dockerfile.
    """
    closest = shub_utils.closest_file('scrapinghub.yml')
    if not closest:
        raise BadConfigException(
            "Not inside a project: scrapinghub.yml not found.")
    return os.path.dirname(closest)