From 820fdfe86804effd1e6578167716a3f4ec4d6842 Mon Sep 17 00:00:00 2001 From: Gabriel Hurley Date: Sat, 23 Jun 2012 13:06:11 -0700 Subject: [PATCH] Corrections for stricter pep8 checking. Updates the code to reflect stricter pep8 checking standards for pep8 1.3+. Also adds a pep8 config file to silence unnecessary indentation errors. Removes the "reverse bugfix" monkeypatch since Django 1.4 is now required. Implements blueprint upgrade-pep8. Change-Id: I7343321627d8ccd1598f39323821133168a645cc --- .pep8 | 4 + horizon/__init__.py | 5 - horizon/api/nova.py | 37 ++-- horizon/api/swift.py | 12 +- .../security_groups/forms.py | 12 +- .../images_and_snapshots/images/tables.py | 5 +- .../nova/images_and_snapshots/images/tests.py | 3 +- .../instances_and_volumes/instances/tables.py | 5 +- .../instances/workflows.py | 4 +- .../nova/instances_and_volumes/views.py | 4 +- .../instances_and_volumes/volumes/tests.py | 11 +- .../dashboards/syspanel/instances/tables.py | 5 +- horizon/dashboards/syspanel/projects/forms.py | 22 +-- horizon/dashboards/syspanel/users/forms.py | 2 +- horizon/tables/base.py | 2 +- horizon/tests/api_tests/nova_tests.py | 3 +- horizon/tests/testsettings.py | 8 +- horizon/utils/reverse_bugfix.py | 183 ------------------ run_tests.sh | 7 +- tools/test-requires | 2 +- 20 files changed, 76 insertions(+), 260 deletions(-) create mode 100644 .pep8 delete mode 100644 horizon/utils/reverse_bugfix.py diff --git a/.pep8 b/.pep8 new file mode 100644 index 000000000..9e4ea3741 --- /dev/null +++ b/.pep8 @@ -0,0 +1,4 @@ + +[pep8] +ignore = E121,E126,E127,E128,W602 +exclude = vcsversion.py,panel_template,dash_template,local_settings.py diff --git a/horizon/__init__.py b/horizon/__init__.py index 71479fb96..7466d921e 100644 --- a/horizon/__init__.py +++ b/horizon/__init__.py @@ -39,11 +39,6 @@ except ImportError: warnings.warn(msg, Warning) if Horizon: - # This can be removed once the upstream bug is fixed. - import django - if django.VERSION < (1, 4): - from horizon.utils import reverse_bugfix - register = Horizon.register unregister = Horizon.unregister get_absolute_url = Horizon.get_absolute_url diff --git a/horizon/api/nova.py b/horizon/api/nova.py index 440923f6e..de30ed3d7 100644 --- a/horizon/api/nova.py +++ b/horizon/api/nova.py @@ -127,12 +127,12 @@ class Usage(APIResourceWrapper): @property def total_active_instances(self): - return sum(1 for s in self.server_usages if s['ended_at'] == None) + return sum(1 for s in self.server_usages if s['ended_at'] is None) @property def vcpus(self): return sum(s['vcpus'] for s in self.server_usages - if s['ended_at'] == None) + if s['ended_at'] is None) @property def vcpu_hours(self): @@ -141,12 +141,12 @@ class Usage(APIResourceWrapper): @property def local_gb(self): return sum(s['local_gb'] for s in self.server_usages - if s['ended_at'] == None) + if s['ended_at'] is None) @property def memory_mb(self): return sum(s['memory_mb'] for s in self.server_usages - if s['ended_at'] == None) + if s['ended_at'] is None) @property def disk_gb_hours(self): @@ -164,8 +164,8 @@ class SecurityGroup(APIResourceWrapper): """Wraps transmitted rule info in the novaclient rule class.""" if "_rules" not in self.__dict__: manager = nova_rules.SecurityGroupRuleManager - self._rules = [nova_rules.SecurityGroupRule(manager, rule) for \ - rule in self._apiresource.rules] + self._rules = [nova_rules.SecurityGroupRule(manager, rule) + for rule in self._apiresource.rules] return self.__dict__['_rules'] @rules.setter @@ -310,8 +310,8 @@ def server_list(request, search_opts=None, all_tenants=False): search_opts['all_tenants'] = True else: search_opts['project_id'] = request.user.tenant_id - return [Server(s, request) for s in novaclient(request).\ - servers.list(True, search_opts)] + return [Server(s, request) + for s in novaclient(request).servers.list(True, search_opts)] def server_console_output(request, instance_id, tail_length=None): @@ -439,18 +439,17 @@ def tenant_quota_usages(request): def security_group_list(request): - return [SecurityGroup(g) for g in novaclient(request).\ - security_groups.list()] + return [SecurityGroup(g) for g + in novaclient(request).security_groups.list()] -def security_group_get(request, security_group_id): - return SecurityGroup(novaclient(request).\ - security_groups.get(security_group_id)) +def security_group_get(request, sg_id): + return SecurityGroup(novaclient(request).security_groups.get(sg_id)) -def security_group_create(request, name, description): - return SecurityGroup(novaclient(request).\ - security_groups.create(name, description)) +def security_group_create(request, name, desc): + return SecurityGroup(novaclient(request).security_groups.create(name, + desc)) def security_group_delete(request, security_group_id): @@ -460,13 +459,13 @@ def security_group_delete(request, security_group_id): def security_group_rule_create(request, parent_group_id, ip_protocol=None, from_port=None, to_port=None, cidr=None, group_id=None): - return SecurityGroupRule(novaclient(request).\ - security_group_rules.create(parent_group_id, + sg = novaclient(request).security_group_rules.create(parent_group_id, ip_protocol, from_port, to_port, cidr, - group_id)) + group_id) + return SecurityGroupRule(sg) def security_group_rule_delete(request, security_group_rule_id): diff --git a/horizon/api/swift.py b/horizon/api/swift.py index 2e09065a5..6e9996fcd 100644 --- a/horizon/api/swift.py +++ b/horizon/api/swift.py @@ -117,11 +117,13 @@ def swift_filter_objects(request, filter_string, container_name, prefix=None, path=path) filter_string_list = filter_string.lower().strip().split(' ') - return filter(lambda obj: any([ - obj.content_type != "application/directory" - and wildcard_search(obj.name.lower(), q) - for q in filter_string_list if q != '' - ]), objects) + def matches_filter(obj): + if obj.content_type == "application/directory": + return False + for q in filter_string_list: + return wildcard_search(obj.name.lower(), q) + + return filter(matches_filter, objects) def wildcard_search(string, q): diff --git a/horizon/dashboards/nova/access_and_security/security_groups/forms.py b/horizon/dashboards/nova/access_and_security/security_groups/forms.py index 60d69fdff..c8c9534c3 100644 --- a/horizon/dashboards/nova/access_and_security/security_groups/forms.py +++ b/horizon/dashboards/nova/access_and_security/security_groups/forms.py @@ -112,10 +112,10 @@ class AddRule(forms.SelfHandlingForm): source_group = cleaned_data.get("source_group", None) if ip_proto == 'icmp': - if from_port == None: + if from_port is None: msg = _('The ICMP type is invalid.') raise ValidationError(msg) - if to_port == None: + if to_port is None: msg = _('The ICMP code is invalid.') raise ValidationError(msg) if from_port not in xrange(-1, 256): @@ -125,10 +125,10 @@ class AddRule(forms.SelfHandlingForm): msg = _('The ICMP code not in range (-1, 255)') raise ValidationError(msg) else: - if from_port == None: + if from_port is None: msg = _('The "from" port number is invalid.') raise ValidationError(msg) - if to_port == None: + if to_port is None: msg = _('The "to" port number is invalid.') raise ValidationError(msg) if to_port < from_port: @@ -159,8 +159,8 @@ class AddRule(forms.SelfHandlingForm): data['to_port'], data['cidr'], data['source_group']) - messages.success(request, _('Successfully added rule: %s') \ - % unicode(rule)) + messages.success(request, + _('Successfully added rule: %s') % unicode(rule)) except: exceptions.handle(request, _('Unable to add rule to security group.')) diff --git a/horizon/dashboards/nova/images_and_snapshots/images/tables.py b/horizon/dashboards/nova/images_and_snapshots/images/tables.py index cfed69d01..c6caea99f 100644 --- a/horizon/dashboards/nova/images_and_snapshots/images/tables.py +++ b/horizon/dashboards/nova/images_and_snapshots/images/tables.py @@ -105,8 +105,9 @@ class ImagesTable(tables.DataTable): ("killed", False), ("deleted", False), ) - name = tables.Column("name", link="horizon:nova:images_and_snapshots:" \ - "images:detail", + name = tables.Column("name", + link=("horizon:nova:images_and_snapshots:" + "images:detail"), verbose_name=_("Image Name")) image_type = tables.Column(get_image_type, verbose_name=_("Type"), diff --git a/horizon/dashboards/nova/images_and_snapshots/images/tests.py b/horizon/dashboards/nova/images_and_snapshots/images/tests.py index b93a7da12..da342b668 100644 --- a/horizon/dashboards/nova/images_and_snapshots/images/tests.py +++ b/horizon/dashboards/nova/images_and_snapshots/images/tests.py @@ -48,8 +48,7 @@ class ImageViewTests(test.TestCase): 'minimum_disk': 15, 'minimum_ram': 512, 'is_public': 1, - 'method': 'CreateImageForm' - } + 'method': 'CreateImageForm'} api.glance.image_create(IsA(http.HttpRequest), container_format="bare", diff --git a/horizon/dashboards/nova/instances_and_volumes/instances/tables.py b/horizon/dashboards/nova/instances_and_volumes/instances/tables.py index d4822da75..320d154d8 100644 --- a/horizon/dashboards/nova/instances_and_volumes/instances/tables.py +++ b/horizon/dashboards/nova/instances_and_volumes/instances/tables.py @@ -255,8 +255,9 @@ class InstancesTable(tables.DataTable): TASK_DISPLAY_CHOICES = ( ("image_snapshot", "Snapshotting"), ) - name = tables.Column("name", link="horizon:nova:instances_and_volumes:" \ - "instances:detail", + name = tables.Column("name", + link=("horizon:nova:instances_and_volumes:" + "instances:detail"), verbose_name=_("Instance Name")) ip = tables.Column(get_ips, verbose_name=_("IP Address")) size = tables.Column(get_size, verbose_name=_("Size")) diff --git a/horizon/dashboards/nova/instances_and_volumes/instances/workflows.py b/horizon/dashboards/nova/instances_and_volumes/instances/workflows.py index ea4654b65..585518394 100644 --- a/horizon/dashboards/nova/instances_and_volumes/instances/workflows.py +++ b/horizon/dashboards/nova/instances_and_volumes/instances/workflows.py @@ -109,7 +109,7 @@ class VolumeOptionsAction(workflows.Action): def populate_volume_id_choices(self, request, context): volume_options = [("", _("Select Volume"))] try: - volumes = [v for v in api.nova.volume_list(self.request) \ + volumes = [v for v in api.nova.volume_list(self.request) if v.status == api.VOLUME_STATE_AVAILABLE] volume_options.extend([self._get_volume_display_name(vol) for vol in volumes]) @@ -122,7 +122,7 @@ class VolumeOptionsAction(workflows.Action): volume_options = [("", _("Select Volume Snapshot"))] try: snapshots = api.nova.volume_snapshot_list(self.request) - snapshots = [s for s in snapshots \ + snapshots = [s for s in snapshots if s.status == api.VOLUME_STATE_AVAILABLE] volume_options.extend([self._get_volume_display_name(snap) for snap in snapshots]) diff --git a/horizon/dashboards/nova/instances_and_volumes/views.py b/horizon/dashboards/nova/instances_and_volumes/views.py index 5c79d43f8..ad41af1b9 100644 --- a/horizon/dashboards/nova/instances_and_volumes/views.py +++ b/horizon/dashboards/nova/instances_and_volumes/views.py @@ -54,8 +54,8 @@ class IndexView(tables.MultiTableView): if instances: try: flavors = api.flavor_list(self.request) - full_flavors = SortedDict([(str(flavor.id), flavor) for \ - flavor in flavors]) + full_flavors = SortedDict([(str(flavor.id), flavor) + for flavor in flavors]) for instance in instances: flavor_id = instance.flavor["id"] instance.full_flavor = full_flavors[flavor_id] diff --git a/horizon/dashboards/nova/instances_and_volumes/volumes/tests.py b/horizon/dashboards/nova/instances_and_volumes/volumes/tests.py index 9fbb4a7d5..88f59431b 100644 --- a/horizon/dashboards/nova/instances_and_volumes/volumes/tests.py +++ b/horizon/dashboards/nova/instances_and_volumes/volumes/tests.py @@ -64,9 +64,8 @@ class VolumeViewTests(test.TestCase): args=[volume.id]) res = self.client.get(url) - self.assertEqual(res.context['form'].\ - fields['instance']._choices[0][1], - "Select an instance") + self.assertEqual(res.context['form'].fields['instance']._choices[0][1], + "Select an instance") self.assertEqual(len(res.context['form'].fields['instance'].choices), 2) self.assertEqual(res.context['form'].fields['instance']._choices[1][0], @@ -90,8 +89,10 @@ class VolumeViewTests(test.TestCase): res = self.client.get(url) self.assertContains(res, "
Volume name
", 1, 200) - self.assertContains(res, "
41023e92-8008-4c8b-8059-" \ - "7f2293ff3775
", 1, 200) + self.assertContains(res, + "
41023e92-8008-4c8b-8059-7f2293ff3775
", + 1, + 200) self.assertContains(res, "
Available
", 1, 200) self.assertContains(res, "
40 GB
", 1, 200) self.assertContains(res, " pep8.txt || true + ${command_wrapper} pep8 $included_dirs | perl -ple 's/: ([WE]\d+)/: [$1]/' > pep8.txt || true PEP8_COUNT=`wc -l pep8.txt | awk '{ print $1 }'` if [ $PEP8_COUNT -ge 1 ]; then echo "PEP8 violations found ($PEP8_COUNT):" diff --git a/tools/test-requires b/tools/test-requires index 5e279e809..db1a18d69 100644 --- a/tools/test-requires +++ b/tools/test-requires @@ -9,7 +9,7 @@ nose nose-exclude nosexcover openstack.nose_plugin -pep8==1.1 +pep8>=1.3 pylint selenium