Enable hacking H233 rule

H233: Python 3.x incompatible use of print operator

Change-Id: I7acd664b888c0ba049524e5f519c72038d79495b
This commit is contained in:
ZhiQiang Fan
2014-01-23 10:12:19 +08:00
parent d5558265cc
commit bbcbc5a69c
12 changed files with 79 additions and 52 deletions

View File

@@ -14,6 +14,8 @@
# under the License. # under the License.
# #
from __future__ import print_function
import argparse import argparse
import logging import logging
import re import re
@@ -421,7 +423,8 @@ class CreateCommand(NeutronCommand, show.ShowOne):
# {u'network': {u'id': u'e9424a76-6db4-4c93-97b6-ec311cd51f19'}} # {u'network': {u'id': u'e9424a76-6db4-4c93-97b6-ec311cd51f19'}}
info = self.resource in data and data[self.resource] or None info = self.resource in data and data[self.resource] or None
if info: if info:
print >>self.app.stdout, _('Created a new %s:') % self.resource print(_('Created a new %s:') % self.resource,
file=self.app.stdout)
else: else:
info = {'': ''} info = {'': ''}
return zip(*sorted(info.iteritems())) return zip(*sorted(info.iteritems()))
@@ -468,9 +471,9 @@ class UpdateCommand(NeutronCommand):
obj_updator = getattr(neutron_client, obj_updator = getattr(neutron_client,
"update_%s" % self.resource) "update_%s" % self.resource)
obj_updator(_id, body) obj_updator(_id, body)
print >>self.app.stdout, ( print((_('Updated %(resource)s: %(id)s') %
_('Updated %(resource)s: %(id)s') % {'id': parsed_args.id, 'resource': self.resource}),
{'id': parsed_args.id, 'resource': self.resource}) file=self.app.stdout)
return return
@@ -507,9 +510,10 @@ class DeleteCommand(NeutronCommand):
else: else:
_id = parsed_args.id _id = parsed_args.id
obj_deleter(_id) obj_deleter(_id)
print >>self.app.stdout, (_('Deleted %(resource)s: %(id)s') print((_('Deleted %(resource)s: %(id)s')
% {'id': parsed_args.id, % {'id': parsed_args.id,
'resource': self.resource}) 'resource': self.resource}),
file=self.app.stdout)
return return

View File

@@ -14,12 +14,16 @@
# under the License. # under the License.
# #
from __future__ import print_function
import logging import logging
from neutronclient.neutron import v2_0 as neutronV20 from neutronclient.neutron import v2_0 as neutronV20
from neutronclient.neutron.v2_0 import network from neutronclient.neutron.v2_0 import network
from neutronclient.neutron.v2_0 import router from neutronclient.neutron.v2_0 import router
from neutronclient.openstack.common.gettextutils import _ from neutronclient.openstack.common.gettextutils import _
PERFECT_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%f" PERFECT_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%f"
@@ -46,8 +50,8 @@ class AddNetworkToDhcpAgent(neutronV20.NeutronCommand):
neutron_client, 'network', parsed_args.network) neutron_client, 'network', parsed_args.network)
neutron_client.add_network_to_dhcp_agent(parsed_args.dhcp_agent, neutron_client.add_network_to_dhcp_agent(parsed_args.dhcp_agent,
{'network_id': _net_id}) {'network_id': _net_id})
print >>self.app.stdout, ( print(_('Added network %s to DHCP agent') % parsed_args.network,
_('Added network %s to DHCP agent') % parsed_args.network) file=self.app.stdout)
class RemoveNetworkFromDhcpAgent(neutronV20.NeutronCommand): class RemoveNetworkFromDhcpAgent(neutronV20.NeutronCommand):
@@ -72,8 +76,8 @@ class RemoveNetworkFromDhcpAgent(neutronV20.NeutronCommand):
neutron_client, 'network', parsed_args.network) neutron_client, 'network', parsed_args.network)
neutron_client.remove_network_from_dhcp_agent( neutron_client.remove_network_from_dhcp_agent(
parsed_args.dhcp_agent, _net_id) parsed_args.dhcp_agent, _net_id)
print >>self.app.stdout, ( print(_('Removed network %s to DHCP agent') % parsed_args.network,
_('Removed network %s to DHCP agent') % parsed_args.network) file=self.app.stdout)
class ListNetworksOnDhcpAgent(network.ListNetwork): class ListNetworksOnDhcpAgent(network.ListNetwork):
@@ -149,8 +153,8 @@ class AddRouterToL3Agent(neutronV20.NeutronCommand):
neutron_client, 'router', parsed_args.router) neutron_client, 'router', parsed_args.router)
neutron_client.add_router_to_l3_agent(parsed_args.l3_agent, neutron_client.add_router_to_l3_agent(parsed_args.l3_agent,
{'router_id': _id}) {'router_id': _id})
print >>self.app.stdout, ( print(_('Added router %s to L3 agent') % parsed_args.router,
_('Added router %s to L3 agent') % parsed_args.router) file=self.app.stdout)
class RemoveRouterFromL3Agent(neutronV20.NeutronCommand): class RemoveRouterFromL3Agent(neutronV20.NeutronCommand):
@@ -176,8 +180,8 @@ class RemoveRouterFromL3Agent(neutronV20.NeutronCommand):
neutron_client, 'router', parsed_args.router) neutron_client, 'router', parsed_args.router)
neutron_client.remove_router_from_l3_agent( neutron_client.remove_router_from_l3_agent(
parsed_args.l3_agent, _id) parsed_args.l3_agent, _id)
print >>self.app.stdout, ( print(_('Removed Router %s to L3 agent') % parsed_args.router,
_('Removed Router %s to L3 agent') % parsed_args.router) file=self.app.stdout)
class ListRoutersOnL3Agent(neutronV20.ListCommand): class ListRoutersOnL3Agent(neutronV20.ListCommand):

View File

@@ -14,6 +14,8 @@
# under the License. # under the License.
# #
from __future__ import print_function
import argparse import argparse
import logging import logging
@@ -122,8 +124,8 @@ class AssociateFloatingIP(neutronV20.NeutronCommand):
update_dict['fixed_ip_address'] = parsed_args.fixed_ip_address update_dict['fixed_ip_address'] = parsed_args.fixed_ip_address
neutron_client.update_floatingip(parsed_args.floatingip_id, neutron_client.update_floatingip(parsed_args.floatingip_id,
{'floatingip': update_dict}) {'floatingip': update_dict})
print >>self.app.stdout, ( print(_('Associated floatingip %s') % parsed_args.floatingip_id,
_('Associated floatingip %s') % parsed_args.floatingip_id) file=self.app.stdout)
class DisassociateFloatingIP(neutronV20.NeutronCommand): class DisassociateFloatingIP(neutronV20.NeutronCommand):
@@ -147,5 +149,5 @@ class DisassociateFloatingIP(neutronV20.NeutronCommand):
neutron_client.format = parsed_args.request_format neutron_client.format = parsed_args.request_format
neutron_client.update_floatingip(parsed_args.floatingip_id, neutron_client.update_floatingip(parsed_args.floatingip_id,
{'floatingip': {'port_id': None}}) {'floatingip': {'port_id': None}})
print >>self.app.stdout, ( print(_('Disassociated floatingip %s') % parsed_args.floatingip_id,
_('Disassociated floatingip %s') % parsed_args.floatingip_id) file=self.app.stdout)

View File

@@ -16,6 +16,8 @@
# @author: KC Wang, Big Switch Networks # @author: KC Wang, Big Switch Networks
# #
from __future__ import print_function
import argparse import argparse
import logging import logging
import string import string
@@ -174,9 +176,8 @@ class FirewallPolicyInsertRule(neutronv20.UpdateCommand):
self.resource, self.resource,
parsed_args.id) parsed_args.id)
self.call_api(neutron_client, _id, body) self.call_api(neutron_client, _id, body)
print >>self.app.stdout, ( print((_('Inserted firewall rule in firewall policy %(id)s') %
_('Inserted firewall rule in firewall policy %(id)s') % {'id': parsed_args.id}), file=self.app.stdout)
{'id': parsed_args.id})
class FirewallPolicyRemoveRule(neutronv20.UpdateCommand): class FirewallPolicyRemoveRule(neutronv20.UpdateCommand):
@@ -216,6 +217,5 @@ class FirewallPolicyRemoveRule(neutronv20.UpdateCommand):
self.resource, self.resource,
parsed_args.id) parsed_args.id)
self.call_api(neutron_client, _id, body) self.call_api(neutron_client, _id, body)
print >>self.app.stdout, ( print((_('Removed firewall rule from firewall policy %(id)s') %
_('Removed firewall rule from firewall policy %(id)s') % {'id': parsed_args.id}), file=self.app.stdout)
{'id': parsed_args.id})

View File

