FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-github3/github3/models.py at master · kennethreitz/python-github3 · GitHub
kennethreitz
/
python-github3
Public
Notifications
You must be signed in to change notification settings
Fork
88
Star
103
Code
Issues
1
Pull requests
1
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
python-github3
/
github3
/
models.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
263 lines (201 loc) · 6.04 KB
Breadcrumbs
python-github3
/
github3
/
models.py
Copy path
File metadata and controls
263 lines (201 loc) · 6.04 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# -*- coding: utf-8 -*-
"""
github3.models
~~~~~~~~~~~~~~
This module contains the models that comprise the Github API.
"""
import
json
from
urllib
import
quote
import
requests
from
.
helpers
import
to_python
from
.
structures
import
*
class
BaseResource
(
object
):
_strs
=
[]
_ints
=
[]
_dates
=
[]
_bools
=
[]
_dicts
=
[]
_map
=
{}
_pks
=
[]
def
__init__
(
self
):
self
.
_bootstrap
()
self
.
_h
=
None
super
(
BaseResource
,
self
).
__init__
()
def
__repr__
(
self
):
return
"<resource '{0}'>"
.
format
(
self
.
_id
)
def
_bootstrap
(
self
):
"""Bootstraps the model object based on configured values."""
for
attr
in
self
.
_keys
():
setattr
(
self
,
attr
,
None
)
def
_keys
(
self
):
return
self
.
_strs
+
self
.
_ints
+
self
.
_dates
+
self
.
_bools
+
self
.
_map
.
keys
()
@
property
def
_id
(
self
):
try
:
return
getattr
(
self
,
self
.
_pks
[
0
])
except
IndexError
:
return
None
@
property
def
_ids
(
self
):
"""The list of primary keys to validate against."""
for
pk
in
self
.
_pks
:
yield
getattr
(
self
,
pk
)
for
pk
in
self
.
_pks
:
try
:
yield
str
(
getattr
(
self
,
pk
))
except
ValueError
:
pass
def
dict
(
self
):
d
=
dict
()
for
k
in
self
.
keys
():
d
[
k
]
=
self
.
__dict__
.
get
(
k
)
return
d
@
classmethod
def
new_from_dict
(
cls
,
d
,
h
=
None
,
**
kwargs
):
d
=
to_python
(
obj
=
cls
(),
in_dict
=
d
,
str_keys
=
cls
.
_strs
,
int_keys
=
cls
.
_ints
,
date_keys
=
cls
.
_dates
,
bool_keys
=
cls
.
_bools
,
dict_keys
=
cls
.
_dicts
,
object_map
=
cls
.
_map
,
_h
=
h
)
d
.
__dict__
.
update
(
kwargs
)
return
d
class
App
(
BaseResource
):
"""Heroku App."""
_strs
=
[
'name'
,
'create_status'
,
'stack'
,
'repo_migrate_status'
]
_ints
=
[
'id'
,
'slug_size'
,
'repo_size'
,
'dynos'
,
'workers'
]
_dates
=
[
'created_at'
,]
_pks
=
[
'name'
,
'id'
]
def
__init__
(
self
):
super
(
App
,
self
).
__init__
()
def
__repr__
(
self
):
return
"<app '{0}'>"
.
format
(
self
.
name
)
def
new
(
self
,
name
=
None
,
stack
=
'cedar'
):
"""Creates a new app."""
payload
=
{}
if
name
:
payload
[
'app[name]'
]
=
name
if
stack
:
payload
[
'app[stack]'
]
=
stack
r
=
self
.
_h
.
_http_resource
(
method
=
'POST'
,
resource
=
(
'apps'
,),
data
=
payload
)
name
=
json
.
loads
(
r
.
content
).
get
(
'name'
)
return
self
.
_h
.
apps
.
get
(
name
)
@
property
def
addons
(
self
):
return
self
.
_h
.
_get_resources
(
resource
=
(
'apps'
,
self
.
name
,
'addons'
),
obj
=
Addon
,
app
=
self
)
@
property
def
collaborators
(
self
):
"""The collaborators for this app."""
return
self
.
_h
.
_get_resources
(
resource
=
(
'apps'
,
self
.
name
,
'collaborators'
),
obj
=
Collaborator
,
app
=
self
)
@
property
def
domains
(
self
):
"""The domains for this app."""
return
self
.
_h
.
_get_resources
(
resource
=
(
'apps'
,
self
.
name
,
'domains'
),
obj
=
Domain
,
app
=
self
)
@
property
def
releases
(
self
):
"""The releases for this app."""
return
self
.
_h
.
_get_resources
(
resource
=
(
'apps'
,
self
.
name
,
'releases'
),
obj
=
Release
,
app
=
self
)
@
property
def
processes
(
self
):
"""The proccesses for this app."""
return
self
.
_h
.
_get_resources
(
resource
=
(
'apps'
,
self
.
name
,
'ps'
),
obj
=
Process
,
app
=
self
,
map
=
ProcessListResource
)
@
property
def
config
(
self
):
"""The envs for this app."""
return
self
.
_h
.
_get_resource
(
resource
=
(
'apps'
,
self
.
name
,
'config_vars'
),
obj
=
ConfigVars
,
app
=
self
)
@
property
def
info
(
self
):
"""Returns current info for this app."""
return
self
.
_h
.
_get_resource
(
resource
=
(
'apps'
,
self
.
name
),
obj
=
App
,
)
def
rollback
(
self
,
release
):
"""Rolls back the release to the given version."""
r
=
self
.
_h
.
_http_resource
(
method
=
'POST'
,
resource
=
(
'apps'
,
self
.
name
,
'releases'
),
data
=
{
'rollback'
:
release
}
)
return
self
.
releases
[
-
1
]
def
rename
(
self
,
name
):
"""Renames app to given name."""
r
=
self
.
_h
.
_http_resource
(
method
=
'PUT'
,
resource
=
(
'apps'
,
self
.
name
),
data
=
{
'app[name]'
:
name
}
)
return
r
.
ok
def
transfer
(
self
,
user
):
"""Transfers app to given username's account."""
r
=
self
.
_h
.
_http_resource
(
method
=
'PUT'
,
resource
=
(
'apps'
,
self
.
name
),
data
=
{
'app[transfer_owner]'
:
user
}
)
return
r
.
ok
def
maintenance
(
self
,
on
=
True
):
"""Toggles maintenance mode."""
r
=
self
.
_h
.
_http_resource
(
method
=
'POST'
,
resource
=
(
'apps'
,
self
.
name
,
'server'
,
'maintenance'
),
data
=
{
'maintenance_mode'
:
int
(
on
)}
)
return
r
.
ok
def
destroy
(
self
):
"""Destoys the app. Do be careful."""
r
=
self
.
_h
.
_http_resource
(
method
=
'DELETE'
,
resource
=
(
'apps'
,
self
.
name
)
)
return
r
.
ok
def
logs
(
self
,
num
=
None
,
source
=
None
,
tail
=
False
):
"""Returns the requested log."""
# Bootstrap payload package.
payload
=
{
'logplex'
:
'true'
}
if
num
:
payload
[
'num'
]
=
num
if
source
:
payload
[
'source'
]
=
source
if
tail
:
payload
[
'tail'
]
=
1
# Grab the URL of the logplex endpoint.
r
=
self
.
_h
.
_http_resource
(
method
=
'GET'
,
resource
=
(
'apps'
,
self
.
name
,
'logs'
),
data
=
payload
)
# Grab the actual logs.
r
=
requests
.
get
(
r
.
content
)
if
not
tail
:
return
r
.
content
else
:
# Return line iterator for tail!
return
r
.
iter_lines
()
Back
|
FazBrowse Home
|
New Git URL