Merge branch 'bug-600422-oauth_upload'

This commit is contained in:
Piotr Zalewa 2011-08-25 12:03:02 +01:00
Родитель a7d6051e8a c3e26ebfb4
Коммит 1db2f274e7
4 изменённых файлов: 11 добавлений и 4 удалений

Просмотреть файл

@ -25,7 +25,7 @@ def upload_to_amo(rev_pk, hashtag=None):
revision = PackageRevision.objects.get(pk=rev_pk) revision = PackageRevision.objects.get(pk=rev_pk)
# save status # save status
revision.amo_status = STATUS_UPLOAD_SCHEDULED revision.amo_status = STATUS_UPLOAD_SCHEDULED
revision.amo_version_name = revision.get_version_name_only() revision.amo_version_name = revision.get_version_name()
super(PackageRevision, revision).save() super(PackageRevision, revision).save()
response = revision.build_xpi( response = revision.build_xpi(
hashtag=hashtag, hashtag=hashtag,

Просмотреть файл

@ -16,7 +16,7 @@ def upload_to_amo(request, pk):
""" """
# check if there this Add-on was uploaded with the same version name # check if there this Add-on was uploaded with the same version name
revision = PackageRevision.objects.get(pk=pk) revision = PackageRevision.objects.get(pk=pk)
version = revision.get_version_name_only() version = revision.get_version_name()
uploaded = PackageRevision.objects.filter( uploaded = PackageRevision.objects.filter(
package=revision.package).filter( package=revision.package).filter(
amo_version_name=version).exclude( amo_version_name=version).exclude(

Просмотреть файл

@ -185,7 +185,8 @@ class PackageRevision(BaseModel):
error = None error = None
if self.package.amo_id: if self.package.amo_id:
# update addon on AMO # update addon on AMO
log.info('AMOOAUTHAPI: updating addon from %s' % self) log.info('AMOOAUTHAPI: updating addon %s to version %s' % (
self, self.amo_version_name))
log.debug(data) log.debug(data)
try: try:
response = amo.create_version(data, self.package.amo_id) response = amo.create_version(data, self.package.amo_id)
@ -203,7 +204,8 @@ class PackageRevision(BaseModel):
# TODO: update jetpack ID if needed # TODO: update jetpack ID if needed
else: else:
# create addon on AMO # create addon on AMO
log.info('AMOOAUTHAPI: creating addon from %s' % self) log.info('AMOOAUTHAPI: creating addon %s version %s' % (
self, self.amo_version_name))
data.update({'platform': 'all'}) data.update({'platform': 'all'})
try: try:
response = amo.create_addon(data) response = amo.create_addon(data)

Просмотреть файл

@ -2,6 +2,7 @@
A class to interact with AMO's api, using OAuth. A class to interact with AMO's api, using OAuth.
Ripped off from Daves test_oauth.py and some notes from python-oauth2 Ripped off from Daves test_oauth.py and some notes from python-oauth2
""" """
import commonware
# Wherein import almost every http or urllib in Python # Wherein import almost every http or urllib in Python
import urllib import urllib
import urllib2 import urllib2
@ -16,6 +17,8 @@ import mimetools
from helpers import encode_multipart, data_keys from helpers import encode_multipart, data_keys
log = commonware.log.getLogger('f.amooauth')
# AMO Specific end points # AMO Specific end points
urls = { urls = {
'login': '/users/login', 'login': '/users/login',
@ -108,12 +111,14 @@ class AMOOAuth:
method, url, parameters)) method, url, parameters))
request.sign_request(self.signature_method, self.get_consumer(), token) request.sign_request(self.signature_method, self.get_consumer(), token)
client = httplib2.Http() client = httplib2.Http()
strdata = str(data)
if data and method == 'POST': if data and method == 'POST':
data = encode_multipart(boundary, data) data = encode_multipart(boundary, data)
headers.update({'Content-Type': headers.update({'Content-Type':
'multipart/form-data; boundary=%s' % boundary}) 'multipart/form-data; boundary=%s' % boundary})
else: else:
data = urllib.urlencode(data) data = urllib.urlencode(data)
log.debug("AMOOAUTH: Sending request %s" % strdata)
return client.request(request.to_url(), method=method, return client.request(request.to_url(), method=method,
headers=headers, body=data) headers=headers, body=data)