PEP8 cleanups, add missing imports

This commit is contained in:
Roberto Rosario
2014-06-25 15:46:30 -04:00
parent 3ec31a890e
commit 20fa4a543d
11 changed files with 51 additions and 57 deletions

View File

@@ -1,10 +1,10 @@
from __future__ import absolute_import
import logging
from itertools import chain
import logging
from django.db import models
from django.core import serializers
from django.db import models
from django.utils.datastructures import SortedDict
from .exceptions import ExistingData, NotABootstrapSetup
@@ -40,7 +40,7 @@ class BootstrapModel(object):
@classmethod
def get_magic_number(cls):
return '%s %s' % (FIXTURE_METADATA_REMARK_CHARACTER, BOOTSTRAP_SETUP_MAGIC_NUMBER)
return '%s %s' % (FIXTURE_METADATA_REMARK_CHARACTER, BOOTSTRAP_SETUP_MAGIC_NUMBER)
@classmethod
def check_magic_number(cls, data):
@@ -102,7 +102,7 @@ class BootstrapModel(object):
app_name_splitted = None
if '.' in model_name:
app_name_splitted, model_name = model_name.split('.')
self.app_name = app_name_splitted or app_name
if not self.app_name:
raise Exception('Pass either a dotted app plus model name or a model name and a separate app name')
@@ -157,7 +157,7 @@ class FixtureMetadata(object):
self.property_name = property_name
self.read_function = read_function or (lambda x: x)
self.__class__._registry[id(self)] = self
def get_with_remark(self):
return '%s %s' % (FIXTURE_METADATA_REMARK_CHARACTER, self.literal)
@@ -169,4 +169,4 @@ class FixtureMetadata(object):
for line in fixture_data.splitlines(False):
if line.startswith(self.get_with_remark()):
# TODO: replace the "+ 4" with a space and next character finding algo
return self.read_function(line[len(self.literal) + 4:])
return self.read_function(line[len(self.literal) + 4:])

View File

@@ -4,7 +4,7 @@ from __future__ import absolute_import
class ExistingData(Exception):
"""
Raised when an attempt to execute a bootstrap setup is made and there is
existing data that would be corrupted or damaged by the loading the
existing data that would be corrupted or damaged by the loading the
bootstrap's fixture.
"""
pass

View File

@@ -17,8 +17,7 @@ class BootstrapSetupForm(forms.ModelForm):
model = BootstrapSetup
widgets = {
'description': forms.widgets.Textarea(attrs={
'rows': 5, 'cols': 80,
}
'rows': 5, 'cols': 80}
)
}
@@ -28,11 +27,11 @@ class BootstrapSetupForm_view(DetailForm):
model = BootstrapSetup
widgets = {
'description': forms.widgets.Textarea(attrs={
'rows': 5, 'cols': 80,
}
'rows': 5, 'cols': 80}
)
}
class BootstrapSetupForm_edit(BootstrapSetupForm):
class Meta(BootstrapSetupForm.Meta):
model = BootstrapSetup

View File

