From 78145b4670b4a06d749848b4f60bc43892d7baf2 Mon Sep 17 00:00:00 2001 From: Christopher Grebs Date: Fri, 7 Apr 2017 17:50:42 +0700 Subject: [PATCH] Remove more unused code. Most of it are leftovers from other cleanups. --- services/update.py | 17 ----- services/utils.py | 5 -- src/olympia/accounts/serializers.py | 8 --- src/olympia/addons/models.py | 7 -- src/olympia/addons/utils.py | 1 - src/olympia/addons/views.py | 17 ----- src/olympia/amo/models.py | 13 ---- src/olympia/amo/search.py | 2 - src/olympia/api/models.py | 4 -- src/olympia/browse/views.py | 7 +- src/olympia/devhub/urls.py | 2 - src/olympia/files/tests/test_utils_.py | 50 -------------- src/olympia/files/utils.py | 91 -------------------------- src/olympia/legacy_api/utils.py | 4 -- src/olympia/users/widgets.py | 4 -- 15 files changed, 1 insertion(+), 231 deletions(-) diff --git a/services/update.py b/services/update.py index 1555c52dff..82b25fd23b 100644 --- a/services/update.py +++ b/services/update.py @@ -75,7 +75,6 @@ no_updates_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)) diff --git a/services/utils.py b/services/utils.py index 5d5ebbddc5..e04c843ac8 100644 --- a/services/utils.py +++ b/services/utils.py @@ -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) diff --git a/src/olympia/accounts/serializers.py b/src/olympia/accounts/serializers.py index acc4f9aa40..d5bafc7bd6 100644 --- a/src/olympia/accounts/serializers.py +++ b/src/olympia/accounts/serializers.py @@ -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': '*:*', diff --git a/src/olympia/addons/models.py b/src/olympia/addons/models.py index 4a05bb0147..8d254b7940 100644 --- a/src/olympia/addons/models.py +++ b/src/olympia/addons/models.py @@ -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 = ( diff --git a/src/olympia/addons/utils.py b/src/olympia/addons/utils.py index 0d5fec74cd..e780cbbb95 100644 --- a/src/olympia/addons/utils.py +++ b/src/olympia/addons/utils.py @@ -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(): diff --git a/src/olympia/addons/views.py b/src/olympia/addons/views.py index 2e899b8a39..19c3d92d24 100644 --- a/src/olympia/addons/views.py +++ b/src/olympia/addons/views.py @@ -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): diff --git a/src/olympia/amo/models.py b/src/olympia/amo/models.py index 0fcbf15ef9..761583e1f2 100644 --- a/src/olympia/amo/models.py +++ b/src/olympia/amo/models.py @@ -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 diff --git a/src/olympia/amo/search.py b/src/olympia/amo/search.py index b06816eb86..1579243d3a 100644 --- a/src/olympia/amo/search.py +++ b/src/olympia/amo/search.py @@ -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): diff --git a/src/olympia/api/models.py b/src/olympia/api/models.py index b95470beb6..118cd131c9 100644 --- a/src/olympia/api/models.py +++ b/src/olympia/api/models.py @@ -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') diff --git a/src/olympia/browse/views.py b/src/olympia/browse/views.py index 8f7f0a7567..8c770e2629 100644 --- a/src/olympia/browse/views.py +++ b/src/olympia/browse/views.py @@ -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' diff --git a/src/olympia/devhub/urls.py b/src/olympia/devhub/urls.py index 68585ff369..2787eb65f4 100644 --- a/src/olympia/devhub/urls.py +++ b/src/olympia/devhub/urls.py @@ -8,8 +8,6 @@ from olympia.lib.misc.urlconf_decorator import decorate from . import views -PACKAGE_NAME = '(?P[_\w]+)' - # These will all start with /theme// theme_detail_patterns = patterns( diff --git a/src/olympia/files/tests/test_utils_.py b/src/olympia/files/tests/test_utils_.py index 53cb6dc145..50b2a96f60 100644 --- a/src/olympia/files/tests/test_utils_.py +++ b/src/olympia/files/tests/test_utils_.py @@ -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): diff --git a/src/olympia/files/utils.py b/src/olympia/files/utils.py index 6e4364446c..a06e485e7b 100644 --- a/src/olympia/files/utils.py +++ b/src/olympia/files/utils.py @@ -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: diff --git a/src/olympia/legacy_api/utils.py b/src/olympia/legacy_api/utils.py index 1fe45f107a..6950ab267b 100644 --- a/src/olympia/legacy_api/utils.py +++ b/src/olympia/legacy_api/utils.py @@ -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. diff --git a/src/olympia/users/widgets.py b/src/olympia/users/widgets.py index ea5a66b208..af20eb8941 100644 --- a/src/olympia/users/widgets.py +++ b/src/olympia/users/widgets.py @@ -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."""