Skip to content

Commit

Permalink
Use print() as function under contrib/
Browse files Browse the repository at this point in the history
This fixes the remaining Python 3 syntax errors, so re-enable compileall
for contrib/ again.
  • Loading branch information
mgedmin committed Aug 28, 2015
1 parent aa5f96d commit 3f9879a
Show file tree
Hide file tree
Showing 28 changed files with 105 additions and 96 deletions.
8 changes: 4 additions & 4 deletions contrib/inventory/apache-libcloud.py
Expand Up @@ -79,7 +79,7 @@ def __init__(self):
else:
data_to_print = self.json_format_dict(self.inventory, True)

print data_to_print
print(data_to_print)


def is_cache_valid(self):
Expand Down Expand Up @@ -282,9 +282,9 @@ def get_host_info(self):
else:
pass
# TODO Product codes if someone finds them useful
#print key
#print type(value)
#print value
#print(key)
#print(type(value))
#print(value)

return self.json_format_dict(instance_vars, True)

Expand Down
16 changes: 10 additions & 6 deletions contrib/inventory/cloudstack.py
Expand Up @@ -70,6 +70,8 @@
usage: cloudstack.py [--list] [--host HOST] [--project PROJECT]
"""

from __future__ import print_function

import os
import sys
import argparse
Expand All @@ -83,7 +85,8 @@
try:
from cs import CloudStack, CloudStackException, read_config
except ImportError:
print >> sys.stderr, "Error: CloudStack library must be installed: pip install cs."
print("Error: CloudStack library must be installed: pip install cs.",
file=sys.stderr)
sys.exit(1)


Expand All @@ -99,21 +102,22 @@ def __init__(self):
try:
self.cs = CloudStack(**read_config())
except CloudStackException as e:
print >> sys.stderr, "Error: Could not connect to CloudStack API"
print("Error: Could not connect to CloudStack API", file=sys.stderr)

project_id = ''
if options.project:
project_id = self.get_project_id(options.project)

if options.host:
data = self.get_host(options.host)
print json.dumps(data, indent=2)
print(json.dumps(data, indent=2))

elif options.list:
data = self.get_list()
print json.dumps(data, indent=2)
print(json.dumps(data, indent=2))
else:
print >> sys.stderr, "usage: --list | --host <hostname> [--project <project>]"
print("usage: --list | --host <hostname> [--project <project>]",
file=sys.stderr)
sys.exit(1)


Expand All @@ -123,7 +127,7 @@ def get_project_id(self, project):
for p in projects['project']:
if p['name'] == project or p['id'] == project:
return p['id']
print >> sys.stderr, "Error: Project %s not found." % project
print("Error: Project %s not found." % project, file=sys.stderr)
sys.exit(1)


Expand Down
2 changes: 1 addition & 1 deletion contrib/inventory/cobbler.py
Expand Up @@ -113,7 +113,7 @@ def __init__(self):
self.inventory['_meta']['hostvars'][hostname] = {'cobbler': self.cache[hostname] }
data_to_print += self.json_format_dict(self.inventory, True)

print data_to_print
print(data_to_print)

def _connect(self):
if not self.conn:
Expand Down
2 changes: 1 addition & 1 deletion contrib/inventory/collins.py
Expand Up @@ -164,7 +164,7 @@ def run(self):
else: # default action with no options
data_to_print = self.json_format_dict(self.inventory, self.args.pretty)

print data_to_print
print(data_to_print)
return successful

def find_assets(self, attributes = {}, operation = 'AND'):
Expand Down
6 changes: 3 additions & 3 deletions contrib/inventory/consul_io.py
Expand Up @@ -137,8 +137,8 @@
try:
import consul
except ImportError as e:
print """failed=True msg='python-consul required for this module. see
http://python-consul.readthedocs.org/en/latest/#installation'"""
print("""failed=True msg='python-consul required for this module. see
http://python-consul.readthedocs.org/en/latest/#installation'""")
sys.exit(1)


Expand Down Expand Up @@ -171,7 +171,7 @@ def __init__(self):
self.load_all_data_consul()

self.combine_all_results()
print json.dumps(self.inventory, sort_keys=True, indent=2)
print(json.dumps(self.inventory, sort_keys=True, indent=2))

