Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
executable file 202 lines (159 sloc) 5.57 KB
#!/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)