예제 #1
0
 def test_boss_template_error(self):
     try:
         raise exc.BossTemplateError("BossTemplateError Test")
     except exc.BossTemplateError as e:
         test.eq(e.msg, "BossTemplateError Test")
         test.eq(e.__str__(), "BossTemplateError Test")
         raise
예제 #2
0
    def _get_config(self):
        config = None
        possibles = [
            fs.abspath(os.path.join(self.basedir, 'boss.json')),
            fs.abspath(os.path.join(self.basedir, 'boss.yml')),
            ]

        for path in possibles:
            if os.path.exists(path):
                if os.path.basename(path) == 'boss.json':
                    config = self._get_json_config(path)
                    break
                elif os.path.basename(path) == 'boss.yml':
                    config = self._get_yaml_config(path)
                    break

        if not config:
            raise boss_exc.BossTemplateError("No supported config found.")

        # fix it up with some defaults
        if 'delimiters' not in config.keys():
            config['delimiters'] = ('@', '@')
            config['start_delimiter'] = config['delimiters'][0]
            config['end_delimiter'] = config['delimiters'][1]
        else:
            config['start_delimiter'] = config['delimiters'][0]
            config['end_delimiter'] = config['delimiters'][1]

        return config
예제 #3
0
    def _get_json_config(self, path):
        full_path = fs.abspath(path)
        if not os.path.exists(full_path):
            raise boss_exc.BossTemplateError("Invalid template config.")

        self.app.log.debug('loading template config %s' % full_path)

        import json
        return json.load(open(full_path, 'r'))
예제 #4
0
    def create_from_template(self, source, template, dest_dir):
        try:
            src = self.app.db['sources'][source]
        except KeyError as e:
            raise exc.BossTemplateError("Source repo '%s' " % source + \
                                        "does not exist.")

        if src['is_local']:
            basedir = os.path.join(src['path'], template)
        else:
            basedir = os.path.join(src['cache'], template)

        tmpl = TemplateManager(self.app, fs.abspath(basedir))
        tmpl.copy(dest_dir)
예제 #5
0
    def _get_yaml_config(self, path):
        full_path = fs.abspath(path)
        if not os.path.exists(full_path):
            raise boss_exc.BossTemplateError("Invalid template config.")

        self.app.log.debug('loading template config %s' % full_path)

        try:
            import yaml
        except ImportError as e:
            raise boss_exc.BossRuntimeError("Unable to import yaml.  " +
                                            "Please install pyYaml.")

        return yaml.load(open(full_path, 'r'))