Remove more unused code. Most of it are leftovers from other cleanups.
This commit is contained in:
Родитель
ef63fbc6aa
Коммит
78145b4670
|
@ -75,7 +75,6 @@ no_updates_rdf = """<?xml version="1.0"?>
|
|||
</RDF:RDF>"""
|
||||
|
||||
|
||||
timing_log = olympia.core.logger.getLogger('z.timer')
|
||||
error_log = olympia.core.logger.getLogger('z.services')
|
||||
|
||||
|
||||
|
@ -326,22 +325,6 @@ class Update(object):
|
|||
('Content-Length', str(length))]
|
||||
|
||||
|
||||
def mail_exception(data):
|
||||
if settings.EMAIL_BACKEND != 'django.core.mail.backends.smtp.EmailBackend':
|
||||
return
|
||||
|
||||
msg = MIMEText('%s\n\n%s' % (
|
||||
'\n'.join(traceback.format_exception(*sys.exc_info())), data))
|
||||
msg['Subject'] = '[Update] ERROR at /services/update'
|
||||
msg['To'] = ','.join([a[1] for a in settings.ADMINS])
|
||||
msg['From'] = settings.DEFAULT_FROM_EMAIL
|
||||
|
||||
conn = smtplib.SMTP(getattr(settings, 'EMAIL_HOST', 'localhost'),
|
||||
getattr(settings, 'EMAIL_PORT', '25'))
|
||||
conn.sendmail(settings.DEFAULT_FROM_EMAIL, msg['To'], msg.as_string())
|
||||
conn.close()
|
||||
|
||||
|
||||
def log_exception(data):
|
||||
(typ, value, traceback) = sys.exc_info()
|
||||
error_log.error(u'Type: %s, %s. Query: %s' % (typ, value, data))
|
||||
|
|
|
@ -126,8 +126,3 @@ def log_exception(data):
|
|||
typ, value, discard = sys.exc_info()
|
||||
error_log = olympia.core.logger.getLogger('z.update')
|
||||
error_log.exception(u'Type: %s, %s. Data: %s' % (typ, value, data))
|
||||
|
||||
|
||||
def log_info(msg):
|
||||
error_log = olympia.core.logger.getLogger('z.update')
|
||||
error_log.info(msg)
|
||||
|
|
|
@ -22,14 +22,6 @@ class UserProfileSerializer(serializers.ModelSerializer):
|
|||
)
|
||||
|
||||
|
||||
class AccountSourceSerializer(serializers.ModelSerializer):
|
||||
source = serializers.CharField()
|
||||
|
||||
class Meta:
|
||||
model = UserProfile
|
||||
fields = ['source']
|
||||
|
||||
|
||||
group_rules = {
|
||||
'reviewer': 'Addons:Review',
|
||||
'admin': '*:*',
|
||||
|
|
|
@ -1850,13 +1850,6 @@ class Preview(ModelBase):
|
|||
'caption': unicode(self.caption)}
|
||||
return d
|
||||
|
||||
@property
|
||||
def is_landscape(self):
|
||||
size = self.image_size
|
||||
if not size:
|
||||
return False
|
||||
return size[0] > size[1]
|
||||
|
||||
@property
|
||||
def thumbnail_url(self):
|
||||
template = (
|
||||
|
|
|
@ -9,7 +9,6 @@ from olympia.constants.categories import CATEGORIES_BY_ID
|
|||
|
||||
|
||||
log = olympia.core.logger.getLogger('z.redis')
|
||||
rnlog = olympia.core.logger.getLogger('z.rn')
|
||||
|
||||
|
||||
def generate_addon_guid():
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import functools
|
||||
import hashlib
|
||||
import json
|
||||
import random
|
||||
|
@ -78,22 +77,6 @@ addon_valid_disabled_pending_view = addon_view_factory(
|
|||
qs=Addon.objects.valid_and_disabled_and_pending)
|
||||
|
||||
|
||||
def author_addon_clicked(f):
|
||||
"""Decorator redirecting clicks on "Other add-ons by author"."""
|
||||
@functools.wraps(f)
|
||||
def decorated(request, *args, **kwargs):
|
||||
redirect_id = request.GET.get('addons-author-addons-select', None)
|
||||
if not redirect_id:
|
||||
return f(request, *args, **kwargs)
|
||||
try:
|
||||
target_id = int(redirect_id)
|
||||
return http.HttpResponsePermanentRedirect(reverse(
|
||||
'addons.detail', args=[target_id]))
|
||||
except ValueError:
|
||||
return http.HttpResponseBadRequest('Invalid add-on ID.')
|
||||
return decorated
|
||||
|
||||
|
||||
@addon_valid_disabled_pending_view
|
||||
@non_atomic_requests
|
||||
def addon_detail(request, addon):
|
||||
|
|
|
@ -418,19 +418,6 @@ def manual_order(qs, pks, pk_name='id'):
|
|||
order_by=['_manual'])
|
||||
|
||||
|
||||
class BlobField(models.Field):
|
||||
"""MySQL blob column.
|
||||
|
||||
This is for using AES_ENCYPT() to store values.
|
||||
It could maybe turn into a fancy transparent encypt/decrypt field
|
||||
like http://djangosnippets.org/snippets/2489/
|
||||
"""
|
||||
description = "blob"
|
||||
|
||||
def db_type(self, **kw):
|
||||
return 'blob'
|
||||
|
||||
|
||||
class SlugField(models.SlugField):
|
||||
"""
|
||||
Django 1.6's SlugField rejects non-ASCII slugs. This field just
|
||||
|
|
|
@ -11,8 +11,6 @@ log = olympia.core.logger.getLogger('z.es')
|
|||
|
||||
DEFAULT_HOSTS = ['localhost:9200']
|
||||
DEFAULT_TIMEOUT = 5
|
||||
DEFAULT_INDEXES = ['default']
|
||||
DEFAULT_DUMP_CURL = None
|
||||
|
||||
|
||||
def get_es(hosts=None, timeout=None, **settings):
|
||||
|
|
|
@ -90,7 +90,3 @@ class APIKey(ModelBase):
|
|||
'{} is too short; secrets must be longer than 32 bytes'
|
||||
.format(byte_length))
|
||||
return os.urandom(byte_length).encode('hex')
|
||||
|
||||
|
||||
def generate():
|
||||
return os.urandom(64).encode('hex')
|
||||
|
|
|
@ -18,7 +18,7 @@ from olympia.amo.urlresolvers import reverse
|
|||
from olympia.amo.utils import render
|
||||
from olympia.addons.models import Addon, AddonCategory, Category, FrozenAddon
|
||||
from olympia.addons.utils import get_featured_ids, get_creatured_ids
|
||||
from olympia.addons.views import BaseFilter, ESBaseFilter
|
||||
from olympia.addons.views import BaseFilter
|
||||
|
||||
|
||||
languages = dict((lang.lower(), val)
|
||||
|
@ -73,11 +73,6 @@ class ThemeFilter(AddonFilter):
|
|||
('hotness', _lazy(u'Up & Coming')))
|
||||
|
||||
|
||||
class ESAddonFilter(ESBaseFilter):
|
||||
opts = AddonFilter.opts
|
||||
extras = AddonFilter.extras
|
||||
|
||||
|
||||
def addon_listing(request, addon_types, filter_=AddonFilter, default=None):
|
||||
if default is None:
|
||||
default = 'rating' if request.MOBILE else 'featured'
|
||||
|
|
|
@ -8,8 +8,6 @@ from olympia.lib.misc.urlconf_decorator import decorate
|
|||
|
||||
from . import views
|
||||
|
||||
PACKAGE_NAME = '(?P<package_name>[_\w]+)'
|
||||
|
||||
|
||||
# These will all start with /theme/<slug>/
|
||||
theme_detail_patterns = patterns(
|
||||
|
|
|
@ -16,11 +16,8 @@ from defusedxml.common import EntitiesForbidden, NotSupportedError
|
|||
|
||||
from olympia import amo
|
||||
from olympia.amo.tests import TestCase
|
||||
from olympia.addons.models import Addon
|
||||
from olympia.applications.models import AppVersion
|
||||
from olympia.files import utils
|
||||
from olympia.files.models import File
|
||||
from olympia.versions.models import Version
|
||||
from olympia.files.tests.test_helpers import get_file
|
||||
|
||||
|
||||
|
@ -85,53 +82,6 @@ def test_is_beta():
|
|||
assert utils.is_beta('1.2rc-123')
|
||||
|
||||
|
||||
class TestFindJetpacks(TestCase):
|
||||
fixtures = ['base/addon_3615']
|
||||
|
||||
def setUp(self):
|
||||
super(TestFindJetpacks, self).setUp()
|
||||
File.objects.update(jetpack_version='1.0')
|
||||
self.file = File.objects.filter(version__addon=3615).get()
|
||||
|
||||
def test_success(self):
|
||||
files = utils.find_jetpacks('1.0', '1.1')
|
||||
assert files == [self.file]
|
||||
|
||||
def test_skip_autorepackage(self):
|
||||
Addon.objects.update(auto_repackage=False)
|
||||
assert utils.find_jetpacks('1.0', '1.1') == []
|
||||
|
||||
def test_minver(self):
|
||||
files = utils.find_jetpacks('1.1', '1.2')
|
||||
assert files == [self.file]
|
||||
assert not files[0].needs_upgrade
|
||||
|
||||
def test_maxver(self):
|
||||
files = utils.find_jetpacks('.1', '1.0')
|
||||
assert files == [self.file]
|
||||
assert not files[0].needs_upgrade
|
||||
|
||||
def test_unreviewed_files_plus_reviewed_file(self):
|
||||
# We upgrade unreviewed files up to the latest reviewed file.
|
||||
v = Version.objects.create(addon_id=3615)
|
||||
new_file = File.objects.create(version=v, jetpack_version='1.0')
|
||||
Version.objects.create(addon_id=3615)
|
||||
new_file2 = File.objects.create(version=v, jetpack_version='1.0')
|
||||
assert new_file.status == amo.STATUS_AWAITING_REVIEW
|
||||
assert new_file2.status == amo.STATUS_AWAITING_REVIEW
|
||||
|
||||
files = utils.find_jetpacks('1.0', '1.1')
|
||||
assert files == [self.file, new_file, new_file2]
|
||||
assert all(f.needs_upgrade for f in files)
|
||||
|
||||
# Now self.file will not need an upgrade since we skip old versions.
|
||||
new_file.update(status=amo.STATUS_PUBLIC)
|
||||
files = utils.find_jetpacks('1.0', '1.1')
|
||||
assert files == [self.file, new_file, new_file2]
|
||||
assert not files[0].needs_upgrade
|
||||
assert all(f.needs_upgrade for f in files[1:])
|
||||
|
||||
|
||||
class TestExtractor(TestCase):
|
||||
|
||||
def os_path_exists_for(self, path_to_accept):
|
||||
|
|
|
@ -14,13 +14,11 @@ import zipfile
|
|||
|
||||
from cStringIO import StringIO as cStringIO
|
||||
from datetime import datetime, timedelta
|
||||
from itertools import groupby
|
||||
from xml.dom import minidom
|
||||
from zipfile import BadZipfile, ZipFile
|
||||
|
||||
from django import forms
|
||||
from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
from django.core.files.storage import (
|
||||
default_storage as storage, File as DjangoFile)
|
||||
from django.utils.jslex import JsLexer
|
||||
|
@ -753,95 +751,6 @@ def get_sha256(filename, **kw):
|
|||
return _get_hash(filename, hash=hashlib.sha256, **kw)
|
||||
|
||||
|
||||
def find_jetpacks(minver, maxver):
|
||||
"""
|
||||
Find all jetpack files that aren't disabled.
|
||||
|
||||
Files that should be upgraded will have needs_upgrade=True.
|
||||
"""
|
||||
from .models import File
|
||||
statuses = amo.VALID_ADDON_STATUSES
|
||||
files = (File.objects.filter(jetpack_version__isnull=False,
|
||||
version__addon__auto_repackage=True,
|
||||
version__addon__status__in=statuses,
|
||||
version__addon__disabled_by_user=False)
|
||||
.exclude(status=amo.STATUS_DISABLED).no_cache()
|
||||
.select_related('version'))
|
||||
files = sorted(files, key=lambda f: (f.version.addon_id, f.version.id))
|
||||
|
||||
# Figure out which files need to be upgraded.
|
||||
for file_ in files:
|
||||
file_.needs_upgrade = False
|
||||
# If any files for this add-on are reviewed, take the last reviewed file
|
||||
# plus all newer files. Otherwise, only upgrade the latest file.
|
||||
for _group, fs in groupby(files, key=lambda f: f.version.addon_id):
|
||||
fs = list(fs)
|
||||
if any(f.status in amo.REVIEWED_STATUSES for f in fs):
|
||||
for file_ in reversed(fs):
|
||||
file_.needs_upgrade = True
|
||||
if file_.status in amo.REVIEWED_STATUSES:
|
||||
break
|
||||
else:
|
||||
fs[-1].needs_upgrade = True
|
||||
# Make sure only old files are marked.
|
||||
for file_ in [f for f in files if f.needs_upgrade]:
|
||||
if not (vint(minver) <= vint(file_.jetpack_version) < vint(maxver)):
|
||||
file_.needs_upgrade = False
|
||||
return files
|
||||
|
||||
|
||||
class JetpackUpgrader(object):
|
||||
"""A little manager for jetpack upgrade data in memcache."""
|
||||
prefix = 'admin:jetpack:upgrade:'
|
||||
|
||||
def __init__(self):
|
||||
self.version_key = self.prefix + 'version'
|
||||
self.file_key = self.prefix + 'files'
|
||||
self.jetpack_key = self.prefix + 'jetpack'
|
||||
|
||||
def jetpack_versions(self, min_=None, max_=None):
|
||||
if None not in (min_, max_):
|
||||
d = {'min': min_, 'max': max_}
|
||||
return cache.set(self.jetpack_key, d)
|
||||
d = cache.get(self.jetpack_key, {})
|
||||
return d.get('min'), d.get('max')
|
||||
|
||||
def version(self, val=None):
|
||||
if val is not None:
|
||||
return cache.add(self.version_key, val)
|
||||
return cache.get(self.version_key)
|
||||
|
||||
def files(self, val=None):
|
||||
if val is not None:
|
||||
current = cache.get(self.file_key, {})
|
||||
current.update(val)
|
||||
return cache.set(self.file_key, val)
|
||||
return cache.get(self.file_key, {})
|
||||
|
||||
def file(self, file_id, val=None):
|
||||
file_id = int(file_id)
|
||||
if val is not None:
|
||||
current = cache.get(self.file_key, {})
|
||||
current[file_id] = val
|
||||
cache.set(self.file_key, current)
|
||||
return val
|
||||
return cache.get(self.file_key, {}).get(file_id, {})
|
||||
|
||||
def cancel(self):
|
||||
cache.delete(self.version_key)
|
||||
newfiles = dict([(k, v) for (k, v) in self.files().items()
|
||||
if v.get('owner') != 'bulk'])
|
||||
cache.set(self.file_key, newfiles)
|
||||
|
||||
def finish(self, file_id):
|
||||
file_id = int(file_id)
|
||||
newfiles = dict([(k, v) for (k, v) in self.files().items()
|
||||
if k != file_id])
|
||||
cache.set(self.file_key, newfiles)
|
||||
if not newfiles:
|
||||
cache.delete(self.version_key)
|
||||
|
||||
|
||||
def zip_folder_content(folder, filename):
|
||||
"""Compress the _content_ of a folder."""
|
||||
with zipfile.ZipFile(filename, 'w', zipfile.ZIP_DEFLATED) as dest:
|
||||
|
|
|
@ -17,10 +17,6 @@ from olympia.versions.models import Version
|
|||
log = olympia.core.logger.getLogger('z.api')
|
||||
|
||||
|
||||
# For app version major.minor matching.
|
||||
m_dot_n_re = re.compile(r'^\d+\.\d+$')
|
||||
|
||||
|
||||
def addon_to_dict(addon, disco=False, src='api'):
|
||||
"""
|
||||
Renders an addon in JSON for the API.
|
||||
|
|
|
@ -67,10 +67,6 @@ class RequiredInputMixin(object):
|
|||
return super(RequiredInputMixin, self).render(name, value, attrs)
|
||||
|
||||
|
||||
class RequiredTextInput(RequiredInputMixin, forms.TextInput):
|
||||
"""A Django TextInput with required attributes."""
|
||||
|
||||
|
||||
class RequiredEmailInput(RequiredInputMixin, forms.EmailInput):
|
||||
"""A Django EmailInput with required attributes."""
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче