diff --git a/.pep8 b/.pep8 new file mode 100644 index 0000000000..9e4ea37416 --- /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 71479fb965..7466d921ef 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 440923f6e7..de30ed3d72 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 2e09065a50..6e9996fcd3 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 60d69fdff2..c8c9534c34 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 cfed69d012..c6caea99f6 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 b93a7da122..da342b6686 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 d4822da753..320d154d8e 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 ea4654b651..585518394a 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 5c79d43f87..ad41af1b9e 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 9fbb4a7d5b..88f59431b8 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 5e279e809d..db1a18d69e 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