Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

check.py ALL THE THINGS, r=lonnen

  • Loading branch information...
commit 93706e363c7fd87ca3822a10757936cb09879b8b 1 parent 821cebc
@peterbe peterbe authored
View
3  .pep8
@@ -0,0 +1,3 @@
+[pep8]
+# regarding E125, see https://github.com/jcrocholl/pep8/issues/126
+ignore=E125
View
19 INSTALL.md
@@ -83,5 +83,22 @@ but this is the basic command to run coverage tests on the
./manage.py test --cover-erase --with-coverage \
--cover-package=crashstats --cover-html
-
+
That'll create `./cover/index.html` for your viewing pleasures.
+
+
+Enable your pre-commit hook
+---------------------------
+
+Paste this into `.git/hooks/pre-commit`:
+
+ check.py | grep "\s" | grep -v 'unable to undefined names'
+ if [ "$?" -ne "1" ]
+ then
+ echo "Aborting commit. Fix above errors or do 'git commit --no-verify'."
+ exit 1
+ fi
+
+Then, make the file executable:
+
+ chmod +x .git/hooks/pre-commit
View
2  crashstats/auth/views.py
@@ -1,6 +1,6 @@
from django.conf import settings
from django.contrib import auth
-from django.shortcuts import redirect, render
+from django.shortcuts import redirect
from django.views.decorators.http import require_POST
from django.core.urlresolvers import reverse
from django.contrib import messages
View
9 crashstats/crashstats/models.py
@@ -88,9 +88,11 @@ def fetch(self, url, headers=None, method='get', data=None,
_clean_query(split.query))
if expect_json:
- cache_file = os.path.join(cache_file, '%s.json' % cache_key)
+ cache_file = os.path.join(cache_file,
+ '%s.json' % cache_key)
else:
- cache_file = os.path.join(cache_file, '%s.dump' % cache_key)
+ cache_file = os.path.join(cache_file,
+ '%s.dump' % cache_key)
if os.path.isfile(cache_file):
# but is it fresh enough?
@@ -255,7 +257,8 @@ def get(self, **kwargs):
# Operating systems can be specified for by version as
# well but, we only want to separate the results by OS
# if the selected, report type was by_os.
- if 'form_selection' in kwargs and kwargs.get('form_selection') == 'by_os':
+ if ('form_selection' in kwargs and
+ kwargs.get('form_selection') == 'by_os'):
params['separated_by'] = 'os'
url += '/separated_by/%(separated_by)s'
View
9 crashstats/crashstats/tests/test_models.py
@@ -233,7 +233,8 @@ def mocked_get(**options):
date_range_type='build'
)
- for count, product_version in enumerate(sorted(response['hits'], reverse=True), start=1):
+ hits = sorted(response['hits'], reverse=True)
+ for count, product_version in enumerate(hits, start=1):
for day in sorted(response['hits'][product_version]):
product = response['hits'][product_version][day]['product']
@@ -249,7 +250,8 @@ def mocked_get(**options):
date_range_type='report'
)
- for count, product_version in enumerate(sorted(response['hits'], reverse=True), start=1):
+ hits = sorted(response['hits'], reverse=True)
+ for count, product_version in enumerate(hits, start=1):
for day in sorted(response['hits'][product_version]):
current_day = day
@@ -274,7 +276,6 @@ def mocked_get(**options):
ok_(response['hits'])
eq_(operating_system, 'lin')
-
@mock.patch('requests.get')
def test_crashtrends(self, rget):
api = models.CrashTrends()
@@ -428,7 +429,7 @@ def mocked_get(**options):
u'flash_version': u'11.3.300.250',
u'duplicates': [None, None, None],
u'url': u'http://example.com',
- u'report_day': u'2012-05-31',
+ u'report_day': u'2012-05-31',
u'plugin_signature': u'hang | ZwYieldExecution',
u'browser_hangid': u'30a712a4-6512-479d-9a0a-48b4d8c7ca13',
u'browser_signature': 'hang | mozilla::plugins::',
View
28 crashstats/crashstats/tests/test_views.py
@@ -100,8 +100,13 @@ def tearDown(self):
@mock.patch('requests.get')
def test_handler500(self, rget):
- root_urlconf = __import__(settings.ROOT_URLCONF,
- globals(), locals(), ['urls'], -1)
+ root_urlconf = __import__(
+ settings.ROOT_URLCONF,
+ globals(),
+ locals(),
+ ['urls'],
+ -1
+ )
# ...so that we can access the 'handler500' defined in there
par, end = root_urlconf.handler500.rsplit('.', 1)
# ...which is an importable reference to the real handler500 function
@@ -253,8 +258,8 @@ def mocked_get(url, **options):
rget.side_effect = mocked_get
- # Test that in the event that no params are passed set_base_data will ensure
- # that the default product is used as a fallback.
+ # Test that in the event that no params are passed set_base_data will
+ # ensure that the default product is used as a fallback.
response = self.client.get(url)
eq_(response.status_code, 200)
@@ -448,7 +453,8 @@ def mocked_get(url, **options):
"currentRank": 0,
"previousRank": 1,
"first_report_exact": "2012-06-21T21:28:08",
- "versions": "2.0, 2.1, 3.0a2, 3.0b2, 3.1b1, 4.0a1, 4.0a2, 5.0a1",
+ "versions":
+ "2.0, 2.1, 3.0a2, 3.0b2, 3.1b1, 4.0a1, 4.0a2, 5.0a1",
"percentOfTotal": 0.24258064516128999,
"win_count": 56,
"changeInPercentOfTotal": 0.011139597126354983,
@@ -837,7 +843,8 @@ def mocked_get(url, **options):
"currentRank": 0,
"previousRank": 1,
"first_report_exact": "2012-06-21T21:28:08",
- "versions": "2.0, 2.1, 3.0a2, 3.0b2, 3.1b1, 4.0a1, 4.0a2, 5.0a1",
+ "versions":
+ "2.0, 2.1, 3.0a2, 3.0b2, 3.1b1, 4.0a1, 4.0a2, 5.0a1",
"percentOfTotal": 0.24258064516128999,
"win_count": 56,
"changeInPercentOfTotal": 0.011139597126354983,
@@ -892,12 +899,17 @@ def mocked_get(url, **options):
}
""")
if 'reports/hang' in url:
+ browser_signature = (
+ 'hang | mozilla::plugins::PPluginInstance'
+ 'Parent::CallNPP_HandleEvent(mozilla::plugins::NPRemoteEve'
+ 'nt const&, short*)'
+ )
return Response("""
{"currentPage": 1,
"endDate": "2012-06-01T00:00:00+00:00",
"hangReport": [{
"browser_hangid": "30a712a4-6512-479d-9a0a-48b4d8c7ca13",
- "browser_signature": "hang | mozilla::plugins::PPluginInstanceParent::CallNPP_HandleEvent(mozilla::plugins::NPRemoteEvent const&, short*)",
+ "browser_signature": "%s",
"duplicates": [
null,
null,
@@ -911,7 +923,7 @@ def mocked_get(url, **options):
}],
"totalCount": 1,
"totalPages": 1}
- """)
+ """ % browser_signature)
raise NotImplementedError(url)
View
46 crashstats/crashstats/urls.py
@@ -11,7 +11,8 @@
perm_legacy_redirect = settings.PERMANENT_LEGACY_REDIRECTS
-urlpatterns = patterns('',
+urlpatterns = patterns(
+ '', # prefix
url('^home' + products + '$',
views.home,
name='crashstats.home'),
@@ -48,7 +49,8 @@
url('^builds' + products + '$',
views.builds,
name='crashstats.builds'),
- # note the deliberate omission of the ';' despite calling the regex variable 'versionS'
+ # note the deliberate omission of the ';' despite calling the regex
+ # variable 'versionS'
url('^builds' + products + '/versions/(?P<versions>[\w\.()]+)' + '$',
views.builds,
name='crashstats.builds'),
@@ -92,7 +94,9 @@
'query_string': True}),
url(r'^buginfo/bug', views.buginfo,
name='crashstats.buginfo'),
- url(r'^topcrasher/plot_signature/(?P<product>\w+)/(?P<versions>[;\w\.()]+)/(?P<start_date>[0-9]{4}-[0-9]{2}-[0-9]{2})/(?P<end_date>[0-9]{4}-[0-9]{2}-[0-9]{2})/(?P<signature>.*)',
+ url(r'^topcrasher/plot_signature/(?P<product>\w+)/(?P<versions>[;\w\.()]+)'
+ r'/(?P<start_date>[0-9]{4}-[0-9]{2}-[0-9]{2})/'
+ r'(?P<end_date>[0-9]{4}-[0-9]{2}-[0-9]{2})/(?P<signature>.*)',
views.plot_signature,
name='crashstats.plot_signature'),
url(r'^signature_summary/json_data$',
@@ -125,22 +129,30 @@
redirect_to, {'url': '/home/products/%(product)s',
'permanent': perm_legacy_redirect}),
url(r'^products/(?P<product>\w+)/versions/(?P<versions>[;\w\.()]+)/$',
- redirect_to, {'url': '/home/products/%(product)s/versions/%(versions)s',
- 'permanent': perm_legacy_redirect}),
- url(r'^products/(?P<product>\w+)/versions/(?P<versions>[;\w\.()]+)/builds$',
- redirect_to, {'url': '/builds/products/%(product)s',
- 'permanent': perm_legacy_redirect}),
+ redirect_to,
+ {'url': '/home/products/%(product)s/versions/%(versions)s',
+ 'permanent': perm_legacy_redirect}),
+ url(r'^products/(?P<product>\w+)/versions/(?P<versions>[;\w\.()]+)/'
+ r'builds$',
+ redirect_to,
+ {'url': '/builds/products/%(product)s',
+ 'permanent': perm_legacy_redirect}),
url(r'^hangreport/byversion/(?P<product>\w+)$',
- redirect_to, {'url': '/hangreport/products/%(product)s',
- 'permanent': perm_legacy_redirect}),
+ redirect_to,
+ {'url': '/hangreport/products/%(product)s',
+ 'permanent': perm_legacy_redirect}),
url(r'^hangreport/byversion/(?P<product>\w+)/(?P<versions>[;\w\.()]+)$',
- redirect_to, {'url': '/hangreport/products/%(product)s/versions/%(versions)s',
- 'permanent': perm_legacy_redirect}),
- url(r'^products/(?P<product>\w+)/versions/(?P<versions>[;\w\.()]+)/topchangers$',
- redirect_to, {'url': '/topchangers/products/%(product)s',
- 'permanent': perm_legacy_redirect}),
+ redirect_to,
+ {'url': '/hangreport/products/%(product)s/versions/%(versions)s',
+ 'permanent': perm_legacy_redirect}),
+ url(r'^products/(?P<product>\w+)/versions/(?P<versions>[;\w\.()]+)/'
+ r'topchangers$',
+ redirect_to,
+ {'url': '/topchangers/products/%(product)s',
+ 'permanent': perm_legacy_redirect}),
url(r'^topcrasher/byversion/(?P<product>\w+)/(?P<versions>[;\w\.()]+)$',
- redirect_to, {'url': '/topcrasher/products/%(product)s/versions/%(versions)s',
- 'permanent': perm_legacy_redirect}),
+ redirect_to,
+ {'url': '/topcrasher/products/%(product)s/versions/%(versions)s',
+ 'permanent': perm_legacy_redirect}),
)
View
9 crashstats/crashstats/utils.py
@@ -30,8 +30,10 @@ def wrapper(*args, **kw):
if isinstance(response, http.HttpResponse):
return response
else:
- return http.HttpResponse(_json_clean(json.dumps(response)),
- content_type='application/json; charset=UTF-8')
+ return http.HttpResponse(
+ _json_clean(json.dumps(response)),
+ content_type='application/json; charset=UTF-8'
+ )
return wrapper
@@ -42,7 +44,8 @@ def _json_clean(value):
# in HTML, as it prevents </script> tags from prematurely terminating
# the javscript. Some json libraries do this escaping by default,
# although python's standard library does not, so we do it here.
- # http://stackoverflow.com/questions/1580647/json-why-are-forward-slashes-escaped
+ # http://stackoverflow.com/questions/1580647/json-why-are-forward-slashe\
+ # s-escaped
return value.replace("</", "<\\/")
View
2  crashstats/crashstats/views.py
@@ -1164,9 +1164,7 @@ def signature_summary(request):
range_value = int(request.GET.get('range_value'))
# FIXME only support "days"
- range_unit = request.GET.get('range_unit')
signature = request.GET.get('signature')
- product_version = request.GET.get('version')
end_date = datetime.datetime.utcnow()
start_date = end_date - datetime.timedelta(days=range_value)
View
0  crashstats/examples/__init__.py
No changes.
View
0  crashstats/examples/models.py
No changes.
View
36 crashstats/examples/templates/examples/bleach.html
@@ -1,36 +0,0 @@
-{% extends "example_base.html" %}
-
-{% block content %}
-<h1>Bleach</h1>
-<p>(back to the <a href="{{ url('examples.home') }}">main page</a>)</p>
-
-<p>An example showing how to use Bleach library to do user input sanitization.</p>
-
-<p>For more information, check out the <a href="https://github.com/jsocol/bleach/">
- Bleach README</a>.</p>
-
-<p>Enter some possibly harmful text here, hit send, and see what Bleach does
-with it.</p>
-
-<form id="bleachform" method="post" action="">
- {{ csrf() }}
- <textarea name="bleachme">{{ bleachme if bleachme else '' }}</textarea>
- <p>(Allowed tags: <code>&lt;strong&gt;</code>, <code>&lt;em&gt;</code>)</p>
- <button type="submit">Bleach!</button>
-</form>
-
-{% if bleached %}
-<section id="bleached">
- <p>Bleached, this became:</p>
- <p>{{ bleached }}</p>
-</section>
-{% endif %}
-
-<p>Some things to try out:</p>
-<ul id="bleachable">
- <li><code>an &lt;script&gt;evil()&lt;/script&gt; example</code></li>
- <li><code>Hello &lt;strong&gt;world&lt;/strong&gt;!</code></li>
- <li><code>Check out &lt;a href="http://mozilla.org"&gt;mozilla.org&lt;/a&gt;</code></li>
- <li><code>Unbalanced &lt;em&gt;tag</code></li>
-</ul>
-{% endblock %}
View
30 crashstats/examples/templates/examples/home.html
@@ -1,30 +0,0 @@
-{% extends "example_base.html" %}
-
-{% block content %}
-<h1>
- <a href="/">{{ _('Hello world') }}</a>
-</h1>
-
-{# L10n: This is a localizer comment #}
-{% if request.MOBILE %}
- <p>{{ _('This is a <em>test view</em> for mobile browsers.') }}</p>
-{% else %}
- <p>{{ _('This is a <em>test view</em> for desktop browsers.') }}</p>
-{% endif %}
-<p>
- {% trans docs_url='http://playdoh.rtfd.org/' %}
- <a href="{{ docs_url }}">Learn you some Playdoh</a> and then go build
- something <strong>awesome</strong>.
- {% endtrans %}
-</p>
-<p>
- {% trans langs=LANGUAGES.items() %}
- Current locale: {{ LANG }}.<br>
- Available locales: {{ langs }}.
- {% endtrans %}
-</p>
-<p>Some more examples:</p>
-<ul>
- <li><a href="{{ url('examples.bleach') }}">Input sanitization with Bleach</a></li>
-</ul>
-{% endblock %}
View
9 crashstats/examples/urls.py
@@ -1,9 +0,0 @@
-from django.conf.urls.defaults import *
-
-from . import views
-
-
-urlpatterns = patterns('',
- url(r'^$', views.home, name='examples.home'),
- url(r'^bleach/?$', views.bleach_test, name='examples.bleach'),
-)
View
45 crashstats/examples/views.py
@@ -1,45 +0,0 @@
-"""Example views. Feel free to delete this app."""
-
-import logging
-
-from django import http
-from django.shortcuts import render
-
-import bleach
-import commonware
-from funfactory.log import log_cef
-from mobility.decorators import mobile_template
-from session_csrf import anonymous_csrf
-
-
-log = commonware.log.getLogger('playdoh')
-
-
-@mobile_template('examples/{mobile/}home.html')
-def home(request, template=None):
- """Main example view."""
- data = {} # You'd add data here that you're sending to the template.
- log.debug("I'm alive!")
- return render(request, template, data)
-
-
-@anonymous_csrf
-def bleach_test(request):
- """A view outlining bleach's HTML sanitization."""
- allowed_tags = ('strong', 'em')
-
- data = {}
-
- if request.method == 'POST':
- bleachme = request.POST.get('bleachme', None)
- data['bleachme'] = bleachme
- if bleachme:
- data['bleached'] = bleach.clean(bleachme, tags=allowed_tags)
-
- # CEF logging: Log user input that needed to be "bleached".
- if data['bleached'] != bleachme:
- log_cef('Bleach Alert', logging.INFO, request,
- username='anonymous', signature='BLEACHED',
- msg='User data needed to be bleached: %s' % bleachme)
-
- return render(request, 'examples/bleach.html', data)
View
31 crashstats/locale/en_US/LC_MESSAGES/messages.po
@@ -1,31 +0,0 @@
-msgid ""
-msgstr ""
-"Project-Id-Version: PACKAGE VERSION\n"
-"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2011-05-26 18:11-0700\n"
-"PO-Revision-Date: 2011-05-26 18:11-0700\n"
-"Last-Translator: Automatically generated\n"
-"Language-Team: none\n"
-"Language: en_US\n"
-"MIME-Version: 1.0\n"
-"Content-Type: text/plain; charset=UTF-8\n"
-"Content-Transfer-Encoding: 8bit\n"
-"X-Generator: Translate Toolkit 1.8.0\n"
-"Plural-Forms: nplurals=2; plural=(n != 1);\n"
-
-#: apps/examples/templates/examples/home.html:5
-msgid "Hello world"
-msgstr "Hello world"
-
-#. This is a localizer comment
-#: apps/examples/templates/examples/home.html:9
-msgid "This is a <em>test view</em>."
-msgstr "This is a <em>test view</em>."
-
-#: apps/examples/templates/examples/home.html:11
-msgid "<a href=\"%(docs_url)s\">Learn you some Playdoh</a> and then go build something <strong>awesome</strong>."
-msgstr "<a href=\"%(docs_url)s\">Learn you some Playdoh</a> and then go build something <strong>awesome</strong>."
-
-#: apps/examples/templates/examples/home.html:17
-msgid "Current locale: %(LANG)s.<br> Available locales: %(langs)s."
-msgstr "Current locale: %(LANG)s.<br> Available locales: %(langs)s."
View
29 crashstats/locale/fr/LC_MESSAGES/messages.po
@@ -1,29 +0,0 @@
-msgid ""
-msgstr ""
-"Project-Id-Version: PACKAGE VERSION\n"
-"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2011-06-03 19:07-0700\n"
-"Last-Translator: Automatically generated\n"
-"Language-Team: none\n"
-"Language: fr\n"
-"MIME-Version: 1.0\n"
-"Content-Type: text/plain; charset=UTF-8\n"
-"Content-Transfer-Encoding: 8bit\n"
-"Plural-Forms: nplurals=2; plural=(n > 1);\n"
-
-#: apps/examples/templates/examples/home.html:5
-msgid "Hello world"
-msgstr "Bonjour le monde"
-
-#. This is a localizer comment
-#: apps/examples/templates/examples/home.html:9
-msgid "This is a <em>test view</em>."
-msgstr "Ceci est une <em>vue de test</em>."
-
-#: apps/examples/templates/examples/home.html:11
-msgid "<a href=\"%(docs_url)s\">Learn you some Playdoh</a> and then go build something <strong>awesome</strong>."
-msgstr "<a href=\"%(docs_url)s\">Apprends à jouer avec Playdoh</a> et construis quelque chose de <strong>génial</strong>."
-
-#: apps/examples/templates/examples/home.html:17
-msgid "Current locale: %(LANG)s.<br> Available locales: %(langs)s."
-msgstr "Langue active&nbsp;: %(LANG)s.<br> Langues disponibles&nbsp;: %(langs)s."
View
32 crashstats/locale/templates/LC_MESSAGES/messages.pot
@@ -1,32 +0,0 @@
-#, fuzzy
-msgid ""
-msgstr ""
-"Project-Id-Version: PACKAGE VERSION\n"
-"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2011-06-03 19:07-0700\n"
-"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
-"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
-"Language-Team: LANGUAGE <LL@li.org>\n"
-"MIME-Version: 1.0\n"
-"Content-Type: text/plain; charset=utf-8\n"
-"Content-Transfer-Encoding: 8bit\n"
-"X-Generator: Translate Toolkit 1.8.0\n"
-
-#: apps/examples/templates/examples/home.html:5
-msgid "Hello world"
-msgstr ""
-
-#. This is a localizer comment
-#: apps/examples/templates/examples/home.html:9
-msgid "This is a <em>test view</em>."
-msgstr ""
-
-#: apps/examples/templates/examples/home.html:11
-msgid ""
-"<a href=\"%(docs_url)s\">Learn you some Playdoh</a> and then go build "
-"something <strong>awesome</strong>."
-msgstr ""
-
-#: apps/examples/templates/examples/home.html:17
-msgid "Current locale: %(LANG)s.<br> Available locales: %(langs)s."
-msgstr ""
View
4 crashstats/settings/__init__.py
@@ -2,5 +2,7 @@
try:
from .local import *
except ImportError, exc:
- exc.args = tuple(['%s (did you rename settings/local.py-dist?)' % exc.args[0]])
+ exc.args = tuple(
+ ['%s (did you rename settings/local.py-dist?)' % exc.args[0]]
+ )
raise exc
View
3  crashstats/settings/base.py
@@ -93,7 +93,8 @@
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
- 'LOCATION': '127.0.0.1:11211', # fox2mike suggest to use IP instead of localhost
+ # fox2mike suggest to use IP instead of localhost
+ 'LOCATION': '127.0.0.1:11211',
'TIMEOUT': 500,
'KEY_PREFIX': 'crashstats',
}
View
17 crashstats/urls.py
@@ -19,26 +19,19 @@
from jingo_offline_compressor.jinja2ext import CompressorExtension
import jingo
try:
- jingo.env.extensions.pop('compressor.contrib.jinja2ext.CompressorExtension')
+ jingo.env.extensions.pop(
+ 'compressor.contrib.jinja2ext.CompressorExtension'
+ )
except KeyError:
# happens if the urlconf is loaded twice
pass
jingo.env.add_extension(CompressorExtension)
-# Uncomment the next two lines to enable the admin:
-# from django.contrib import admin
-# admin.autodiscover()
-urlpatterns = patterns('',
- # Example:
+urlpatterns = patterns(
+ '',
(r'', include(urls)),
(r'', include('crashstats.auth.urls', namespace='auth')),
-
- # Uncomment the admin/doc line below to enable admin documentation:
- # (r'^admin/doc/', include('django.contrib.admindocs.urls')),
-
- # Uncomment the next line to enable the admin:
- # (r'^admin/', include(admin.site.urls)),
)
## In DEBUG mode, serve media files through Django.
View
4 setup.py
@@ -1,5 +1,3 @@
-import os
-
from setuptools import setup, find_packages
@@ -12,6 +10,6 @@
license='',
url='',
include_package_data=True,
- classifiers = [],
+ classifiers=[],
packages=find_packages(exclude=['tests']),
install_requires=[])
Please sign in to comment.
Something went wrong with that request. Please try again.