def load_all_data_consul(self):
''' cycle through each of the datacenters in the consul catalog and process
Expand Down
14 changes: 7 additions & 7 deletions contrib/inventory/digital_ocean.py
Expand Up @@ -146,7 +146,7 @@
try:
from dopy.manager import DoError, DoManager
except ImportError as e:
print "failed=True msg='`dopy` library required for this script'"
print("failed=True msg='`dopy` library required for this script'")
sys.exit(1)


Expand Down Expand Up @@ -175,14 +175,14 @@ def __init__(self):

# Verify credentials were set
if not hasattr(self, 'api_token'):
print '''Could not find values for DigitalOcean api_token.
print('''Could not find values for DigitalOcean api_token.
They must be specified via either ini file, command line argument (--api-token),
or environment variables (DO_API_TOKEN)'''
or environment variables (DO_API_TOKEN)''')
sys.exit(-1)

# env command, show DigitalOcean credentials
if self.args.env:
print "DO_API_TOKEN=%s" % self.api_token
print("DO_API_TOKEN=%s" % self.api_token)
sys.exit(0)

# Manage cache
Expand All @@ -193,7 +193,7 @@ def __init__(self):
self.load_from_cache()
if len(self.data) == 0:
if self.args.force_cache:
print '''Cache is empty and --force-cache was specified'''
print('''Cache is empty and --force-cache was specified''')
sys.exit(-1)

self.manager = DoManager(None, self.api_token, api_version=2)
Expand Down Expand Up @@ -231,9 +231,9 @@ def __init__(self):
self.write_to_cache()

if self.args.pretty:
print json.dumps(json_data, sort_keys=True, indent=2)
print(json.dumps(json_data, sort_keys=True, indent=2))
else:
print json.dumps(json_data)
print(json.dumps(json_data))
# That's all she wrote...


Expand Down
2 changes: 1 addition & 1 deletion contrib/inventory/docker.py
Expand Up @@ -334,7 +334,7 @@ def list_groups():
groups['docker_hosts'] = [host.get('base_url') for host in hosts]
groups['_meta'] = dict()
groups['_meta']['hostvars'] = hostvars
print json.dumps(groups, sort_keys=True, indent=4)
print(json.dumps(groups, sort_keys=True, indent=4))
sys.exit(0)


Expand Down
4 changes: 2 additions & 2 deletions contrib/inventory/fleet.py
Expand Up @@ -81,7 +81,7 @@ def get_a_ssh_config(box_name):
for data in ssh_config:
hosts['coreos'].append(data['Host'])

print json.dumps(hosts)
print(json.dumps(hosts))
sys.exit(1)

# Get out the host details
Expand All @@ -96,7 +96,7 @@ def get_a_ssh_config(box_name):
result = details[0]
result

print json.dumps(result)
print(json.dumps(result))
sys.exit(1)


Expand Down
4 changes: 2 additions & 2 deletions contrib/inventory/freeipa.py
Expand Up @@ -41,7 +41,7 @@ def list_groups(api):

inventory['_meta'] = {'hostvars': hostvars}
inv_string = json.dumps(inventory, indent=1, sort_keys=True)
print inv_string
print(inv_string)

return None

Expand Down Expand Up @@ -69,7 +69,7 @@ def print_host(host):
This function expects one string, this hostname to lookup variables for.
'''

print json.dumps({})
print(json.dumps({}))

return None

Expand Down
4 changes: 2 additions & 2 deletions contrib/inventory/gce.py
Expand Up @@ -112,9 +112,9 @@ def __init__(self):

# Just display data for specific host
if self.args.host:
print self.json_format_dict(self.node_to_dict(
print(self.json_format_dict(self.node_to_dict(
self.get_instance(self.args.host)),
pretty=self.args.pretty)
pretty=self.args.pretty))
sys.exit(0)

# Otherwise, assume user wants all instances grouped
Expand Down
6 changes: 3 additions & 3 deletions contrib/inventory/jail.py
Expand Up @@ -30,8 +30,8 @@
result['all']['vars']['ansible_connection'] = 'jail'

if len(sys.argv) == 2 and sys.argv[1] == '--list':
print json.dumps(result)
print(json.dumps(result))
elif len(sys.argv) == 3 and sys.argv[1] == '--host':
print json.dumps({'ansible_connection': 'jail'})
print(json.dumps({'ansible_connection': 'jail'}))
else:
print "Need an argument, either --list or --host <host>"
print("Need an argument, either --list or --host <host>")
6 changes: 3 additions & 3 deletions contrib/inventory/libvirt_lxc.py
Expand Up @@ -30,8 +30,8 @@
result['all']['vars']['ansible_connection'] = 'lxc'

if len(sys.argv) == 2 and sys.argv[1] == '--list':
print json.dumps(result)
print(json.dumps(result))
elif len(sys.argv) == 3 and sys.argv[1] == '--host':
print json.dumps({'ansible_connection': 'lxc'})
print(json.dumps({'ansible_connection': 'lxc'}))
else:
print "Need an argument, either --list or --host <host>"
print("Need an argument, either --list or --host <host>")
14 changes: 7 additions & 7 deletions contrib/inventory/linode.py
Expand Up @@ -139,7 +139,7 @@ def __init__(self):
else:
data_to_print = self.json_format_dict(self.inventory, True)

print data_to_print
print(data_to_print)

def is_cache_valid(self):
"""Determines if the cache file has expired, or if it is still valid."""
Expand Down Expand Up @@ -185,19 +185,19 @@ def get_nodes(self):
for node in Linode.search(status=Linode.STATUS_RUNNING):
self.add_node(node)
except chube_api.linode_api.ApiError as e:
print "Looks like Linode's API is down:"
print
print e
print("Looks like Linode's API is down:")
print("")
print(e)
sys.exit(1)

def get_node(self, linode_id):
"""Gets details about a specific node."""
try:
return Linode.find(api_id=linode_id)
except chube_api.linode_api.ApiError as e:
print "Looks like Linode's API is down:"
print
print e
print("Looks like Linode's API is down:")
print("")
print(e)
sys.exit(1)

def populate_datacenter_cache(self):
Expand Down
2 changes: 1 addition & 1 deletion contrib/inventory/nova.py
Expand Up @@ -225,5 +225,5 @@ def get_metadata(server):
sys.exit(0)

else:
print "usage: --list ..OR.. --host <hostname>"
print("usage: --list ..OR.. --host <hostname>")
sys.exit(1)
8 changes: 4 additions & 4 deletions contrib/inventory/openshift.py
Expand Up @@ -61,7 +61,7 @@ def get_config(env_var, config_var):
if not result:
result = get_from_rhc_config(config_var)
if not result:
print "failed=True msg='missing %s'" % env_var
print("failed=True msg='missing %s'" % env_var)
sys.exit(1)
return result

Expand Down Expand Up @@ -109,8 +109,8 @@ def passwd_setup(top_level_url, username, password):
result[app_name]['vars']['ansible_ssh_user'] = user

if len(sys.argv) == 2 and sys.argv[1] == '--list':
print json.dumps(result)
print(json.dumps(result))
elif len(sys.argv) == 3 and sys.argv[1] == '--host':
print json.dumps({})
print(json.dumps({}))
else:
print "Need an argument, either --list or --host <host>"
print("Need an argument, either --list or --host <host>")
6 changes: 3 additions & 3 deletions contrib/inventory/openvz.py
Expand Up @@ -70,8 +70,8 @@ def get_guests():

if len(sys.argv) == 2 and sys.argv[1] == '--list':
inv_json = get_guests()
print json.dumps(inv_json, sort_keys=True)
print(json.dumps(inv_json, sort_keys=True))
elif len(sys.argv) == 3 and sys.argv[1] == '--host':
print json.dumps({});
print(json.dumps({}))
else:
print "Need an argument, either --list or --host <host>"
print("Need an argument, either --list or --host <host>")
4 changes: 2 additions & 2 deletions contrib/inventory/ovirt.py
Expand Up @@ -95,10 +95,10 @@ def __init__(self):

# Just display data for specific host
if self.args.host:
print self.json_format_dict(
print(self.json_format_dict(
self.node_to_dict(self.get_instance(self.args.host)),
pretty=self.args.pretty
)
))
sys.exit(0)

# Otherwise, assume user wants all instances grouped
Expand Down
2 changes: 1 addition & 1 deletion contrib/inventory/proxmox.py
Expand Up @@ -172,7 +172,7 @@ def main():
if options.pretty:
indent = 2

print json.dumps(data, indent=indent)
print(json.dumps(data, indent=indent))

if __name__ == '__main__':
main()
4 changes: 2 additions & 2 deletions contrib/inventory/softlayer.py
Expand Up @@ -53,10 +53,10 @@ def __init__(self):

if self.args.list:
self.get_all_servers()
print self.json_format_dict(self.inventory, True)
print(self.json_format_dict(self.inventory, True))
elif self.args.host:
self.get_virtual_servers()
print self.json_format_dict(self.inventory["_meta"]["hostvars"][self.args.host], True)
print(self.json_format_dict(self.inventory["_meta"]["hostvars"][self.args.host], True))

def to_safe(self, word):
'''Converts 'bad' characters in a string to underscores so they can be used as Ansible groups'''
Expand Down

0 comments on commit 3f9879a

Please sign in to comment.