@@ -16,6 +16,8 @@
# @author: Ilya Shakhat, Mirantis Inc. # @author: Ilya Shakhat, Mirantis Inc.
# #
from __future__ import print_function
import logging import logging
from neutronclient.neutron import v2_0 as neutronV20 from neutronclient.neutron import v2_0 as neutronV20
@@ -141,8 +143,9 @@ class AssociateHealthMonitor(neutronV20.NeutronCommand):
pool_id = neutronV20.find_resourceid_by_name_or_id( pool_id = neutronV20.find_resourceid_by_name_or_id(
neutron_client, 'pool', parsed_args.pool_id) neutron_client, 'pool', parsed_args.pool_id)
neutron_client.associate_health_monitor(pool_id, body) neutron_client.associate_health_monitor(pool_id, body)
print >>self.app.stdout, (_('Associated health monitor ' print((_('Associated health monitor '
'%s') % parsed_args.health_monitor_id) '%s') % parsed_args.health_monitor_id),
file=self.app.stdout)
class DisassociateHealthMonitor(neutronV20.NeutronCommand): class DisassociateHealthMonitor(neutronV20.NeutronCommand):
@@ -169,5 +172,6 @@ class DisassociateHealthMonitor(neutronV20.NeutronCommand):
neutron_client.disassociate_health_monitor(pool_id, neutron_client.disassociate_health_monitor(pool_id,
parsed_args parsed_args
.health_monitor_id) .health_monitor_id)
print >>self.app.stdout, (_('Disassociated health monitor ' print((_('Disassociated health monitor '
'%s') % parsed_args.health_monitor_id) '%s') % parsed_args.health_monitor_id),
file=self.app.stdout)

View File

@@ -14,6 +14,8 @@
#@author Sergey Sudakovich, Cisco Systems #@author Sergey Sudakovich, Cisco Systems
#@author Rudrajit Tapadar, Cisco Systems #@author Rudrajit Tapadar, Cisco Systems
from __future__ import print_function
import logging import logging
from neutronclient.neutron import v2_0 as neutronV20 from neutronclient.neutron import v2_0 as neutronV20
@@ -128,7 +130,7 @@ class UpdateNetworkProfileV2(neutronV20.NeutronCommand):
data[self.resource]['remove_tenant'] = parsed_args.remove_tenant data[self.resource]['remove_tenant'] = parsed_args.remove_tenant
neutron_client.update_network_profile(parsed_args.id, neutron_client.update_network_profile(parsed_args.id,
{self.resource: data}) {self.resource: data})
print >>self.app.stdout, ( print((_('Updated %(resource)s: %(id)s') %
_('Updated %(resource)s: %(id)s') % {'id': parsed_args.id, 'resource': self.resource}),
{'id': parsed_args.id, 'resource': self.resource}) file=self.app.stdout)
return return

View File

@@ -14,6 +14,8 @@
# under the License. # under the License.
# #
from __future__ import print_function
import logging import logging
from neutronclient.common import utils from neutronclient.common import utils
@@ -133,8 +135,8 @@ class ConnectNetworkGateway(NetworkGatewayInterfaceCommand):
'segmentation_id': parsed_args.segmentation_id}) 'segmentation_id': parsed_args.segmentation_id})
# TODO(Salvatore-Orlando): Do output formatting as # TODO(Salvatore-Orlando): Do output formatting as
# any other command # any other command
print >>self.app.stdout, ( print(_('Connected network to gateway %s') % gateway_id,
_('Connected network to gateway %s') % gateway_id) file=self.app.stdout)
class DisconnectNetworkGateway(NetworkGatewayInterfaceCommand): class DisconnectNetworkGateway(NetworkGatewayInterfaceCommand):
@@ -154,5 +156,5 @@ class DisconnectNetworkGateway(NetworkGatewayInterfaceCommand):
'segmentation_id': parsed_args.segmentation_id}) 'segmentation_id': parsed_args.segmentation_id})
# TODO(Salvatore-Orlando): Do output formatting as # TODO(Salvatore-Orlando): Do output formatting as
# any other command # any other command
print >>self.app.stdout, ( print(_('Disconnected network from gateway %s') % gateway_id,
_('Disconnected network from gateway %s') % gateway_id) file=self.app.stdout)

View File

@@ -13,7 +13,10 @@
#@author Abhishek Raut, Cisco Systems #@author Abhishek Raut, Cisco Systems
#@author Sergey Sudakovich, Cisco Systems #@author Sergey Sudakovich, Cisco Systems
from __future__ import print_function
import logging import logging
from neutronclient.neutron import v2_0 as neutronV20 from neutronclient.neutron import v2_0 as neutronV20
from neutronclient.neutron.v2_0 import parse_args_to_dict from neutronclient.neutron.v2_0 import parse_args_to_dict
from neutronclient.openstack.common.gettextutils import _ from neutronclient.openstack.common.gettextutils import _
@@ -71,7 +74,7 @@ class UpdatePolicyProfileV2(neutronV20.UpdateCommand):
data[self.resource]['remove_tenant'] = parsed_args.remove_tenant data[self.resource]['remove_tenant'] = parsed_args.remove_tenant
neutron_client.update_policy_profile(parsed_args.id, neutron_client.update_policy_profile(parsed_args.id,
{self.resource: data}) {self.resource: data})
print >>self.app.stdout, ( print((_('Updated %(resource)s: %(id)s') %
_('Updated %(resource)s: %(id)s') % {'id': parsed_args.id, 'resource': self.resource}),
{'id': parsed_args.id, 'resource': self.resource}) file=self.app.stdout)
return return

