-
Notifications
You must be signed in to change notification settings - Fork 2
/
activity-publish
executable file
·202 lines (159 loc) · 5.57 KB
/
activity-publish
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
#!/usr/bin/python
# Copyright (C) 2018 One Laptop per Child, Inc
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
import os
import ConfigParser
import requests
from lxml import html
# configuration file must contain
# [server]
# username = something
# password = something
uc = ConfigParser.ConfigParser()
uc.read(os.path.join(os.getenv('HOME'), '.sugar-activity-publish.conf'))
username = uc.get('server', 'username')
password = uc.get('server', 'password')
# activity configuration file
cp = ConfigParser.ConfigParser()
cp.read('activity/activity.info')
A = cp.get('Activity', 'name')
V = cp.get('Activity', 'activity_version')
if 'sugar-activity3' in cp.get('Activity', 'exec'):
print "activities.sugarlabs.org does not host python 3 activities"
exit(1)
G = os.path.basename(cp.get('Activity', 'repository')).split('.')[0]
# todo; get addon number from config
ns = {
'Write': 4201,
'Speak': 4038,
'Memorize': 4063,
'StopWatch': 4263,
'Story': 4565,
'Portfolio': 4437,
'Poll': 4074,
'Pippy': 4041,
'Physics': 4193,
'Implode': 4086,
'Paint': 4082,
'Measure': 4197,
'Maze': 4071,
'Log': 4056,
'Letters': 4477,
'Jukebox': 4045,
'Image Viewer': 4032,
'Get Books': 4304,
'Terminal': 4043,
'Moon': 4034,
'Clock': 4191,
'Calculate': 4076,
'Chat': 4069,
'Level': 4628,
'FractionBounce': 4488,
'Chart': 4534,
}
N = ns[A]
# release notes file
notes = file('RELEASE-NOTES', 'r').read()
# begin a session
s = requests.Session()
print 'visit'
u = 'https://activities.sugarlabs.org/en-US/sugar/'
r = s.get(u)
print 'click login'
u = 'https://activities.sugarlabs.org/en-US/sugar/users/login?to=en-US%2Fsugar%2F'
r = s.get(u)
print 'try login'
u = 'https://activities.sugarlabs.org/en-US/sugar/users/login'
p = {
'data[Login][referer]': 'en-US/sugar/',
'data[Login][email]': username,
'data[Login][password]': password}
r = s.post(u, data=p)
if r.status_code != 200:
print 'fail, bad status', repr(r.status_code)
exit(1)
if 'AMOv3' not in s.cookies:
print 'fail, no cookie'
exit(1)
print 'logged in,', s.cookies['AMOv3']
print 'visit addon'
u = 'https://activities.sugarlabs.org/en-US/developers/versions/add/%d' % N
r = s.get(u)
if r.status_code != 200:
print 'fail, bad status', repr(r.status_code)
exit(1)
# extract sessionCheck and other values
tree = html.fromstring(r.content)
h = tree.find_class('hsession')[0]
i = h.getchildren()[0]
k = i.values()[2]
print "sessionCheck", k
u = 'https://activities.sugarlabs.org/en-US/developers/json/fileupload/update'
p = {
'data[appversion_min]': '109', # 0.98
'data[appversion_max]': '120', # 0.116
'data[Version][releasenotes][en-US]': notes,
'sessionCheck': k,
'data[Addon][id]': '%d' % N,
'data[Version][id]': '',
'data[File][id]': '',
}
n = '%s-%s.xo' % (A.replace(' ', ''), V)
f = {
"file": (n, open('dist/%s' % n, 'rb'), 'application/octet-stream'),
}
print 'upload'
r = s.post(u, data=p, files=f)
if r.status_code != 200:
print repr(r.status_code)
exit(1)
print 'upload ok'
print r.text
u = 'https://activities.sugarlabs.org/en-US/developers/verify/-1/1/1/%s' % n
r = s.get(u)
if r.status_code != 200:
print 'fail, bad status', repr(r.status_code)
exit(1)
print r.text
# todo; parse and report failures that may be returned at this point;
# such as bad license
u = 'https://activities.sugarlabs.org/en-US/developers/json/complete/update/%s' % n
r = s.get(u)
if r.status_code != 200:
print 'fail, bad status', repr(r.status_code)
exit(1)
print r.text
print ''
print 'http://activities.sugarlabs.org/en-US/sugar/addon/%s' % N
# good response looks like this (status 4);
# <script id="json">{"file_id":-1,"file_name":"Jukebox-34.xo","addon_type":"1","uploadtype":"update"}</script>
# {"validation_disabled":1}
# <script id="json">{"error":0,"uploadtype":"update","addon_id":"4045","version_id":"32331","file_id":"29336","version":"34","status":"4","queuecount":6}</script>
# next action; none
# less good response looks like this (status 2):
# <script id="json">{"file_id":-1,"file_name":"Chart-12.1.xo","addon_type":"1","uploadtype":"update"}</script>
# {"validation_disabled":1}
# <script id="json">{"error":0,"uploadtype":"update","addon_id":"4534","version_id":"32352","file_id":"29357","version":"12.1","status":"2","queuecount":6}</script>
# next action; use editor mode, pending updates, approve
# a bad response looks like this (addon_id null, status 1);
# <script id="json">{"file_id":-1,"file_name":"17426800 1540606366.xo","addon_type":"1","uploadtype":"update"}</script>
# {"validation_disabled":1}
# <script id="json">{"error":0,"uploadtype":"update","addon_id":null,"version_id":null,"file_id":null,"version":"","status":"1","queuecount":6}</script>
# next action; server sometimes fails to take action on upload, fix is
# to remove files from server temp directory,
# /srv/www-sugarlabs/activities/files/temp and then retry
exit(0)