@@ -13,7 +13,7 @@ link_bootstrap_setup_list = {'text': _(u'bootstrap setup list'), 'view': 'bootst
link_bootstrap_setup_create = {'text': _(u'create new bootstrap setup'), 'view': 'bootstrap_setup_create', 'famfam': 'lightning_add', 'permissions': [PERMISSION_BOOTSTRAP_CREATE]}
link_bootstrap_setup_edit = {'text': _(u'edit'), 'view': 'bootstrap_setup_edit', 'args': 'object.pk', 'famfam': 'pencil', 'permissions': [PERMISSION_BOOTSTRAP_EDIT]}
link_bootstrap_setup_delete = {'text': _(u'delete'), 'view': 'bootstrap_setup_delete', 'args': 'object.pk', 'famfam': 'lightning_delete', 'permissions': [PERMISSION_BOOTSTRAP_DELETE]}
link_bootstrap_setup_view = {'text': _(u'details'), 'view': 'bootstrap_setup_view', 'args': 'object.pk', 'famfam': 'lightning', 'permissions': [PERMISSION_BOOTSTRAP_VIEW]}
link_bootstrap_setup_view = {'text': _(u'details'), 'view': 'bootstrap_setup_view', 'args': 'object.pk', 'famfam': 'lightning', 'permissions': [PERMISSION_BOOTSTRAP_VIEW]}
link_bootstrap_setup_execute = {'text': _(u'execute'), 'view': 'bootstrap_setup_execute', 'args': 'object.pk', 'famfam': 'lightning_go', 'permissions': [PERMISSION_BOOTSTRAP_EXECUTE]}
link_bootstrap_setup_dump = {'text': _(u'dump current setup'), 'view': 'bootstrap_setup_dump', 'famfam': 'arrow_down', 'permissions': [PERMISSION_BOOTSTRAP_DUMP]}
link_bootstrap_setup_export = {'text': _(u'export'), 'view': 'bootstrap_setup_export', 'args': 'object.pk', 'famfam': 'disk', 'permissions': [PERMISSION_BOOTSTRAP_EXPORT]}

View File

@@ -19,7 +19,7 @@ FIXTURE_TYPE_XML = 'xml'
FIXTURE_TYPES_CHOICES = (
(FIXTURE_TYPE_JSON, _(u'JSON')),
# Disabing XML until a way to specify a null pk is found
#(FIXTURE_TYPE_XML, _(u'XML')),
# (FIXTURE_TYPE_XML, _(u'XML')),
)
FIXTURE_FILE_TYPE = {

View File

@@ -2,11 +2,10 @@ from __future__ import absolute_import
from optparse import make_option
from django.db import models, router, connections, DEFAULT_DB_ALIAS
from django.core.management import call_command
from django.core.management.base import NoArgsCommand, CommandError
from django.core.management.color import no_style
from django.core.management.sql import emit_post_sync_signal
from django.db import models, router, connections, DEFAULT_DB_ALIAS
from ...classes import Cleanup

View File

@@ -1,7 +1,5 @@
from __future__ import absolute_import
from optparse import make_option
from django.core.management.base import BaseCommand, CommandError
from ...models import BootstrapSetup

View File

@@ -4,11 +4,9 @@ import logging
import requests
from django.db import models
from django.core import serializers
from django.utils.simplejson import loads
from django.db import IntegrityError
from django.db import IntegrityError, models
from django.db.models import Q
from django.utils.simplejson import loads
from .classes import BootstrapModel, FixtureMetadata
from .literals import (FIXTURE_TYPE_FIXTURE_PROCESS, FIXTURE_TYPE_EMPTY_FIXTURE,
@@ -56,7 +54,7 @@ class BootstrapSetupManager(models.Manager):
def import_from_file(self, files):
file_data = files.read()
self.import_setup(file_data)
def import_from_url(self, url, **kwargs):
response = requests.get(url)
if response.status_code == requests.codes.ok:
@@ -72,4 +70,3 @@ class BootstrapSetupManager(models.Manager):
self.import_from_url(bootstrap_setup_url, overwrite=True)
else:
response.raise_for_status()

View File

@@ -1,9 +1,9 @@
from __future__ import absolute_import
import os
import tempfile
import re
import datetime
import os
import re
import tempfile
import slugify
@@ -12,15 +12,15 @@ try:
except ImportError:
from StringIO import StringIO
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.core import management
from django.core.files.uploadedfile import SimpleUploadedFile
from django.db import models
from django.utils.translation import ugettext_lazy as _
from .classes import BootstrapModel, FixtureMetadata
from .literals import (FIXTURE_TYPES_CHOICES, FIXTURE_FILE_TYPE, COMMAND_LOADDATA,
BOOTSTRAP_EXTENSION, FIXTURE_METADATA_REMARK_CHARACTER)
from .managers import BootstrapSetupManager
from .classes import BootstrapModel, FixtureMetadata
class BootstrapSetup(models.Model):
@@ -59,7 +59,7 @@ class BootstrapSetup(models.Model):
with open(filepath, 'w') as file_handle:
file_handle.write(self.cleaned_fixture)
content = StringIO()
management.call_command(COMMAND_LOADDATA, filepath, verbosity=0, stderr=content)
content.seek(0, os.SEEK_END)

View File

@@ -1,23 +1,23 @@
## {{{ http://code.activestate.com/recipes/578272/ (r1)
# {{{ http://code.activestate.com/recipes/578272/ (r1)
def toposort2(data):
"""Dependencies are expressed as a dictionary whose keys are items
and whose values are a set of dependent items. Output is a list of
sets in topological order. The first set consists of items with no
dependences, each subsequent set consists of items that depend upon
items in the preceeding sets.
and whose values are a set of dependent items. Output is a list of
sets in topological order. The first set consists of items with no
dependences, each subsequent set consists of items that depend upon
items in the preceeding sets.
>>> print '\\n'.join(repr(sorted(x)) for x in toposort2({
... 2: set([11]),
... 9: set([11,8]),
... 10: set([11,3]),
... 11: set([7,5]),
... 8: set([7,3]),
... }) )
[3, 5, 7]
[8, 11]
[2, 9, 10]
>>> print '\\n'.join(repr(sorted(x)) for x in toposort2({
... 2: set([11]),
... 9: set([11,8]),
... 10: set([11,3]),
... 11: set([7,5]),
... 8: set([7,3]),
... }) )
[3, 5, 7]
[8, 11]
[2, 9, 10]
"""
"""
from functools import reduce
@@ -39,4 +39,4 @@ items in the preceeding sets.
if item not in ordered:
data[item] = dep - ordered
assert not data, "Cyclic dependencies exist among these items:\n%s" % '\n'.join(repr(x) for x in data.iteritems())
## end of http://code.activestate.com/recipes/578272/ }}}
# end of http://code.activestate.com/recipes/578272/ }}}

View File

@@ -1,26 +1,27 @@
from __future__ import absolute_import
from django.utils.translation import ugettext_lazy as _
from django.contrib import messages
from django.core.exceptions import PermissionDenied
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django.contrib import messages
from django.core.urlresolvers import reverse
from django.core.files import File
from django.utils.translation import ugettext_lazy as _
from filetransfers.api import serve_file
from acls.models import AccessEntry
from permissions.models import Permission
from .classes import Cleanup
from .exceptions import ExistingData, NotABootstrapSetup
from .forms import (BootstrapSetupForm, BootstrapSetupForm_view, BootstrapSetupForm_dump,
BootstrapSetupForm_edit, BootstrapFileImportForm, BootstrapURLImportForm)
from .models import BootstrapSetup
from .classes import Cleanup, BootstrapModel
from .permissions import (PERMISSION_BOOTSTRAP_VIEW, PERMISSION_BOOTSTRAP_CREATE,
PERMISSION_BOOTSTRAP_EDIT, PERMISSION_BOOTSTRAP_DELETE,
PERMISSION_BOOTSTRAP_EXECUTE, PERMISSION_NUKE_DATABASE, PERMISSION_BOOTSTRAP_DUMP,
PERMISSION_BOOTSTRAP_EXPORT, PERMISSION_BOOTSTRAP_IMPORT, PERMISSION_BOOTSTRAP_REPOSITORY_SYNC)
from .forms import (BootstrapSetupForm, BootstrapSetupForm_view, BootstrapSetupForm_dump,
BootstrapSetupForm_edit, BootstrapFileImportForm, BootstrapURLImportForm)
from .exceptions import ExistingData, NotABootstrapSetup
def bootstrap_setup_list(request):
@@ -218,7 +219,7 @@ def bootstrap_setup_export(request, bootstrap_setup_pk):
Permission.objects.check_permissions(request.user, [PERMISSION_BOOTSTRAP_EXPORT])
except PermissionDenied:
AccessEntry.objects.check_access(PERMISSION_BOOTSTRAP_EXPORT, request.user, bootstrap)
return serve_file(
request,
bootstrap.as_file(),
@@ -316,7 +317,7 @@ def erase_database_view(request):
def bootstrap_setup_repository_sync(request):
Permission.objects.check_permissions(request.user, [PERMISSION_BOOTSTRAP_REPOSITORY_SYNC])
post_action_redirect = reverse('bootstrap_setup_list')
previous = request.POST.get('previous', request.GET.get('previous', request.META.get('HTTP_REFERER', '/')))