Enabled support for pyflakes in pontoon.

This commit is contained in:
Jot 2015-10-13 21:04:06 +02:00
Родитель e54fdb92e4
Коммит a5670b024d
37 изменённых файлов: 69 добавлений и 169 удалений

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

@ -9,6 +9,7 @@ install:
before_script:
- psql -c 'create database pontoon;' -U postgres
script:
- pylama
- python manage.py test
addons:
postgresql: "9.4"

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

@ -7,7 +7,6 @@ from optparse import make_option
from pootle_store.models import Store, Unit
import codecs
import io
import json
import subprocess

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

@ -1,5 +1,4 @@
import codecs
import configparser
import datetime
import fnmatch
import logging
@ -92,8 +91,6 @@ def get_locale_directory(project, locale):
}
# Projects not using locale directories (format=file)
formats = Resource.objects.filter(project=project).values_list(
'format', flat=True).distinct()
if project.repository_type == 'file':
return {
'name': '',
@ -742,7 +739,7 @@ def dump_po(project, locale, relative_path):
if 'fuzzy' in entry.flags:
entry.flags.remove('fuzzy')
except Translation.DoesNotExist as e:
except Translation.DoesNotExist:
pass
else:
@ -760,7 +757,7 @@ def dump_po(project, locale, relative_path):
if 'fuzzy' in entry.flags:
entry.flags.remove('fuzzy')
except Translation.DoesNotExist as e:
except Translation.DoesNotExist:
pass
# Remove obsolete plural forms if exist
@ -791,7 +788,6 @@ def dump_xliff(project, locale, relative_path):
locale_directory_path = get_locale_directory(project, locale)["path"]
path = os.path.join(locale_directory_path, relative_path)
resource = Resource.objects.filter(project=project, path=relative_path)
entities = Entity.objects.filter(resource=resource, obsolete=False)
with open(path, 'r+') as f:
xf = xliff.xlifffile(f)
@ -805,9 +801,8 @@ def dump_xliff(project, locale, relative_path):
try:
entity = Entity.objects.get(resource=resource, key=key)
except Entity.DoesNotExist as e:
log.error('%s: Entity "%s" does not exist' % (path, original))
except Entity.DoesNotExist:
log.error('%s: Entity "%s" does not exist' % (path, key))
continue
try:
@ -816,7 +811,7 @@ def dump_xliff(project, locale, relative_path):
.latest('date').string
unit.settarget(translation)
except Translation.DoesNotExist as e:
except Translation.DoesNotExist:
# Remove "approved" attribute
try:
del unit.xmlelement.attrib['approved']
@ -861,7 +856,7 @@ def dump_silme(parser, project, locale, relative_path):
.latest('date')
structure.modify_entity(key, translation.string)
except Translation.DoesNotExist as e:
except Translation.DoesNotExist:
# Remove untranslated and following newline
pos = structure.entity_pos(key)
structure.remove_entity(key)
@ -879,7 +874,7 @@ def dump_silme(parser, project, locale, relative_path):
structure.remove_element(pos)
# Obsolete entities
except KeyError as e:
except KeyError:
pass
# Erase file and then write, otherwise content gets appended
@ -924,7 +919,7 @@ def dump_lang(project, locale, relative_path):
try:
resource = Resource.objects.get(project=project, path=relative_path)
except Resource.DoesNotExist as e:
except Resource.DoesNotExist:
log.info("Resource does not exist")
return
@ -952,7 +947,7 @@ def dump_lang(project, locale, relative_path):
try:
entity = Entity.objects.get(
resource=resource, string=original)
except Entity.DoesNotExist as e:
except Entity.DoesNotExist:
log.error('%s: Entity "%s" does not exist' %
(path, original))
continue
@ -965,7 +960,7 @@ def dump_lang(project, locale, relative_path):
if translation == original:
translation += ' {ok}'
except Translation.DoesNotExist as e:
except Translation.DoesNotExist:
translation = original
# Erase file and then write, otherwise content gets appended
@ -989,9 +984,6 @@ def dump_l20n(project, locale, relative_path):
structure = parser.parse(f.read())
ast = L20nast
resource = Resource.objects.filter(project=project, path=relative_path)
entities = Entity.objects.filter(resource=resource, obsolete=False)
for obj in structure.body:
if obj.type == "Entity":
@ -1006,7 +998,7 @@ def dump_l20n(project, locale, relative_path):
.latest('date')
attr.value.content[0] = translation.string
except Translation.DoesNotExist as e:
except Translation.DoesNotExist:
# Remove untranslated
obj.attrs.remove(attr)
@ -1021,7 +1013,7 @@ def dump_l20n(project, locale, relative_path):
.latest('date')
obj.value.content[0] = translation.string
except Translation.DoesNotExist as e:
except Translation.DoesNotExist:
# Remove untranslated
obj.value = None
@ -1053,7 +1045,7 @@ def dump_l20n(project, locale, relative_path):
)
obj.value.items.append(hashItem)
except Translation.DoesNotExist as e:
except Translation.DoesNotExist:
# Untranslated already removed on empty items
pass

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

