refactor, then flake8 our services py (#6583)
This commit is contained in:
Родитель
d0bd8d2041
Коммит
956ffe8685
2
Makefile
2
Makefile
|
@ -23,4 +23,4 @@ docs:
|
|||
$(MAKE) -C docs html
|
||||
|
||||
flake8:
|
||||
flake8 src/
|
||||
flake8 src/ services/
|
||||
|
|
|
@ -15,6 +15,11 @@ from utils import log_configure
|
|||
# This has to be imported after the settings so statsd knows where to log to.
|
||||
from django_statsd.clients import statsd
|
||||
|
||||
JAVA_PLUGIN_SUMO_URL = (
|
||||
'https://support.mozilla.org/'
|
||||
'kb/use-java-plugin-to-view-interactive-content')
|
||||
|
||||
|
||||
# Go configure the log.
|
||||
log_configure()
|
||||
|
||||
|
@ -22,7 +27,8 @@ error_log = olympia.core.logger.getLogger('z.pfs')
|
|||
|
||||
xml_template = """\
|
||||
<?xml version="1.0"?>
|
||||
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:pfs="http://www.mozilla.org/2004/pfs-rdf#">
|
||||
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:pfs="http://www.mozilla.org/2004/pfs-rdf#">
|
||||
|
||||
<RDF:Description about="urn:mozilla:plugin-results:$mimetype">
|
||||
<pfs:plugins><RDF:Seq>
|
||||
|
@ -45,9 +51,11 @@ xml_template = """\
|
|||
</RDF:RDF>
|
||||
"""
|
||||
|
||||
quicktime_re = re.compile(r'^image/(pict|png|tiff|x-(macpaint|pict|png|quicktime|sgi|targa|tiff))$')
|
||||
quicktime_re = re.compile(
|
||||
r'^image/(pict|png|tiff|x-(macpaint|pict|png|quicktime|sgi|targa|tiff))$')
|
||||
java_re = re.compile(r'^application/x-java-.*$')
|
||||
|
||||
|
||||
def get_output(data):
|
||||
g = defaultdict(str, [(k, jinja2.escape(v)) for k, v in data.iteritems()])
|
||||
|
||||
|
@ -97,14 +105,14 @@ def get_output(data):
|
|||
# We don't want to link users directly to the Java plugin because
|
||||
# we want to warn them about ongoing security problems first. Link
|
||||
# to SUMO.
|
||||
|
||||
plugin.update(
|
||||
name='Java Runtime Environment',
|
||||
manualInstallationURL='https://support.mozilla.org/kb/use-java-plugin-to-view-interactive-content')
|
||||
manualInstallationURL=JAVA_PLUGIN_SUMO_URL)
|
||||
|
||||
# End ridiculously huge and embarrassing if-else block.
|
||||
return output.substitute(plugin)
|
||||
|
||||
|
||||
def format_date(secs):
|
||||
return '%s GMT' % formatdate(time() + secs)[:25]
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
import os
|
||||
|
||||
from django.utils import importlib
|
||||
|
||||
|
||||
# get the right settings module
|
||||
settings = importlib.import_module(
|
||||
os.environ.get('DJANGO_SETTINGS_MODULE', 'settings_local'))
|
|
@ -11,13 +11,14 @@ from olympia.constants import base
|
|||
from services.utils import log_configure, log_exception, mypool
|
||||
from services.utils import settings, user_media_path, user_media_url
|
||||
|
||||
# Configure the log.
|
||||
log_configure()
|
||||
|
||||
# This has to be imported after the settings (utils).
|
||||
from django_statsd.clients import statsd
|
||||
|
||||
|
||||
# Configure the log.
|
||||
log_configure()
|
||||
|
||||
|
||||
class ThemeUpdate(object):
|
||||
|
||||
def __init__(self, locale, id_, qs=None):
|
||||
|
@ -95,11 +96,12 @@ class ThemeUpdate(object):
|
|||
self.cursor.execute(sql, self.data)
|
||||
row = self.cursor.fetchone()
|
||||
|
||||
row_to_dict = lambda row: dict(zip((
|
||||
'persona_id', 'addon_id', 'slug', 'current_version', 'name',
|
||||
'description', 'username', 'header', 'footer', 'accentcolor',
|
||||
'textcolor', 'modified'),
|
||||
list(row)))
|
||||
def row_to_dict(row):
|
||||
return dict(zip((
|
||||
'persona_id', 'addon_id', 'slug', 'current_version', 'name',
|
||||
'description', 'username', 'header', 'footer', 'accentcolor',
|
||||
'textcolor', 'modified'),
|
||||
list(row)))
|
||||
|
||||
if row:
|
||||
self.data['row'] = row_to_dict(row)
|
||||
|
@ -205,7 +207,6 @@ def application(environ, start_response):
|
|||
|
||||
status = '200 OK'
|
||||
with statsd.timer('services.theme_update'):
|
||||
data = environ['wsgi.input'].read()
|
||||
try:
|
||||
locale, id_ = url_re.match(environ['PATH_INFO']).groups()
|
||||
locale = (locale or 'en-US').lstrip('/')
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
import smtplib
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
from django.utils.encoding import force_bytes
|
||||
from email.Utils import formatdate
|
||||
from email.mime.text import MIMEText
|
||||
from time import time
|
||||
from urlparse import parse_qsl
|
||||
|
||||
|
@ -13,9 +10,6 @@ from services.utils import mypool, settings
|
|||
# This has to be imported after the settings so statsd knows where to log to.
|
||||
from django_statsd.clients import statsd
|
||||
|
||||
import MySQLdb as mysql
|
||||
import sqlalchemy.pool as pool
|
||||
|
||||
try:
|
||||
from compare import version_int
|
||||
except ImportError:
|
||||
|
@ -27,6 +21,7 @@ import olympia.core.logger
|
|||
from utils import (
|
||||
APP_GUIDS, get_cdn_url, log_configure, PLATFORMS)
|
||||
|
||||
|
||||
# Go configure the log.
|
||||
log_configure()
|
||||
|
||||
|
|
|
@ -1,25 +1,15 @@
|
|||
import logging
|
||||
import logging.config
|
||||
import os
|
||||
import urllib
|
||||
|
||||
# get the right settings module
|
||||
settingmodule = os.environ.get('DJANGO_SETTINGS_MODULE', 'settings_local')
|
||||
if settingmodule.startswith(('zamboni', # typical git clone destination
|
||||
'workspace', # Jenkins
|
||||
'freddo')):
|
||||
settingmodule = settingmodule.split('.', 1)[1]
|
||||
|
||||
|
||||
import posixpath
|
||||
import re
|
||||
import sys
|
||||
import urllib
|
||||
|
||||
import MySQLdb as mysql
|
||||
import sqlalchemy.pool as pool
|
||||
|
||||
from django.utils import importlib
|
||||
settings = importlib.import_module(settingmodule)
|
||||
from .settings import settings
|
||||
|
||||
import olympia.core.logger
|
||||
from olympia.lib.log_settings_base import formatters, handlers
|
||||
|
|
|
@ -8,4 +8,4 @@ for path in ['../', '../..',
|
|||
'../../apps']:
|
||||
site.addsitedir(os.path.abspath(os.path.join(wsgidir, path)))
|
||||
|
||||
from ..pfs import application
|
||||
from ..pfs import application # noqa
|
||||
|
|
|
@ -9,4 +9,4 @@ for path in ['../',
|
|||
'../../apps']:
|
||||
site.addsitedir(os.path.abspath(os.path.join(wsgidir, path)))
|
||||
|
||||
from ..theme_update import application
|
||||
from ..theme_update import application # noqa
|
||||
|
|
|
@ -10,4 +10,4 @@ for path in ['../',
|
|||
'../../apps']:
|
||||
site.addsitedir(os.path.abspath(os.path.join(wsgidir, path)))
|
||||
|
||||
from update import application
|
||||
from update import application # noqa
|
||||
|
|
Загрузка…
Ссылка в новой задаче