View File

@@ -14,6 +14,8 @@
# under the License. # under the License.
# #
from __future__ import print_function
import argparse import argparse
import logging import logging
@@ -57,9 +59,10 @@ class DeleteQuota(neutronV20.NeutronCommand):
obj_deleter = getattr(neutron_client, obj_deleter = getattr(neutron_client,
"delete_%s" % self.resource) "delete_%s" % self.resource)
obj_deleter(tenant_id) obj_deleter(tenant_id)
print >>self.app.stdout, (_('Deleted %(resource)s: %(tenant_id)s') print((_('Deleted %(resource)s: %(tenant_id)s')
% {'tenant_id': tenant_id, % {'tenant_id': tenant_id,
'resource': self.resource}) 'resource': self.resource}),
file=self.app.stdout)
return return

View File

@@ -14,6 +14,8 @@
# under the License. # under the License.
# #
from __future__ import print_function
import argparse import argparse
import logging import logging
@@ -141,8 +143,8 @@ class RouterInterfaceCommand(neutronV20.NeutronCommand):
body = {'%s_id' % resource: _interface_id} body = {'%s_id' % resource: _interface_id}
portinfo = self.call_api(neutron_client, _router_id, body) portinfo = self.call_api(neutron_client, _router_id, body)
print >>self.app.stdout, self.success_message(parsed_args.router_id, print(self.success_message(parsed_args.router_id, portinfo),
portinfo) file=self.app.stdout)
class AddInterfaceRouter(RouterInterfaceCommand): class AddInterfaceRouter(RouterInterfaceCommand):
@@ -203,8 +205,8 @@ class SetGatewayRouter(neutronV20.NeutronCommand):
if parsed_args.disable_snat: if parsed_args.disable_snat:
router_dict['enable_snat'] = False router_dict['enable_snat'] = False
neutron_client.add_gateway_router(_router_id, router_dict) neutron_client.add_gateway_router(_router_id, router_dict)
print >>self.app.stdout, ( print(_('Set gateway for router %s') % parsed_args.router_id,
_('Set gateway for router %s') % parsed_args.router_id) file=self.app.stdout)
class RemoveGatewayRouter(neutronV20.NeutronCommand): class RemoveGatewayRouter(neutronV20.NeutronCommand):
@@ -228,5 +230,5 @@ class RemoveGatewayRouter(neutronV20.NeutronCommand):
_router_id = neutronV20.find_resourceid_by_name_or_id( _router_id = neutronV20.find_resourceid_by_name_or_id(
neutron_client, self.resource, parsed_args.router_id) neutron_client, self.resource, parsed_args.router_id)
neutron_client.remove_gateway_router(_router_id) neutron_client.remove_gateway_router(_router_id)
print >>self.app.stdout, ( print(_('Removed gateway from router %s') % parsed_args.router_id,
_('Removed gateway from router %s') % parsed_args.router_id) file=self.app.stdout)

View File

@@ -18,6 +18,8 @@
Command-line interface to the Neutron APIs Command-line interface to the Neutron APIs
""" """
from __future__ import print_function
import argparse import argparse
import logging import logging
import os import os
@@ -459,7 +461,7 @@ class NeutronShell(app.App):
cmd_parser = cmd.get_parser('') cmd_parser = cmd.get_parser('')
for option, _action in cmd_parser._option_string_actions.items(): for option, _action in cmd_parser._option_string_actions.items():
options.add(option) options.add(option)
print ' '.join(commands | options) print(' '.join(commands | options))
def run(self, argv): def run(self, argv):
"""Equivalent to the main program for the application. """Equivalent to the main program for the application.
@@ -666,7 +668,7 @@ def main(argv=sys.argv[1:]):
except exc.NeutronClientException: except exc.NeutronClientException:
return 1 return 1
except Exception as e: except Exception as e:
print unicode(e) print(unicode(e))
return 1 return 1

View File

@@ -29,8 +29,7 @@ downloadcache = ~/cache/pip
[flake8] [flake8]
# E125 continuation line does not distinguish itself from next logical line # E125 continuation line does not distinguish itself from next logical line
# H233 Python 3.x incompatible use of print operator
# H302 import only modules # H302 import only modules
ignore = E125,H233,H302 ignore = E125,H302
show-source = true show-source = true
exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,tools exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,tools