Merge branch 'master' into staging

This commit is contained in:
Piotr Zalewa 2011-10-14 11:31:21 +01:00
Родитель 8bbca3eb39 efc62d88a2
Коммит 6234b7006d
11 изменённых файлов: 111 добавлений и 28 удалений

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

@ -75,7 +75,7 @@
<div id="editor-menu-wrapper">
<ul class="UI_Editor_Menu">
{% block app_content_menu_items %}{% endblock %}
{% if revision.package.public_permission != 2 %}
{% if revision.package.public_permission != 2 and user.is_authenticated %}
<li id="package-copy" title="Copy" class="UI_Editor_Menu_Button Icon_copy">
<a href="#"><span></span></a>
</li>

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

@ -3,7 +3,7 @@ Managers for the Profile models
"""
import commonware
from django.core.exceptions import MultipleObjectsReturned
from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist
from django.db import models
from django.db.models import Q
@ -19,15 +19,23 @@ class ProfileManager(models.Manager):
# for AMO users
by_nick = Q(nickname=username)
def _get_profile():
def _get_profile(queries):
try:
return self.get(by_nick | by_username)
return self.get(queries[0])
except ObjectDoesNotExist:
queries.pop(0)
if not queries:
raise
# try to find profile by the next query
return _get_profile(queries)
except MultipleObjectsReturned:
profiles = self.filter(by_nick | by_username)
log.debug("User (%s) has %d profiles, attempt %s" % (
username, len(profiles), _get_profile.index))
profiles = self.filter(queries[0])
log.debug("User (%s) has %d usernames: %s, attempt %s" % (
username, len(profiles),
str([(x.user.username, x.nickname) for x in profiles]),
_get_profile.index))
for p in profiles:
p.update_from_AMO()
@ -39,7 +47,7 @@ class ProfileManager(models.Manager):
', '.join([p.user.username for p in profiles])))
raise
_get_profile.index += 1
return _get_profile()
return _get_profile(queries)
except Exception, error:
log.critical("Getting profile for user (%s) failed" % username)
raise
@ -49,6 +57,7 @@ class ProfileManager(models.Manager):
# Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=681098
# PEP: http://www.python.org/dev/peps/pep-3104/
_get_profile.index = 0
return _get_profile()
# try to get profile in given order
return _get_profile([by_nick, by_username])

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

@ -1,3 +1,5 @@
import commonware
from django.conf import settings
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
@ -6,6 +8,9 @@ from django.db import models
from amo.helpers import get_amo_cursor
from person.managers import ProfileManager
log = commonware.log.getLogger('f.profile.models')
class Limit(models.Model):
email = models.CharField(max_length=255)
@ -53,13 +58,14 @@ class Profile(models.Model):
columns = ('id', 'email', 'username', 'display_name', 'email' ,
'homepage')
SQL = ('SELECT %s FROM %s WHERE username=%%s') % (
SQL = ('SELECT %s FROM %s WHERE id=%%s') % (
','.join(columns), settings.AUTH_DATABASE['TABLE'])
auth_cursor.execute(SQL, [self.nickname])
data = auth_cursor.fetchone()
auth_cursor.execute(SQL, [self.user.username])
row = auth_cursor.fetchone()
data = {}
for i in range(len(data)):
data[columns[i]] = data[i]
if row:
for i in range(len(row)):
data[columns[i]] = row[i]
if 'display_name' in data:
if data['display_name']:
@ -71,6 +77,8 @@ class Profile(models.Model):
if 'username' in data:
self.nickname = data['username']
log.debug('nickname "%s" updated from AMO by id (%s)' % (
self.nickname, self.user.username))
if 'homepage' in data:
self.homepage = data['homepage']

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

@ -19,6 +19,27 @@ from xpi import xpi_utils
log = commonware.log.getLogger('f.repackage')
def increment_version(version):
"""
Modify version string to indicate changes made by repacking
:attr: version (string) version to be modified
"""
version = str(version)
version_split = version.split('.')
if len(version_split) == 2:
return '%s.1' % version
if len(version_split) == 1:
return '%s.0.1' % version
try:
int(version_split[-1])
except ValueError:
return '%s.1' % version
else:
version_split[-1] = str(int(version_split[-1]) + 1)
return '.'.join(version_split)
class Extractor(object):
"""
@ -47,7 +68,8 @@ class Extractor(object):
'id': self.find('id'),
'type': self.find('type') or self.ADDON_EXTENSION,
'fullName': self.find('name'),
'version': self.find('version'),
# read version and increment the version number
'version': increment_version(self.find('version')),
'url': self.find('homepageURL'),
'description': self.find('description'),
'author': self.find('creator'),
@ -163,6 +185,9 @@ class Repackage(object):
log.debug("[%s] Done rebuilding XPI; cleaning up" % hashtag)
# clean up (sdk_dir is already removed)
self.cleanup()
# here find the created XPI and compare main dir list
# if not the same - copy the files from original XPI
return response
def get_manifest(self, package_overrides={}):
@ -189,7 +214,7 @@ class Repackage(object):
self.manifest['dependencies'] = ['addon-kit', 'api-utils']
def extract_packages(self, sdk_source_dir):
"""Builds SDK environment and calls the :method:`xpi.xpi_utils.build`
"""Builds SDK environment and calls the :meth:`xpi.xpi_utils.build`
:returns: temporary sdk_dir
"""

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

@ -16,7 +16,7 @@ from utils.test import TestCase
from django.conf import settings
from base.templatetags.base_helpers import hashtag
from repackage.helpers import Repackage
from repackage.helpers import Repackage, increment_version
log = commonware.log.getLogger('f.tests')
@ -84,3 +84,13 @@ class RepackageTest(TestCase):
raise SkipTest()
# I've got no idea how to copy icon16.png to main dir of the XPI
assert 'icon16.png' in filenames
def test_version_increment(self):
eq_('2.1.1', increment_version('2.1'))
eq_('abc.0.1', increment_version('abc'))
eq_('1.0.1', increment_version('1'))
eq_('1.2pre.1', increment_version('1.2pre'))
eq_('1.2.3pre.1', increment_version('1.2.3pre'))
eq_('2.1.2', increment_version('2.1.1'))
eq_('2.1.2.3', increment_version('2.1.2.2'))
eq_('1.2.3pre.2', increment_version('1.2.3pre.1'))

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

@ -27,6 +27,14 @@ class BadManifestFieldException(exceptions.SimpleException):
def _get_package_overrides(container, sdk_version=None):
"""
Prepare package overrides (from POST)
sdk_version is used to override the version if {sdk_version} provided in
optional container['version']
:attr: container (dict) list of overrides
:attr: sdk_version (string)
"""
version = container.get('version', None)
if version and sdk_version:
version = version.format(sdk_version=sdk_version)
@ -64,8 +72,8 @@ def rebuild(request):
"""Rebuild ``XPI`` file. It can be provided as POST['location']
:returns: (JSON) contains one field - hashtag it is later used to download
the xpi using :method:`xpi.views.check_download` and
:method:`xpi.views.get_download`
the xpi using :meth:`xpi.views.check_download` and
:meth:`xpi.views.get_download`
"""
# validate entries
secret = request.POST.get('secret', None)

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

@ -36,10 +36,11 @@ def setup_mapping():
}
es = get_es()
index = settings.ES_INDEXES['default']
try:
es.create_index_if_missing(settings.ES_INDEX)
es.create_index_if_missing(index)
es.put_mapping(Package._meta.db_table, package_mapping,
settings.ES_INDEX)
index)
except ElasticSearchException, e:
log.debug(e)

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

@ -73,10 +73,11 @@ def _get_average_activity():
return average
# TODO: ES has statistical facet that can provide average, but I couldn't
# get it working.
values = Package.search().values('activity')
qs = Package.search().filter(activity__gt=0)
values = qs.values('activity')[:qs.count()]
num = len(values)
if num > 0:
average = sum(v[1] for v in values) / len(values)
average = sum(v[1] for v in values) / num
else:
average = 0.2

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

@ -26,13 +26,32 @@ site.addsitedir(path('lib'))
site.addsitedir(path(''))
# Move the new items to the front of sys.path. (via virtualenv)
new_sys_path = []
new_sys_path = [path('vendor'), path('vendor/lib/python'), path('apps'), path('lib')]
for item in list(sys.path):
if item not in prev_sys_path:
new_sys_path.append(item)
sys.path.remove(item)
sys.path[:0] = new_sys_path
# XXX: for some reason this fixes the AttributeError exception
#File "[...]/FlightDeck/apps/jetpack/managers.py", line 11, in <module>
# log = commonware.log.getLogger('f.jetpack.managers')
# AttributeError: 'module' object has no attribute 'log'
import commonware.log
# Mock modules which fail on readthedocs.org
class Mock(object):
def __init__(self, *args):
pass
def __getattr__(self, name):
return Mock
MOCK_MODULES = ['MySQLdb']
for mod_name in MOCK_MODULES:
sys.modules[mod_name] = Mock()
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
# If extensions (or modules to document with autodoc) are in another directory,

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

@ -341,7 +341,9 @@ ENGAGE_ROBOTS = False
# For search:
# Checkout flightdeck-es and run bin/elasticsearch -f
ES_DISABLED = True
ES_INDEX = 'flightdeck'
ES_INDEXES = {
'default': 'flightdeck',
}
# ES_HOSTS = ['127.0.0.1:9201']
# Graphite reporting

2
vendor

@ -1 +1 @@
Subproject commit b955928b1540457397bb9f65753825be4a2f5458
Subproject commit 6d3f6f6940266de416d932fb3c109fd785c21dfe