1 from __future__ import print_function
2 from __future__ import unicode_literals
3 from __future__ import division
4 from __future__ import absolute_import
5
6 import weakref
10 """
11 Base class for API responses.
12 Some response provides further actions based on response content.
13 """
14 _simple_fields = []
15
17 """
18 :param client: copr.main.Client
19 :param response:
20 """
21 self.response = response
22 self.client = weakref.proxy(client)
23
25 return str(self.response)
26
28 return unicode(self.response)
29
31 if item not in self._simple_fields:
32 raise KeyError(item)
33 if self.response is None:
34 raise RuntimeError()
35
36 return self.response[item]
37
39 raise NotImplementedError()
40
43 """
44 Provides methods related to copr project.
45 Object must have fields "client" and "project_name"
46 """
49
52
55 - def __init__(self, username, projectname,
56 description=None, instructions=None,
57 yum_repos=None, additional_repos=None):
58
59 self.username = username
60 self.projectname = projectname
61 self.description = description
62 self.instructions = instructions
63 self.yum_repos = yum_repos or {}
64 self.additional_repos = additional_repos or {}
65
67 out = list()
68 out.append("Name: {0}".format(self.projectname))
69 out.append(" Description: {0}".format(self.description))
70
71 if self.yum_repos:
72 out.append(" Yum repo(s):")
73 for k in sorted(self.yum_repos.keys()):
74 out.append(" {0}: {1}".format(k, self.yum_repos[k]))
75 if self.additional_repos:
76 out.append(" Additional repo: {0}".format(self.additional_repos))
77 if self.instructions:
78 out.append(" Instructions: {0}".format(self.instructions))
79
80 out.append("")
81 return "\n".join(out)
82
85 _simple_fields = ["output", "repos"]
86
87 - def __init__(self, client, response, username=None):
90
91 @property
93 if not self.response or \
94 self.response.get("output", None) != "ok" or \
95 not self.response.get("repos"):
96 return None
97 else:
98 return [
99 ProjectWrapper(
100 username=self.username,
101 projectname=prj.get("name"),
102 description=prj.get("description"),
103 yum_repos=prj.get("yum_repos"),
104 additional_repos=prj.get("additional_repos"),
105 ) for prj in self.response["repos"]
106 ]
107
110 _simple_fields = ["message", "output"]
111
112 - def __init__(self, client, response,
113 name, description, instructions,
114 chroots, repos, initial_pkgs):
115 super(CreateProjectResponse, self).__init__(client, response)
116 self.project_name = name
117 self.description = description
118 self.instructions = instructions
119 self.chroots = chroots
120 self.repos = repos
121 self.initial_pkgs = initial_pkgs
122
124 if hasattr(self, "message"):
125 return str(self.message)
126
128 if hasattr(self, "message"):
129 return unicode(self.message)
130
133 - def __init__(self, client, response,
134 name, description=None,
135 instructions=None, repos=None):
136 super(ModifyProjectResponse, self).__init__(client, response)
137 self.project_name = name
138 self.description = description
139 self.instructions = instructions
140 self.repos = repos
141
144 _simple_fields = ["detail", "output"]
145
146 - def __init__(self, client, response, name):
149
151 if hasattr(self, "detail"):
152 return str(self.detail)
153
155 if hasattr(self, "detail."):
156 return unicode(self.detail)
157
160
163 _simple_fields = ["message", "output"]
164
165 - def __init__(self, client, response, name):
168
170 if hasattr(self, "message"):
171 return str(self.message)
172
174 if hasattr(self, "message"):
175 return unicode(self.message)
176
179
182 """
183 Provides methods related to individual builds
184 Object must have fields "client" and "build_id"
185 """
188
191
194
196 if not self.response:
197 return super(BuildMixin, self).__str__()
198 elif self.response["output"] == "ok":
199 return self.response["status"]
200 else:
201 return self.response["error"]
202
213
216 _simple_fields = [
217 'status', 'error', 'submitted_by', 'results', 'src_pkg', 'started_on',
218 'submitted_on', 'owner', 'chroots', 'project', 'built_pkgs',
219 'ended_on', 'output', 'src_version'
220 ]
221
222 - def __init__(self, client, response, build_id):
225
228
239
250 _simple_fields = ["message", "output", "error", "ids"]
251
252 - def __init__(self, client, response,
253 copr_project, pkgs, memory, timeout, chroots):
254 super(BuildRequestResponse, self).__init__(client, response)
255 self.copr_project = copr_project
256 self.pkgs = pkgs
257 self.memory = memory
258 self.timeout = timeout
259 self.chroots = chroots
260
262 return self.client.send_new_build(
263 copr_project=self.copr_project,
264 pkgs=self.pkgs,
265 memory=self.memory,
266 timeout=self.timeout,
267 chroots=self.chroots
268 )
269
272 """
273 Provides methods related to project chroots
274 Object must have fields "client", "project_name", "chroot"
275 """
278
282
285 - def __init__(self, client, response, name, chroot):
289
292
295 - def __init__(self, client, response, name, chroot, pkgs):
300
303
314