@ -1,6 +1,3 @@
import datetime
from django.contrib.auth.models import User
from django.core.management.base import BaseCommand, CommandError
from pontoon.administration.files import dump_from_database, update_from_repository, extract_to_database

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

@ -2,8 +2,6 @@ from datetime import datetime
from django.contrib.auth.models import Permission, User
from django.core.management.base import (
BaseCommand,
CommandError,
NoArgsCommand,
)
from pontoon.base.models import Translation

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

@ -1,6 +1,3 @@
import datetime
from django.core.management.base import BaseCommand, CommandError
from pontoon.administration.files import (

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

@ -1,3 +0,0 @@
from django.db import models
# Create your models here.

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

@ -26,10 +26,6 @@ urlpatterns = patterns(
url(r'^repository/$', views.update_from_repository,
name='pontoon.admin.repository.update'),
# Update from Transifex
url(r'^transifex/$', views.update_from_transifex,
name='pontoon.admin.transifex.update'),
# Get slug
url(r'^get-slug/$', views.get_slug,
name='pontoon.admin.get_slug'),

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

@ -1,8 +1,5 @@
import base64
import json
import logging
import os
import shutil
import traceback
from django.core.urlresolvers import reverse
@ -21,12 +18,9 @@ from pontoon.administration.forms import (
)
from pontoon.base import utils
from pontoon.base.models import (
Entity,
Locale,
Project,
Repository,
Resource,
UserProfile,
get_projects_with_stats,
)
@ -90,7 +84,6 @@ def manage_project(request, slug=None, template='admin_project.html'):
subtitle = 'Add project'
pk = None
project = None
message = 'Please wait while strings are imported from the repository.'
# Save project
if request.method == 'POST':
@ -249,67 +242,3 @@ def update_from_repository(request, template=None):
}), content_type='application/json')
return HttpResponse("200")
def update_from_transifex(request, template=None):
"""Update all project locales from Transifex repository."""
log.debug("Update all project locales from Transifex repository.")
if not request.user.has_perm('base.can_manage'):
return render(request, '403.html', status=403)
if request.method != 'POST':
log.error("Non-POST request")
raise Http404
try:
pk = request.POST['pk']
transifex_project = request.POST['transifex_project']
transifex_resource = request.POST['transifex_resource']
except MultiValueDictKeyError as e:
log.error(str(e))
return HttpResponse("error")
try:
p = Project.objects.get(pk=pk)
except Project.DoesNotExist as e:
log.error(str(e))
return HttpResponse("error")
"""Check if user authenticated to Transifex."""
profile = UserProfile.objects.get(user=request.user)
username = request.POST.get(
'transifex_username', profile.transifex_username)
password = request.POST.get(
'transifex_password', base64.decodestring(profile.transifex_password))
if len(username) == 0 or len(password) == 0:
return HttpResponse("authenticate")
for l in p.locales.all():
"""Make GET request to Transifex API."""
response = utils.req('get', transifex_project, transifex_resource,
l.code, username, password)
"""Save or update Transifex data to DB."""
if hasattr(response, 'status_code') and response.status_code == 200:
entities = json.loads(response.content)
for entity in entities:
_save_entity(project=p, string=entity["key"],
comment=entity["comment"])
if len(entity["translation"]) > 0:
e = Entity.objects.get(project=p, string=entity["key"])
_save_translation(
entity=e, locale=l, string=entity["translation"])
log.debug("Transifex data for " + l.name + " saved to DB.")
else:
return HttpResponse(response)
"""Save Transifex username and password."""
if 'remember' in request.POST and request.POST['remember'] == "on":
profile.transifex_username = request.POST['transifex_username']
profile.transifex_password = base64.encodestring(
request.POST['transifex_password'])
profile.save()
return HttpResponse(response.status_code)

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

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations
def add_cldr_plurals_to_locales(apps, schema_editor):

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

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations
import jsonfield.fields
import pontoon.base.models

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

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations
class Migration(migrations.Migration):

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

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations
def remove_unused_locales(apps, schema_editor):

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

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations
def add_back_source_locales(apps, schema_editor):

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

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations
class Migration(migrations.Migration):

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

