Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
migrate apps/amo/utils.py
Browse files Browse the repository at this point in the history
  • Loading branch information
eviljeff committed Dec 31, 2014
1 parent 356c6da commit 66d0c68
Show file tree
Hide file tree
Showing 80 changed files with 956 additions and 1,054 deletions.
60 changes: 0 additions & 60 deletions apps/amo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import threading

import commonware.log
from caching.base import CachingQuerySet

from mkt.constants.applications import *
from mkt.constants.base import *
Expand All @@ -31,65 +30,6 @@ def set_user(user):
_locals.user = user


def cached_property(*args, **kw):
# Handles invocation as a direct decorator or
# with intermediate keyword arguments.
if args: # @cached_property
return CachedProperty(args[0])
else: # @cached_property(name=..., writable=...)
return lambda f: CachedProperty(f, **kw)


class CachedProperty(object):
"""
A decorator that converts a function into a lazy property. The
function wrapped is called the first time to retrieve the result
and than that calculated result is used the next time you access
the value::
class Foo(object):
@cached_property
def foo(self):
# calculate something important here
return 42
Lifted from werkzeug.
"""

def __init__(self, func, name=None, doc=None, writable=False):
self.func = func
self.writable = writable
self.__name__ = name or func.__name__
self.__doc__ = doc or func.__doc__

def __get__(self, obj, type=None):
if obj is None:
return self
_missing = object()
value = obj.__dict__.get(self.__name__, _missing)
if value is _missing:
value = self.func(obj)
if isinstance(value, CachingQuerySet):
# Work around a bug in django-cache-machine that
# causes deadlock or infinite recursion if
# CachingQuerySets are cached before they run their
# query.
value._fetch_all()
obj.__dict__[self.__name__] = value
return value

def __set__(self, obj, value):
if not self.writable:
raise TypeError('read only attribute')
obj.__dict__[self.__name__] = value

def __delete__(self, obj):
if not self.writable:
raise TypeError('read only attribute')
del obj.__dict__[self.__name__]


# We need to import waffle here to avoid a circular import with jingo which
# loads all INSTALLED_APPS looking for helpers.py files, but some of those apps
# import jingo.
Expand Down
5 changes: 2 additions & 3 deletions apps/amo/tests/ospatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,9 @@ def __call__(self, *args, **kw):
or 'django/core/files/storage.py:url' in file_fn
or 'django/core/files/storage.py:save' in file_fn
or 'django/core/files/storage.py:delete' in file_fn
or 'amo/utils.py:path' in file_fn # storage API
or 'mkt/site/utils.py:path' in file_fn # storage API
# These need to operate on local files.
or 'amo/utils.py:rm_local_tmp_dir' in file_fn
or 'amo/utils.py:rm_local_tmp_file' in file_fn
or 'mkt/site/utils.py:rm_local_tmp_dir' in file_fn
or 'files/utils.py:extract_xpi' in file_fn
or 'payments/models.py:generate_private_key' in file_fn
# Ignore some test code.
Expand Down
230 changes: 0 additions & 230 deletions apps/amo/tests/test_amo_utils.py

This file was deleted.

16 changes: 0 additions & 16 deletions apps/amo/tests/test_utils_.py

This file was deleted.

2 changes: 1 addition & 1 deletion lib/es/management/commands/reindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from django.core.management.base import BaseCommand, CommandError

import mkt.feed.indexers as f_indexers
from amo.utils import chunked, timestamp_index
from lib.es.models import Reindexing
from mkt.site.utils import chunked, timestamp_index
from mkt.webapps.indexers import WebappIndexer


Expand Down
2 changes: 1 addition & 1 deletion migrations/465-generate-image-assets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from amo.utils import chunked
from mkt.site.utils import chunked

from mkt.developers.tasks import generate_image_assets
from mkt.webapps.models import Webapp
Expand Down
2 changes: 1 addition & 1 deletion migrations/468-delete-dupe-assets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from amo.utils import chunked
from mkt.site.utils import chunked

from mkt.constants import APP_IMAGE_SIZES
from mkt.webapps.models import ImageAsset, Webapp
Expand Down
2 changes: 1 addition & 1 deletion migrations/479-regenerate-image-assets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from amo.utils import chunked
from mkt.site.utils import chunked

from mkt.developers.tasks import generate_image_assets
from mkt.webapps.models import Webapp
Expand Down
2 changes: 1 addition & 1 deletion migrations/482-generate-featured-image-assets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from amo.utils import chunked
from mkt.site.utils import chunked

from mkt.developers.tasks import generate_image_assets
from mkt.webapps.models import Webapp
Expand Down
2 changes: 1 addition & 1 deletion migrations/488-reindex-ratings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from celeryutils import task

from amo.utils import chunked
from mkt.site.utils import chunked
from mkt.site.decorators import write
from mkt.webapps.models import Webapp

Expand Down
2 changes: 1 addition & 1 deletion migrations/503-gaia-device-type.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import amo
from addons.models import AddonDeviceType as ADT
from amo.utils import chunked
from mkt.site.utils import chunked
from mkt.site.decorators import write


Expand Down
2 changes: 1 addition & 1 deletion migrations/596-theme-checksums.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from addons.models import Persona
from addons.tasks import calc_checksum
from amo.utils import chunked
from mkt.site.utils import chunked


def run():
Expand Down

0 comments on commit 66d0c68

Please sign in to comment.