|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +# ########################## Copyrights and license ############################ |
| 4 | +# # |
| 5 | +# Copyright 2012 Vincent Jacques <[email protected]> # |
| 6 | +# Copyright 2012 Zearin <[email protected]> # |
| 7 | +# Copyright 2013 AKFish <[email protected]> # |
| 8 | +# Copyright 2013 Vincent Jacques <[email protected]> # # |
| 9 | +# Copyright 2017 Chris McBride <[email protected]> # |
| 10 | +# # |
| 11 | +# This file is part of PyGithub. # |
| 12 | +# http://pygithub.github.io/PyGithub/v1/index.html # |
| 13 | +# # |
| 14 | +# PyGithub is free software: you can redistribute it and/or modify it under # |
| 15 | +# the terms of the GNU Lesser General Public License as published by the Free # |
| 16 | +# Software Foundation, either version 3 of the License, or (at your option) # |
| 17 | +# any later version. # |
| 18 | +# # |
| 19 | +# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # |
| 20 | +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # |
| 21 | +# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # |
| 22 | +# details. # |
| 23 | +# # |
| 24 | +# You should have received a copy of the GNU Lesser General Public License # |
| 25 | +# along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # |
| 26 | +# # |
| 27 | +# ############################################################################## |
| 28 | + |
| 29 | +import github.GithubObject |
| 30 | + |
| 31 | + |
| 32 | +class GitReleaseAsset(github.GithubObject.CompletableGithubObject): |
| 33 | + """ |
| 34 | + This class represents GitReleaseAssets as returned by |
| 35 | + GET /repos/:owner/:repo/releases/assets/:id |
| 36 | + See: |
| 37 | + https://developer.github.com/v3/repos/releases/#get-a-single-release-asset |
| 38 | + """ |
| 39 | + |
| 40 | + def __repr__(self): |
| 41 | + return self.get__repr__({"url": self.url}) |
| 42 | + |
| 43 | + @property |
| 44 | + def url(self): |
| 45 | + """ |
| 46 | + :type: string |
| 47 | + """ |
| 48 | + self._completeIfNotSet(self._url) |
| 49 | + return self._url.value |
| 50 | + |
| 51 | + @property |
| 52 | + def id(self): |
| 53 | + """ |
| 54 | + :type: integer |
| 55 | + """ |
| 56 | + self._completeIfNotSet(self._id) |
| 57 | + return self._id.value |
| 58 | + |
| 59 | + @property |
| 60 | + def name(self): |
| 61 | + """ |
| 62 | + :type: string |
| 63 | + """ |
| 64 | + self._completeIfNotSet(self._name) |
| 65 | + return self._name.value |
| 66 | + |
| 67 | + @name.setter |
| 68 | + def name(self, value): |
| 69 | + """ |
| 70 | + :type: string |
| 71 | + """ |
| 72 | + self._completeIfNotSet(self._name) |
| 73 | + self._name.value = value |
| 74 | + |
| 75 | + @property |
| 76 | + def label(self): |
| 77 | + """ |
| 78 | + :type: string |
| 79 | + """ |
| 80 | + self._completeIfNotSet(self._label) |
| 81 | + return self._label.value |
| 82 | + |
| 83 | + @label.setter |
| 84 | + def label(self, value): |
| 85 | + """ |
| 86 | + :type: string |
| 87 | + """ |
| 88 | + self._completeIfNotSet(self._label) |
| 89 | + self._label.value = value |
| 90 | + |
| 91 | + @property |
| 92 | + def content_type(self): |
| 93 | + """ |
| 94 | + :type: string |
| 95 | + """ |
| 96 | + self._completeIfNotSet(self._content_type) |
| 97 | + return self._content_type.value |
| 98 | + |
| 99 | + @property |
| 100 | + def state(self): |
| 101 | + """ |
| 102 | + :type: string |
| 103 | + """ |
| 104 | + self._completeIfNotSet(self._state) |
| 105 | + return self._state.value |
| 106 | + |
| 107 | + @property |
| 108 | + def size(self): |
| 109 | + """ |
| 110 | + :type: integer |
| 111 | + """ |
| 112 | + self._completeIfNotSet(self._size) |
| 113 | + return self._size.value |
| 114 | + |
| 115 | + @property |
| 116 | + def download_count(self): |
| 117 | + """ |
| 118 | + :type: integer |
| 119 | + """ |
| 120 | + self._completeIfNotSet(self._download_count) |
| 121 | + return self._download_count.value |
| 122 | + |
| 123 | + @property |
| 124 | + def created_at(self): |
| 125 | + """ |
| 126 | + :type: datetime |
| 127 | + """ |
| 128 | + self._completeIfNotSet(self._created_at) |
| 129 | + return self._created_at.value |
| 130 | + |
| 131 | + @property |
| 132 | + def updated_at(self): |
| 133 | + """ |
| 134 | + :type: datetime |
| 135 | + """ |
| 136 | + self._completeIfNotSet(self._updated_at) |
| 137 | + return self._updated_at.value |
| 138 | + |
| 139 | + @property |
| 140 | + def browser_download_url(self): |
| 141 | + """ |
| 142 | + :type: string |
| 143 | + """ |
| 144 | + self._completeIfNotSet(self._browser_download_url) |
| 145 | + return self._browser_download_url.value |
| 146 | + |
| 147 | + @property |
| 148 | + def uploader(self): |
| 149 | + """ |
| 150 | + :type: github.NamedUser.NamedUser |
| 151 | + """ |
| 152 | + self._completeIfNotSet(self._uploader) |
| 153 | + return self._uploader.value |
| 154 | + |
| 155 | + def delete_asset(self): |
| 156 | + """ |
| 157 | + Delete asset from the release. |
| 158 | + :rtype: bool |
| 159 | + """ |
| 160 | + headers, data = self._requester.requestJsonAndCheck( |
| 161 | + "DELETE", |
| 162 | + self.url |
| 163 | + ) |
| 164 | + return True |
| 165 | + |
| 166 | + def update_asset(self, name, label=""): |
| 167 | + """ |
| 168 | + Update asset metadata. |
| 169 | + :rtype: github.GitReleaseAsset.GitReleaseAsset |
| 170 | + """ |
| 171 | + assert isinstance(name, (str, unicode)), name |
| 172 | + assert isinstance(label, (str, unicode)), label |
| 173 | + post_parameters = { |
| 174 | + "name": name, |
| 175 | + "label": label |
| 176 | + } |
| 177 | + headers, data = self._requester.requestJsonAndCheck( |
| 178 | + "PATCH", |
| 179 | + self.url, |
| 180 | + input=post_parameters |
| 181 | + ) |
| 182 | + return GitReleaseAsset(self._requester, headers, data, completed=True) |
| 183 | + |
| 184 | + def _initAttributes(self): |
| 185 | + self._url = github.GithubObject.NotSet |
| 186 | + self._id = github.GithubObject.NotSet |
| 187 | + self._name = github.GithubObject.NotSet |
| 188 | + self._label = github.GithubObject.NotSet |
| 189 | + self._uploader = github.GithubObject.NotSet |
| 190 | + self._content_type = github.GithubObject.NotSet |
| 191 | + self._state = github.GithubObject.NotSet |
| 192 | + self._size = github.GithubObject.NotSet |
| 193 | + self._download_count = github.GithubObject.NotSet |
| 194 | + self._created_at = github.GithubObject.NotSet |
| 195 | + self._updated_at = github.GithubObject.NotSet |
| 196 | + self._browser_download_url = github.GithubObject.NotSet |
| 197 | + |
| 198 | + def _useAttributes(self, attributes): |
| 199 | + if "url" in attributes: # pragma no branch |
| 200 | + self._url = self._makeStringAttribute(attributes["url"]) |
| 201 | + if "id" in attributes: # pragma no branch |
| 202 | + self._id = self._makeIntAttribute(attributes["id"]) |
| 203 | + if "name" in attributes: # pragma no branch |
| 204 | + self._name = self._makeStringAttribute(attributes["name"]) |
| 205 | + if "label" in attributes: # pragma no branch |
| 206 | + self._label = self._makeStringAttribute(attributes["label"]) |
| 207 | + if "uploader" in attributes: # pragma no branch |
| 208 | + self._uploader = github.NamedUser.NamedUser(self._requester, {}, \ |
| 209 | + attributes["uploader"], completed=True) |
| 210 | + if "content_type" in attributes: # pragma no branch |
| 211 | + self._content_type = self._makeStringAttribute(attributes["content_type"]) |
| 212 | + if "state" in attributes: # pragma no branch |
| 213 | + self._state = self._makeStringAttribute(attributes["state"]) |
| 214 | + if "size" in attributes: # pragma no branch |
| 215 | + self._size = self._makeIntAttribute(attributes["size"]) |
| 216 | + if "download_count" in attributes: # pragma no branch |
| 217 | + self._download_count = self._makeIntAttribute(attributes["download_count"]) |
| 218 | + if "created_at" in attributes: # pragma no branch |
| 219 | + self._created_at = self._makeDatetimeAttribute(attributes["created_at"]) |
| 220 | + if "updated_at" in attributes: # pragma no branch |
| 221 | + self._updated_at = self._makeDatetimeAttribute(attributes["updated_at"]) |
| 222 | + if "browser_download_url" in attributes: # pragma no branch |
| 223 | + self._browser_download_url = self._makeStringAttribute(attributes["browser_download_url"]) |
0 commit comments