@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations
def add_tagalog_locale(apps, schema_editor):
Locale = apps.get_model('base', 'Locale')
locale = Locale.objects.create(
Locale.objects.create(
code='tl',
name='Tagalog',
nplurals=2,

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

@ -3,7 +3,7 @@ from __future__ import unicode_literals
import json
from django.db import models, migrations
from django.db import migrations
import jsonfield.fields

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

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations
def change_chinese_plurals(apps, schema_editor):

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

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations
class Migration(migrations.Migration):

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

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations
def complete_plurals(apps, schema_editor):

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

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations
def remove_pa_fy(apps, schema_editor):

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

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations
class Migration(migrations.Migration):

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

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations
class Migration(migrations.Migration):

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

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations
import jsonfield.fields

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

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations
class Migration(migrations.Migration):

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

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations
def remove_deleted_migrations(apps, schema_editor):

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

@ -404,7 +404,9 @@ class TranslationQuerySetTests(TestCase):
return submission date and user.
"""
latest_submission = self._translation(self.user0, submitted=(1970, 1, 3), approved=None)
latest_approval = self._translation(self.user1, submitted=(1970, 1, 1), approved=(1970, 1, 2))
# latest approval
self._translation(self.user1, submitted=(1970, 1, 1), approved=(1970, 1, 2))
assert_equal(Translation.objects.all().latest_activity(), {
'date': latest_submission.date,
'user': latest_submission.user
@ -415,7 +417,9 @@ class TranslationQuerySetTests(TestCase):
If latest activity in Translation QuerySet is translation approval,
return approval date and user.
"""
latest_submission = self._translation(self.user0, submitted=(1970, 1, 2), approved=(1970, 1, 2))
# latest submission
self._translation(self.user0, submitted=(1970, 1, 2), approved=(1970, 1, 2))
latest_approval = self._translation(self.user1, submitted=(1970, 1, 1), approved=(1970, 1, 3))
assert_equal(Translation.objects.all().latest_activity(), {
'date': latest_approval.date,
@ -538,7 +542,9 @@ class UserTranslationManagerTests(TestCase):
first_contributor = self.create_contributor_with_translation_counts(approved=12, unapproved=1, needs_work=2,
date=aware_datetime(2015, 3, 2))
second_contributor = self.create_contributor_with_translation_counts(approved=2, unapproved=11, needs_work=2,
# Second contributor
self.create_contributor_with_translation_counts(approved=2, unapproved=11, needs_work=2,
date=aware_datetime(2015, 6, 1))
TranslationFactory.create_batch(5, approved=True, user=first_contributor, date=aware_datetime(2015, 7, 2))
@ -632,7 +638,8 @@ class EntityTests(TestCase):
other_project = ProjectFactory.create(
locales=[self.locale, other_locale]
)
obsolete_entity = EntityFactory.create(
# Obsolete_entity
EntityFactory.create(
obsolete=True,
resource=self.main_resource,
string='Obsolete String'
@ -724,12 +731,14 @@ class EntityTests(TestCase):
"""
Return entities in correct order.
"""
entity_second = EntityFactory.create(
# First entity
EntityFactory.create(
order=1,
resource=self.main_resource,
string='Second String'
)
entity_first = EntityFactory.create(
# Second entity
EntityFactory.create(
order=0,
resource=self.main_resource,
string='First String'

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

@ -1,5 +1,3 @@
from contextlib import nested
from django.core.urlresolvers import reverse
from django.shortcuts import render
from django.utils.timezone import now
@ -11,12 +9,10 @@ from pontoon.base.models import Project
from pontoon.base.utils import aware_datetime
from pontoon.base.tests import (
assert_redirects,
UserFactory,
LocaleFactory,
ProjectFactory,
ResourceFactory,
StatsFactory,
TranslationFactory,
TestCase,
)
@ -162,7 +158,7 @@ class ContributorsTests(TestCase):
"""
Calling the top_contributors should result in period being None.
"""
response = self.client.get('/contributors/')
self.client.get('/contributors/')
assert_true(self.mock_render.call_args[0][2]['period'] is None)
assert_true(self.mock_translations_manager.call_args[0][0] is None)
@ -171,12 +167,12 @@ class ContributorsTests(TestCase):
Checks how view handles invalid period, it result in period being None - displays all data.
"""
# If period parameter is invalid value
response = self.client.get('/contributors/?period=invalidperiod')
self.client.get('/contributors/?period=invalidperiod')
assert_true(self.mock_render.call_args[0][2]['period'] is None)
assert_true(self.mock_translations_manager.call_args[0][0] is None)
# Period shouldn't be negative integer
response = self.client.get('/contributors/?period=-6')
self.client.get('/contributors/?period=-6')
assert_true(self.mock_render.call_args[0][2]['period'] is None)
assert_true(self.mock_translations_manager.call_args[0][0] is None)
@ -185,6 +181,6 @@ class ContributorsTests(TestCase):
Checks if view sets and returns data for right period.
"""
with patch('django.utils.timezone.now', wraps=now, return_value=aware_datetime(2015, 7, 5)):
response = self.client.get('/contributors/?period=6')
self.client.get('/contributors/?period=6')
assert_equal(self.mock_render.call_args[0][2]['period'], 6)
assert_equal(self.mock_translations_manager.call_args[0][0], aware_datetime(2015, 1, 5))

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

@ -1,15 +1,10 @@
import base64
from collections import defaultdict
import datetime
import hashlib
import json
import Levenshtein
import logging
import math
import os
import pytz
import requests
import traceback
import xml.etree.ElementTree as ET
import urllib
@ -17,7 +12,6 @@ from dateutil.relativedelta import relativedelta
from django.conf import settings
from django.contrib import messages
from django.contrib.auth import authenticate, login
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.core.mail import send_mail
@ -27,8 +21,6 @@ from django.db.models import Count, F, Prefetch
from django.http import (
Http404,
HttpResponse,
HttpResponseBadRequest,
HttpResponseForbidden,
HttpResponseRedirect,
)
@ -37,7 +29,6 @@ from django.utils import timezone
from django.utils.datastructures import MultiValueDictKeyError
from django_browserid.views import Verify as BrowserIDVerifyBase
from operator import itemgetter
from pontoon.administration.vcs import commit_to_vcs
from pontoon.administration import files
from pontoon.base import utils
@ -48,7 +39,6 @@ from pontoon.base.models import (
Resource,
Subpage,
Translation,
Stats,
UserProfile,
get_locales_with_project_stats,
get_locales_with_stats,
@ -131,8 +121,6 @@ def project(request, slug, template='project.html'):
}
return HttpResponseRedirect(reverse('pontoon.home'))
locales = p.locales.all().order_by("name")
data = {
'locales': get_locales_with_project_stats(p),
'project': p,

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

@ -1,11 +1,11 @@
import sys
from .base import *
from .base import * # noqa
# Import local settings if they exist (usually only in development).
try:
from .local import *
from .local import * # noqa
except ImportError, exc:
pass
@ -14,6 +14,6 @@ except ImportError, exc:
TEST = len(sys.argv) > 1 and sys.argv[1] == 'test'
if TEST:
try:
from .test import *
from .test import * # noqa
except ImportError:
pass

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

@ -1,3 +0,0 @@
from django.contrib import admin
# Register your models here.

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

@ -1,3 +0,0 @@
from django.db import models
# Create your models here.

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

@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

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

@ -1,6 +1,3 @@
import os
import tempfile
from django_nose.tools import assert_equal
from pontoon.base.tests import (

12
pylama.ini Normal file
Просмотреть файл

@ -0,0 +1,12 @@
[pylama]
linters = pyflakes
[pylama:*/pontoon-intro/]
skip = 1
[pylama:docs/conf.py]
skip = 1
[pylama:bin/peep.py]
skip = 1

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

@ -206,3 +206,6 @@ kombu==3.0.26
amqp==1.4.6
# sha256: N4Ethjya0-NcBzTELgvwMgzow77YLNIK1UyzTRWBV7o
anyjson==0.3.3
# sha256: 8Q40TOv5GQPKIK20kXYNt01sQ7bwHFfld9L5HavACqg
pylama==6.4.0

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

@ -1,5 +1,3 @@
import os
from setuptools import setup, find_packages