Debian Codegraph @

jenkins_jobs/project.py

raw
1 # Licensed under the Apache License, Version 2.0 (the "License");
2 # you may not use this file except in compliance with the License.
3 # You may obtain a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
11 # under the License.
12
13 from dataclasses import dataclass
14
15 from .errors import JenkinsJobsException
16 from .position import Pos
17 from .root_base import GroupBase
18
19
20 @dataclass
21 class Project(GroupBase):
22 _jobs: dict
23 _job_templates: dict
24 _job_groups: dict
25 _views: dict
26 _view_templates: dict
27 _view_groups: dict
28 name: str
29 pos: Pos
30 defaults_name: str
31 job_specs: list # list[Spec]
32 view_specs: list # list[Spec]
33 params: dict
34
35 @classmethod
36 def add(cls, config, roots, data, pos):
37 d = data.copy()
38 name = d.pop_required_loc_string("name")
39 defaults = d.pop_loc_string("defaults", None)
40 try:
41 job_specs = cls._specs_from_list(d.pop("jobs", None))
42 view_specs = cls._specs_from_list(d.pop("views", None))
43 except JenkinsJobsException as x:
44 raise x.with_context(f"In project {name!r}", pos=pos)
45 project = cls(
46 roots.jobs,
47 roots.job_templates,
48 roots.job_groups,
49 roots.views,
50 roots.view_templates,
51 roots.view_groups,
52 name,
53 pos,
54 defaults,
55 job_specs,
56 view_specs,
57 params=d,
58 )
59 roots.assign(roots.projects, project.name, project, "project")
60
61 def __str__(self):
62 return f"project {self.name!r}"
63
64 @property
65 def _my_params(self):
66 return {"name": self.name}
67
68 def generate_jobs(self):
69 root_dicts = [self._jobs, self._job_templates, self._job_groups]
70 return self._generate_items(
71 root_dicts, self.job_specs, self.defaults_name, params={}
72 )
73
74 def generate_views(self):
75 root_dicts = [self._views, self._view_templates, self._view_groups]
76 return self._generate_items(
77 root_dicts, self.view_specs, self.defaults_name, params={}
78 )