Updated to use binary_components from validator (bug 714698)

This commit is contained in:
Rob Hudson 2012-01-18 12:21:53 -08:00
Родитель a0ebeff1f6
Коммит 1fca769fcb
13 изменённых файлов: 75 добавлений и 24 удалений

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

@ -307,6 +307,7 @@
"datestatuschanged": "2011-12-05 14:46:43",
"no_restart": false,
"binary": false,
"binary_components": false,
"size": 0
}
},
@ -330,6 +331,7 @@
"datestatuschanged": "2011-12-05 14:46:43",
"no_restart": false,
"binary": false,
"binary_components": false,
"size": 0
}
},
@ -353,6 +355,7 @@
"datestatuschanged": "2011-12-05 14:46:43",
"no_restart": false,
"binary": false,
"binary_components": false,
"size": 0
}
},
@ -376,6 +379,7 @@
"datestatuschanged": "2011-12-05 14:46:43",
"no_restart": false,
"binary": false,
"binary_components": false,
"size": 0
}
}

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

@ -8,6 +8,8 @@ from devhub.tasks import convert_purified, flag_binary, get_preview_sizes
tasks = {
'flag_binary_components': {'method': flag_binary, 'qs': [],
'kwargs': dict(latest=False)},
'flag_binary': {'method': flag_binary, 'qs': []},
'get_preview_sizes': {'method': get_preview_sizes, 'qs': []},
'convert_purified': {'method': convert_purified, 'qs': []}
@ -33,4 +35,7 @@ class Command(BaseCommand):
.values_list('pk', flat=True)
.order_by('id'))
for chunk in chunked(pks, 100):
task['method'].delay(chunk)
if task.get('kwargs'):
task['method'].delay(chunk, **task.get('kwargs'))
else:
task['method'].delay(chunk)

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

@ -563,7 +563,18 @@ class Addon(amo.models.OnChangeMixin, amo.models.ModelBase):
@amo.cached_property
def binary(self):
"""Returns if the current version has binary files."""
return self.current_version.files.filter(binary=True).exists()
version = self.current_version
if version:
return version.files.filter(binary=True).exists()
return False
@amo.cached_property
def binary_components(self):
"""Returns if the current version has files with binary_components."""
version = self.current_version
if version:
return version.files.filter(binary_components=True).exists()
return False
@property
def backup_version(self):

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

@ -1144,6 +1144,12 @@ class TestAddonModels(amo.tests.TestCase):
file.update(binary=True)
eq_(addon.binary, True)
def test_binary_components_property(self):
addon = Addon.objects.get(id=3615)
file = addon.current_version.files.all()[0]
file.update(binary_components=True)
eq_(addon.binary_components, True)
class TestAddonGetURLPath(amo.tests.TestCase):

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

