diff options
Diffstat (limited to 'cython/installation_proxy.pxi')
| -rw-r--r-- | cython/installation_proxy.pxi | 126 |
1 files changed, 103 insertions, 23 deletions
diff --git a/cython/installation_proxy.pxi b/cython/installation_proxy.pxi index cf6662f..3dfb0b1 100644 --- a/cython/installation_proxy.pxi +++ b/cython/installation_proxy.pxi | |||
| @@ -64,71 +64,109 @@ cdef class InstallationProxyClient(PropertyListService): | |||
| 64 | plist.Node options | 64 | plist.Node options |
| 65 | plist.plist_t c_options | 65 | plist.plist_t c_options |
| 66 | plist.plist_t c_result = NULL | 66 | plist.plist_t c_result = NULL |
| 67 | bint free_options = False | ||
| 67 | instproxy_error_t err | 68 | instproxy_error_t err |
| 68 | if isinstance(client_options, plist.Dict): | 69 | if isinstance(client_options, plist.Dict): |
| 69 | options = client_options | 70 | options = client_options |
| 70 | c_options = options._c_node | 71 | c_options = options._c_node |
| 71 | elif isinstance(client_options, dict): | 72 | elif isinstance(client_options, dict): |
| 72 | c_options = plist.native_to_plist_t(client_options) | 73 | c_options = plist.native_to_plist_t(client_options) |
| 74 | free_options = True | ||
| 73 | else: | 75 | else: |
| 74 | raise InstallationProxyError(INSTPROXY_E_INVALID_ARG) | 76 | raise InstallationProxyError(INSTPROXY_E_INVALID_ARG) |
| 75 | err = instproxy_browse(self._c_client, c_options, &c_result) | 77 | err = instproxy_browse(self._c_client, c_options, &c_result) |
| 76 | self.handle_error(err) | 78 | |
| 77 | return plist.plist_t_to_node(c_result) | 79 | try: |
| 80 | self.handle_error(err) | ||
| 81 | return plist.plist_t_to_node(c_result) | ||
| 82 | except Exception, e: | ||
| 83 | if c_result != NULL: | ||
| 84 | plist.plist_free(c_result) | ||
| 85 | raise | ||
| 86 | finally: | ||
| 87 | if free_options: | ||
| 88 | plist.plist_free(c_options) | ||
| 78 | 89 | ||
| 79 | cpdef install(self, bytes pkg_path, object client_options, object callback=None): | 90 | cpdef install(self, bytes pkg_path, object client_options, object callback=None): |
| 80 | cdef: | 91 | cdef: |
| 81 | plist.Node options | 92 | plist.Node options |
| 82 | plist.plist_t c_options | 93 | plist.plist_t c_options |
| 94 | bint free_options = False | ||
| 83 | instproxy_error_t err | 95 | instproxy_error_t err |
| 84 | if isinstance(client_options, plist.Dict): | 96 | if isinstance(client_options, plist.Dict): |
| 85 | options = client_options | 97 | options = client_options |
| 86 | c_options = options._c_node | 98 | c_options = options._c_node |
| 87 | elif isinstance(client_options, dict): | 99 | elif isinstance(client_options, dict): |
| 88 | c_options = plist.native_to_plist_t(client_options) | 100 | c_options = plist.native_to_plist_t(client_options) |
| 101 | free_options = True | ||
| 89 | else: | 102 | else: |
| 90 | raise InstallationProxyError(INSTPROXY_E_INVALID_ARG) | 103 | raise InstallationProxyError(INSTPROXY_E_INVALID_ARG) |
| 91 | if callback is None: | 104 | if callback is None: |
| 92 | err = instproxy_install(self._c_client, pkg_path, options._c_node, NULL, NULL) | 105 | err = instproxy_install(self._c_client, pkg_path, c_options, NULL, NULL) |
| 93 | else: | 106 | else: |
| 94 | err = instproxy_install(self._c_client, pkg_path, options._c_node, instproxy_notify_cb, <void*>callback) | 107 | err = instproxy_install(self._c_client, pkg_path, c_options, instproxy_notify_cb, <void*>callback) |
| 95 | self.handle_error(err) | 108 | |
| 109 | try: | ||
| 110 | self.handle_error(err) | ||
| 111 | except Exception, e: | ||
| 112 | raise | ||
| 113 | finally: | ||
| 114 | if free_options: | ||
| 115 | plist.plist_free(c_options) | ||
| 96 | 116 | ||
| 97 | cpdef upgrade(self, bytes pkg_path, object client_options, object callback=None): | 117 | cpdef upgrade(self, bytes pkg_path, object client_options, object callback=None): |
| 98 | cdef: | 118 | cdef: |
| 99 | plist.Node options | 119 | plist.Node options |
| 100 | plist.plist_t c_options | 120 | plist.plist_t c_options |
| 121 | bint free_options = False | ||
| 101 | instproxy_error_t err | 122 | instproxy_error_t err |
| 102 | if isinstance(client_options, plist.Dict): | 123 | if isinstance(client_options, plist.Dict): |
| 103 | options = client_options | 124 | options = client_options |
| 104 | c_options = options._c_node | 125 | c_options = options._c_node |
| 105 | elif isinstance(client_options, dict): | 126 | elif isinstance(client_options, dict): |
| 106 | c_options = plist.native_to_plist_t(client_options) | 127 | c_options = plist.native_to_plist_t(client_options) |
| 128 | free_options = True | ||
| 107 | else: | 129 | else: |
| 108 | raise InstallationProxyError(INSTPROXY_E_INVALID_ARG) | 130 | raise InstallationProxyError(INSTPROXY_E_INVALID_ARG) |
| 109 | if callback is None: | 131 | if callback is None: |
| 110 | err = instproxy_upgrade(self._c_client, pkg_path, options._c_node, NULL, NULL) | 132 | err = instproxy_upgrade(self._c_client, pkg_path, c_options, NULL, NULL) |
| 111 | else: | 133 | else: |
| 112 | err = instproxy_upgrade(self._c_client, pkg_path, options._c_node, instproxy_notify_cb, <void*>callback) | 134 | err = instproxy_upgrade(self._c_client, pkg_path, c_options, instproxy_notify_cb, <void*>callback) |
| 113 | self.handle_error(err) | 135 | try: |
| 136 | self.handle_error(err) | ||
| 137 | except Exception, e: | ||
| 138 | raise | ||
| 139 | finally: | ||
| 140 | if free_options: | ||
| 141 | plist.plist_free(c_options) | ||
| 114 | 142 | ||
| 115 | cpdef uninstall(self, bytes appid, object client_options, object callback=None): | 143 | cpdef uninstall(self, bytes appid, object client_options, object callback=None): |
| 116 | cdef: | 144 | cdef: |
| 117 | plist.Node options | 145 | plist.Node options |
| 118 | plist.plist_t c_options | 146 | plist.plist_t c_options |
| 119 | instproxy_error_t err | 147 | instproxy_error_t err |
| 148 | bint free_options = False | ||
| 120 | if isinstance(client_options, plist.Dict): | 149 | if isinstance(client_options, plist.Dict): |
| 121 | options = client_options | 150 | options = client_options |
| 122 | c_options = options._c_node | 151 | c_options = options._c_node |
| 123 | elif isinstance(client_options, dict): | 152 | elif isinstance(client_options, dict): |
| 124 | c_options = plist.native_to_plist_t(client_options) | 153 | c_options = plist.native_to_plist_t(client_options) |
| 154 | free_options = True | ||
| 125 | else: | 155 | else: |
| 126 | raise InstallationProxyError(INSTPROXY_E_INVALID_ARG) | 156 | raise InstallationProxyError(INSTPROXY_E_INVALID_ARG) |
| 157 | |||
| 127 | if callback is None: | 158 | if callback is None: |
| 128 | err = instproxy_uninstall(self._c_client, appid, options._c_node, NULL, NULL) | 159 | err = instproxy_uninstall(self._c_client, appid, c_options, NULL, NULL) |
| 129 | else: | 160 | else: |
| 130 | err = instproxy_uninstall(self._c_client, appid, options._c_node, instproxy_notify_cb, <void*>callback) | 161 | err = instproxy_uninstall(self._c_client, appid, c_options, instproxy_notify_cb, <void*>callback) |
| 131 | self.handle_error(err) | 162 | |
| 163 | try: | ||
| 164 | self.handle_error(err) | ||
| 165 | except Exception, e: | ||
| 166 | raise | ||
| 167 | finally: | ||
| 168 | if free_options: | ||
| 169 | plist.plist_free(c_options) | ||
| 132 | 170 | ||
| 133 | cpdef plist.Node lookup_archives(self, object client_options): | 171 | cpdef plist.Node lookup_archives(self, object client_options): |
| 134 | cdef: | 172 | cdef: |
| @@ -136,70 +174,112 @@ cdef class InstallationProxyClient(PropertyListService): | |||
| 136 | plist.plist_t c_options | 174 | plist.plist_t c_options |
| 137 | plist.plist_t c_node = NULL | 175 | plist.plist_t c_node = NULL |
| 138 | instproxy_error_t err | 176 | instproxy_error_t err |
| 177 | bint free_options = False | ||
| 139 | if isinstance(client_options, plist.Dict): | 178 | if isinstance(client_options, plist.Dict): |
| 140 | options = client_options | 179 | options = client_options |
| 141 | c_options = options._c_node | 180 | c_options = options._c_node |
| 142 | elif isinstance(client_options, dict): | 181 | elif isinstance(client_options, dict): |
| 143 | c_options = plist.native_to_plist_t(client_options) | 182 | c_options = plist.native_to_plist_t(client_options) |
| 183 | free_options = True | ||
| 144 | else: | 184 | else: |
| 145 | raise InstallationProxyError(INSTPROXY_E_INVALID_ARG) | 185 | raise InstallationProxyError(INSTPROXY_E_INVALID_ARG) |
| 146 | err = instproxy_lookup_archives(self._c_client, options._c_node, &c_node) | 186 | |
| 147 | self.handle_error(err) | 187 | err = instproxy_lookup_archives(self._c_client, c_options, &c_node) |
| 148 | return plist.plist_t_to_node(c_node) | 188 | |
| 189 | try: | ||
| 190 | self.handle_error(err) | ||
| 191 | return plist.plist_t_to_node(c_node) | ||
| 192 | except Exception, e: | ||
| 193 | if c_node != NULL: | ||
| 194 | plist.plist_free(c_node) | ||
| 195 | raise | ||
| 196 | finally: | ||
| 197 | if free_options: | ||
| 198 | plist.plist_free(c_options) | ||
| 149 | 199 | ||
| 150 | cpdef archive(self, bytes appid, object client_options, object callback=None): | 200 | cpdef archive(self, bytes appid, object client_options, object callback=None): |
| 151 | cdef: | 201 | cdef: |
| 152 | plist.Node options | 202 | plist.Node options |
| 153 | plist.plist_t c_options | 203 | plist.plist_t c_options |
| 204 | bint free_options = False | ||
| 154 | instproxy_error_t err | 205 | instproxy_error_t err |
| 155 | if isinstance(client_options, plist.Dict): | 206 | if isinstance(client_options, plist.Dict): |
| 156 | options = client_options | 207 | options = client_options |
| 157 | c_options = options._c_node | 208 | c_options = options._c_node |
| 158 | elif isinstance(client_options, dict): | 209 | elif isinstance(client_options, dict): |
| 159 | c_options = plist.native_to_plist_t(client_options) | 210 | c_options = plist.native_to_plist_t(client_options) |
| 211 | free_options = True | ||
| 160 | else: | 212 | else: |
| 161 | raise InstallationProxyError(INSTPROXY_E_INVALID_ARG) | 213 | raise InstallationProxyError(INSTPROXY_E_INVALID_ARG) |
| 214 | |||
| 162 | if callback is None: | 215 | if callback is None: |
| 163 | err = instproxy_archive(self._c_client, appid, options._c_node, NULL, NULL) | 216 | err = instproxy_archive(self._c_client, appid, c_options, NULL, NULL) |
| 164 | else: | 217 | else: |
| 165 | err = instproxy_archive(self._c_client, appid, options._c_node, instproxy_notify_cb, <void*>callback) | 218 | err = instproxy_archive(self._c_client, appid, c_options, instproxy_notify_cb, <void*>callback) |
| 166 | self.handle_error(err) | 219 | |
| 220 | try: | ||
| 221 | self.handle_error(err) | ||
| 222 | except Exception, e: | ||
| 223 | raise | ||
| 224 | finally: | ||
| 225 | if free_options: | ||
| 226 | plist.plist_free(c_options) | ||
| 167 | 227 | ||
| 168 | cpdef restore(self, bytes appid, object client_options, object callback=None): | 228 | cpdef restore(self, bytes appid, object client_options, object callback=None): |
| 169 | cdef: | 229 | cdef: |
| 170 | plist.Node options | 230 | plist.Node options |
| 171 | plist.plist_t c_options | 231 | plist.plist_t c_options |
| 232 | bint free_options = False | ||
| 172 | instproxy_error_t err | 233 | instproxy_error_t err |
| 173 | if isinstance(client_options, plist.Dict): | 234 | if isinstance(client_options, plist.Dict): |
| 174 | options = client_options | 235 | options = client_options |
| 175 | c_options = options._c_node | 236 | c_options = options._c_node |
| 176 | elif isinstance(client_options, dict): | 237 | elif isinstance(client_options, dict): |
| 177 | c_options = plist.native_to_plist_t(client_options) | 238 | c_options = plist.native_to_plist_t(client_options) |
| 239 | free_options = True | ||
| 178 | else: | 240 | else: |
| 179 | raise InstallationProxyError(INSTPROXY_E_INVALID_ARG) | 241 | raise InstallationProxyError(INSTPROXY_E_INVALID_ARG) |
| 242 | |||
| 180 | if callback is None: | 243 | if callback is None: |
| 181 | err = instproxy_restore(self._c_client, appid, options._c_node, NULL, NULL) | 244 | err = instproxy_restore(self._c_client, appid, c_options, NULL, NULL) |
| 182 | else: | 245 | else: |
| 183 | err = instproxy_restore(self._c_client, appid, options._c_node, instproxy_notify_cb, <void*>callback) | 246 | err = instproxy_restore(self._c_client, appid, c_options, instproxy_notify_cb, <void*>callback) |
| 184 | self.handle_error(err) | 247 | |
| 248 | try: | ||
| 249 | self.handle_error(err) | ||
| 250 | except Exception, e: | ||
| 251 | raise | ||
| 252 | finally: | ||
| 253 | if free_options: | ||
| 254 | plist.plist_free(c_options) | ||
| 185 | 255 | ||
| 186 | cpdef remove_archive(self, bytes appid, object client_options, object callback=None): | 256 | cpdef remove_archive(self, bytes appid, object client_options, object callback=None): |
| 187 | cdef: | 257 | cdef: |
| 188 | plist.Node options | 258 | plist.Node options |
| 189 | plist.plist_t c_options | 259 | plist.plist_t c_options |
| 260 | bint free_options = False | ||
| 190 | instproxy_error_t err | 261 | instproxy_error_t err |
| 191 | if isinstance(client_options, plist.Dict): | 262 | if isinstance(client_options, plist.Dict): |
| 192 | options = client_options | 263 | options = client_options |
| 193 | c_options = options._c_node | 264 | c_options = options._c_node |
| 194 | elif isinstance(client_options, dict): | 265 | elif isinstance(client_options, dict): |
| 195 | c_options = plist.native_to_plist_t(client_options) | 266 | c_options = plist.native_to_plist_t(client_options) |
| 267 | free_options = True | ||
| 196 | else: | 268 | else: |
| 197 | raise InstallationProxyError(INSTPROXY_E_INVALID_ARG) | 269 | raise InstallationProxyError(INSTPROXY_E_INVALID_ARG) |
| 270 | |||
| 198 | if callback is None: | 271 | if callback is None: |
| 199 | err = instproxy_remove_archive(self._c_client, appid, options._c_node, NULL, NULL) | 272 | err = instproxy_remove_archive(self._c_client, appid, c_options, NULL, NULL) |
| 200 | else: | 273 | else: |
| 201 | err = instproxy_remove_archive(self._c_client, appid, options._c_node, instproxy_notify_cb, <void*>callback) | 274 | err = instproxy_remove_archive(self._c_client, appid, c_options, instproxy_notify_cb, <void*>callback) |
| 202 | self.handle_error(err) | 275 | |
| 276 | try: | ||
| 277 | self.handle_error(err) | ||
| 278 | except Exception, e: | ||
| 279 | raise | ||
| 280 | finally: | ||
| 281 | if free_options: | ||
| 282 | plist.plist_free(c_options) | ||
| 203 | 283 | ||
| 204 | cdef inline BaseError _error(self, int16_t ret): | 284 | cdef inline BaseError _error(self, int16_t ret): |
| 205 | return InstallationProxyError(ret) | 285 | return InstallationProxyError(ret) |
