コード例 #1
0
ファイル: nodes.py プロジェクト: toddtomkinson/chamberlain
 def print_node(self, node, attrs=[]):
     wrapper = Config(node)
     self.log.title(wrapper.displayName())
     self.log.info("  - offline: %s" % wrapper.offline())
     self.log.info("  - idle: %s" % wrapper.idle())
     for key in attrs:
         self.log.info("  - %s: %s" % (key, node[key]))
コード例 #2
0
 def test_filter(self):
     valid_list = [
         Config({"full_name": "foobar"}),
         Config({"full_name": "foobaz"})
     ]
     self.client.repos = valid_list + [Config({"full_name": "floobygoop"})]
     self.assertEquals(self.client.filter_repos(["fooba"], []), valid_list)
コード例 #3
0
 def test_repo_data_throws(self):
     repo = "user/test"
     stub_list = [
         Config({"full_name": "user/test-other"}),
         Config({"full_name": "wrong_repo"})
     ]
     self.client.repo_list = mock.Mock(return_value=stub_list)
     self.assertRaises(RuntimeWarning, self.client.repo_data, repo)
コード例 #4
0
 def test_repo_data(self):
     repo = "user/test"
     stub_list = [
         Config({"full_name": repo}),
         Config({"full_name": "wrong_repo"})
     ]
     self.client.repo_list = mock.Mock(return_value=stub_list)
     self.assertEquals(self.client.repo_data(repo).full_name(), repo)
コード例 #5
0
 def repo_list(self, force=False, filters=[], file_filters=[], orgs=[]):
     if self.repos is not None and not force:
         return self.filter_repos(filters, file_filters)
     if os.path.isfile(self.cache_file) and not force:
         self.repos = [Config(repo)
                       for repo in load_json_file(self.cache_file)]
         return self.filter_repos(filters, file_filters)
     repos = []
     if len(orgs) <= 0:
         orgs = copy(self.config.orgs())
     for org_login in orgs:
         for repo in self.client.organization(org_login).repositories():
             repos.append(repo_hash(repo))
     write_json_file(self.cache_file, repos)
     self.repos = [Config(repo) for repo in repos]
     return self.filter_repos(filters, file_filters)
コード例 #6
0
ファイル: mappers.py プロジェクト: toddtomkinson/chamberlain
 def filter_repo_jobs(self, repo):
     """Map a repo (object from the repo module) to all jobs in given
     job config objects"""
     templates = {}
     for cfg in [Config(cfg) for cfg in self.metas]:
         meta_templates = TemplateFetcher(cfg).templates(repo)
         if not len(meta_templates) <= 0:
             if cfg.instance() not in templates:
                 templates[cfg.instance()] = []
             templates[cfg.instance()] += meta_templates
     return templates
コード例 #7
0
class ConfigTest(unittest.TestCase):
    def setUp(self):
        self.cfg = Config({"foo": "bar"})

    def test_existing_k_returns_config(self):
        self.assertTrue(type(self.cfg.foo) is Config)

    def test_non_existing_k_returns_null_config(self):
        self.assertTrue(type(self.cfg.baz) is NullConfig)

    def test_kv_get_on_k_returns_v(self):
        self.assertEquals(self.cfg.foo(), "bar")

    def test_kv_get_on_nonexistant_k_returns_false(self):
        self.assertFalse(self.cfg.baz())

    def test_real_kv_exist_returns_true(self):
        self.assertTrue(self.cfg.foo.exists())

    def test_bad_kv_exist_returns_false(self):
        self.assertFalse(self.cfg.baz.exists())
コード例 #8
0
ファイル: templates.py プロジェクト: kangman/chamberlain
    def execute(self, opts):
        try:
            icfg = self.app.config.jenkins.instances()[opts.instance]
        except KeyError:
            self.log.error("no such instance [%s]" % (opts.instance))
            return

        fork = opts.repo
        org = None
        if fork is None:
            fork = git.name_from_local_remote(opts.fork)
            org = git.org_from_name(fork)
        else:
            org, _ = opts.repo.split("/", 1)
        fork = fork.lower()
        org = org.lower()
        repo_name = fork.replace("%s/" % org, "")

        self.log.title("Fetching github data for %s (org: %s)" % (fork, org))

        repo = repo_hash(
            self.app.github(opts.api_url).repository(org, repo_name))

        self.log.title("Fetched metadata for %s" % fork)
        self.log.info(json.dumps(repo, indent=2))

        workspace = opts.workspace
        if workspace is None:
            workspace = self._default_workspace(fork)
        workspace = "%s-%i" % (workspace, int(time.time()))

        self.app.workspace.set_dir(workspace)
        self.clean_workspace(workspace)
        self.app.workspace.create_subdir(opts.instance)
        params = self.repo_params(opts.instance, fork, Config(repo))
        user_params = params_from_str(opts.params)
        if bool(user_params):
            self.log.info("Injecting params: %s" % user_params)
        params['name'] = '%s-project' % params['name']
        params.update(user_params)
        self.write_instance_templates(opts.instance, fork, params,
                                      opts.templates, opts.vars)
        ok = 0
        try:
            create_jobs(opts.instance, self.app.workspace, icfg,
                        self.app.workspace._default_libdir())
        except Exception as err:
            self.log.error("Could not provision jobs: %s" % err)
            ok = 1
        self.log.info("Project templates created in:")
        print(workspace)
        return ok
コード例 #9
0
ファイル: mappers.py プロジェクト: toddtomkinson/chamberlain
 def templates(self, repo):
     if not type(repo) == Config:
         repo = Config(repo)
     if self.cfg.owner() != repo.owner():
         return []
     if self.cfg.repo.exists() and self.cfg.repo() != repo.name():
         return []
     if self.private_only and not repo.private():
         return []
     if self.forks_only and repo.fork():
         return []
     if self.cfg.include.exists() and repo.name() not in self.cfg.include():
         return []
     return self.cfg.templates()
コード例 #10
0
ファイル: nodes.py プロジェクト: toddtomkinson/chamberlain
 def wanted_node(self, node, filters=[]):
     if len(filters) == 0:
         return True
     wrapper = Config(node)
     if wrapper.displayName() == "master":
         return False
     if "offline" in filters or "online" in filters:
         if wrapper.offline() and "offline" in filters:
             return True
         if wrapper.offline() and "online" in filters:
             return False
     if "idle" in filters or "busy" in filters:
         if wrapper.idle() and "idle" in filters:
             return True
         if wrapper.idle() and "busy" in filters:
             return False
     return False
コード例 #11
0
 def load_config(self, cfg_file=None):
     if cfg_file is None:
         cfg_file = prep_default_config()
     self.config = Config(load_json_file(cfg_file))
コード例 #12
0
 def __init__(self, log):
     self.config = Config({})
     self.log = log
     self.workspace = Workspace()
コード例 #13
0
ファイル: mappers.py プロジェクト: toddtomkinson/chamberlain
 def __init__(self, template_meta):
     if not type(template_meta) == Config:
         template_meta = Config(template_meta)
     self.cfg = template_meta
     self.private_only = not template_meta.include_public()
     self.forks_only = not template_meta.include_forks()
コード例 #14
0
 def setUp(self):
     self.cfg = Config({"foo": "bar"})