@ -449,20 +449,21 @@ class TestDefaultToCompat(amo.tests.TestCase):
expected['-'.join([version, mode])])
def test_extension(self):
# Tests simple add-on (non-binary, non-strict).
# Tests simple add-on (non-binary-components, non-strict).
self.check(self.expected)
def test_binary_extension(self):
# Tests add-on with binary flag.
self.update_files(binary=True)
self.update_files(binary_components=True)
self.expected.update({
'8.0-normal': None,
})
self.check(self.expected)
def test_extension_compat_override(self):
# Tests simple add-on (non-binary, non-strict) with a compat override.
# Tests simple add-on (non-binary-components, non-strict) with a compat
# override.
self.create_override(min_version='1.3', max_version='1.4')
self.expected.update({
@ -473,9 +474,10 @@ class TestDefaultToCompat(amo.tests.TestCase):
self.check(self.expected)
def test_binary_extension_compat_override(self):
# Tests simple add-on (non-binary, non-strict) with a compat override.
# Tests simple add-on (non-binary-components, non-strict) with a compat
# override.
self.update_files(binary=True)
self.update_files(binary_components=True)
self.create_override(min_version='1.3', max_version='1.4')
self.expected.update({
'6.0-normal': self.ver_1_2,
@ -494,8 +496,8 @@ class TestDefaultToCompat(amo.tests.TestCase):
self.check(self.expected)
def test_compat_override_max_addon_wildcard(self):
# Tests simple add-on (non-binary, non-strict) with a compat override
# that contains a max wildcard.
# Tests simple add-on (non-binary-components, non-strict) with a compat
# override that contains a max wildcard.
self.create_override(min_version='1.2', max_version='1.*',
min_app_version='5.0', max_app_version='6.*')
@ -506,8 +508,8 @@ class TestDefaultToCompat(amo.tests.TestCase):
self.check(self.expected)
def test_compat_override_max_app_wildcard(self):
# Tests simple add-on (non-binary, non-strict) with a compat override
# that contains a min/max wildcard for the app.
# Tests simple add-on (non-binary-components, non-strict) with a compat
# override that contains a min/max wildcard for the app.
self.create_override(min_version='1.2', max_version='1.3')
self.expected.update({
@ -519,8 +521,9 @@ class TestDefaultToCompat(amo.tests.TestCase):
self.check(self.expected)
def test_compat_override_both_wildcards(self):
# Tests simple add-on (non-binary, non-strict) with a compat override
# that contains a wildcard for both addon version and app version.
# Tests simple add-on (non-binary-components, non-strict) with a compat
# override that contains a wildcard for both addon version and app
# version.
self.create_override(min_app_version='7.0', max_app_version='*')
self.expected.update({

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

@ -161,17 +161,24 @@ def flag_binary(ids, **kw):
% (len(ids), flag_binary.rate_limit, ids[0]))
addons = Addon.objects.filter(pk__in=ids).no_transforms()
latest = kw.pop('latest', True)
for addon in addons:
try:
log.info('Validating addon with id: %s' % addon.pk)
file = File.objects.filter(version__addon=addon).latest('created')
result = json.loads(run_validator(file.file_path))
metadata = result['metadata']
binary = (metadata.get('contains_binary_extension', False) or
metadata.get('contains_binary_content', False))
log.info('Setting binary for addon with id: %s to %s'
% (addon.pk, binary))
file.update(binary=binary)
files = (File.objects.filter(version__addon=addon)
.order_by('-created'))
if latest:
files = [files[0]]
for file in files:
result = json.loads(run_validator(file.file_path))
metadata = result['metadata']
binary = (metadata.get('contains_binary_extension', False) or
metadata.get('contains_binary_content', False))
binary_components = metadata.get('binary_components', False)
log.info('Setting binary for addon with id: %s to %s'
% (addon.pk, binary))
file.update(binary=binary, binary_components=binary_components)
except Exception, err:
log.error('Failed to run validation on addon id: %s, %s'
% (addon.pk, err))

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

@ -187,7 +187,7 @@ class EditorQueueTable(SQLTable, ItemStateTable):
info.append(_lazy(u'Site Specific'))
if row.external_software:
info.append(_lazy(u'Requires External Software'))
if row.binary:
if row.binary or row.binary_components:
info.append(_lazy(u'Binary Components'))
return u', '.join([jinja2.escape(i) for i in info])

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

@ -73,6 +73,7 @@ class ViewQueue(RawSQLModel):
is_site_specific = models.BooleanField()
external_software = models.BooleanField()
binary = models.BooleanField()
binary_components = models.BooleanField()
premium_type = models.IntegerField()
_no_restart = models.CharField(max_length=255)
_jetpack_versions = models.CharField(max_length=255)
@ -101,6 +102,7 @@ class ViewQueue(RawSQLModel):
('is_site_specific', 'addons.sitespecific'),
('external_software', 'addons.externalsoftware'),
('binary', 'files.binary'),
('binary_components', 'files.binary_components'),
('premium_type', 'addons.premium_type'),
('_latest_version_ids', """GROUP_CONCAT(versions.id
ORDER BY versions.created DESC)"""),

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

@ -162,6 +162,7 @@ class TestAdditionalInfoInQueue(amo.tests.TestCase):
self.row.file_platform_vers = [self.platform_id(amo.PLATFORM_ALL.id)]
self.row.external_software = False
self.row.binary = False
self.row.binary_components = False
def platform_id(self, platform):
return '%s-%s' % (platform, self.row.latest_version_id)

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

@ -63,7 +63,14 @@ class File(amo.models.OnChangeMixin, amo.models.ModelBase):
# The XPI contains JS that calls require("chrome").
requires_chrome = models.BooleanField(default=False)
reviewed = models.DateTimeField(null=True)
# The `binary` field is used to store the flags from amo-validator when it
# files files with binary extensions or files that may contain binary
# content.
binary = models.BooleanField(default=False)
# The `binary_components` field is used to store the flag from
# amo-validator when it finds "binary-components" in the chrome manifest
# file, used for default to compatible.
binary_components = models.BooleanField(default=False, db_index=True)
class Meta(amo.models.ModelBase.Meta):
db_table = 'files'
@ -637,6 +644,8 @@ class FileValidation(amo.models.ModelBase):
js['metadata'].get('contains_binary_extension', False) or
js['metadata'].get('contains_binary_content', False))):
file.update(binary=True)
if 'metadata' in js and js['metadata'].get('binary_components', False):
file.update(binary_components=True)
new.save()
return new

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

@ -0,0 +1,2 @@
ALTER TABLE `files` ADD COLUMN `binary_components` bool NOT NULL DEFAULT '0';
CREATE INDEX `files_cedd2560` ON `files` (`binary_components`);

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

@ -226,7 +226,8 @@ class Update(object):
# When file has strict_compatibility enabled, or file has binary
# components, default to compatible is disabled.
sql.append("""AND
CASE WHEN files.strict_compatibility = 1 OR files.binary = 1
CASE WHEN files.strict_compatibility = 1 OR
files.binary_components = 1
THEN appmax.version_int >= %(version_int)s ELSE 1 END
""")
# Filter out versions found in compat overrides

2
vendor

@ -1 +1 @@
Subproject commit be588787a8410979bf5645363a184d57211aa21a
Subproject commit e738e26ee711916750c444ce72370bdcb28ecfdc