Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: sitescripts/extensions/utils.py

Issue 6291923287408640: Issue 1093 - Separate update manifest generation (Closed)
Patch Set: Created July 22, 2014, 8:03 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sitescripts/extensions/utils.py
===================================================================
--- a/sitescripts/extensions/utils.py
+++ b/sitescripts/extensions/utils.py
@@ -18,9 +18,12 @@
import re
import os
import subprocess
+import urlparse
from ConfigParser import SafeConfigParser, NoOptionError
from StringIO import StringIO
from sitescripts.utils import get_config
+from sitescripts.extensions.android import get_min_sdk_version
+from buildtools.packagerGecko import KNOWN_APPS
def compareVersionParts(part1, part2):
def convertInt(value, default):
@@ -256,3 +259,108 @@
return m.group(1)
finally:
bio.close()
+
+def _getLocalLink(repo):
Felix Dahlke 2014/07/22 08:11:11 These functions have just been moved. The only cha
+ """
+ gets the link for the newest download of an add-on in the local downloads
+ repository
+ """
+ highestURL = None
+ highestVersion = None
+
+ for filename, version in repo.getDownloads():
+ if not highestVersion or compareVersions(version, highestVersion) > 0:
+ highestURL = urlparse.urljoin(repo.downloadsURL, filename)
+ highestVersion = version
+
+ return (highestURL, highestVersion)
+
+def _getDownloadLink(repo):
+ """
+ gets the download link to the most current version of an extension
+ """
+ # you can't easily install extensions from third-party sources on Chrome
+ # and Opera. So always get the link for the version on the Web Store.
+ if repo.galleryID:
+ if repo.type == "chrome":
+ return getGoogleDownloadLink(repo.galleryID)
+ if repo.type == "opera":
+ return getOperaDownloadLink(repo.galleryID)
+
+ (localURL, localVersion) = _getLocalLink(repo)
+
+ # get a link to Firefox Add-Ons, if the latest version has been published there
+ if repo.type == 'gecko' and repo.galleryID:
+ (galleryURL, galleryVersion) = getMozillaDownloadLink(repo.galleryID)
+ if not localVersion or (galleryVersion and
+ compareVersions(galleryVersion, localVersion) >= 0):
+ return (galleryURL, galleryVersion)
+
+ return (localURL, localVersion)
+
+def _getQRCode(text):
+ try:
+ import qrcode
+ import base64
+ import Image # required by qrcode but not formally a dependency
+ except:
+ return None
+
+ data = StringIO()
+ qrcode.make(text, box_size=5).save(data, 'png')
+ return 'data:image/png;base64,' + base64.b64encode(data.getvalue())
+
+def getDownloadLinks(result):
+ """
+ gets the download links for all extensions and puts them into the config
+ object
+ """
+ for repo in Configuration.getRepositoryConfigurations():
+ (downloadURL, version) = _getDownloadLink(repo)
+ if downloadURL == None:
+ continue
+ if not result.has_section(repo.repositoryName):
+ result.add_section(repo.repositoryName)
+ result.set(repo.repositoryName, "downloadURL", downloadURL)
+ result.set(repo.repositoryName, "version", version)
+
+ qrcode = _getQRCode(downloadURL)
+ if qrcode != None:
+ result.set(repo.repositoryName, "qrcode", qrcode)
+
+def readMetadata(repo, version):
+ """
+ reads extension ID and compatibility information from metadata file in the
+ extension's repository
+ """
+ if repo.type == 'android':
+ command = ['hg', '-R', repo.repository, 'id', '-r', version, '-n']
+ result = subprocess.check_output(command)
+ revision = re.sub(r'\D', '', result)
+
+ return {
+ 'revision': revision,
+ 'minSdkVersion': get_min_sdk_version(repo, version),
+ }
+ elif repo.type == 'safari':
+ metadata = repo.readMetadata(version)
+ return {
+ 'certificateID': getSafariCertificateID(repo.keyFile),
+ 'version': version,
+ 'shortVersion': version,
+ 'basename': metadata.get('general', 'basename'),
+ }
+ elif repo.type == 'gecko':
+ metadata = repo.readMetadata(version)
+ result = {
+ 'extensionID': metadata.get('general', 'id'),
+ 'version': version,
+ 'compat': []
+ }
+ for key, value in KNOWN_APPS.iteritems():
+ if metadata.has_option('compat', key):
+ minVersion, maxVersion = metadata.get('compat', key).split('/')
+ result['compat'].append({'id': value, 'minVersion': minVersion, 'maxVersion': maxVersion})
+ return result
+ else:
+ raise Exception('unknown repository type %r' % repo.type)

Powered by Google App Engine
This is Rietveld