Skip to content

Commit 797664d

Browse files
committed
Python 2.6 str.format() compatibility fixes.
1 parent 95ff8f1 commit 797664d

File tree

20 files changed

+43
-62
lines changed

20 files changed

+43
-62
lines changed

contrib/inventory/proxmox.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def __init__(self, options):
9797
raise Exception('Missing mandatory parameter --password (or PROXMOX_PASSWORD).')
9898

9999
def auth(self):
100-
request_path = '{}api2/json/access/ticket'.format(self.options.url)
100+
request_path = '{0}api2/json/access/ticket'.format(self.options.url)
101101

102102
request_params = urlencode({
103103
'username': self.options.username,
@@ -112,9 +112,9 @@ def auth(self):
112112
}
113113

114114
def get(self, url, data=None):
115-
request_path = '{}{}'.format(self.options.url, url)
115+
request_path = '{0}{1}'.format(self.options.url, url)
116116

117-
headers = {'Cookie': 'PVEAuthCookie={}'.format(self.credentials['ticket'])}
117+
headers = {'Cookie': 'PVEAuthCookie={0}'.format(self.credentials['ticket'])}
118118
request = open_url(request_path, data=data, headers=headers)
119119

120120
response = json.load(request)
@@ -124,10 +124,10 @@ def nodes(self):
124124
return ProxmoxNodeList(self.get('api2/json/nodes'))
125125

126126
def vms_by_type(self, node, type):
127-
return ProxmoxVMList(self.get('api2/json/nodes/{}/{}'.format(node, type)))
127+
return ProxmoxVMList(self.get('api2/json/nodes/{0}/{1}'.format(node, type)))
128128

129129
def vm_description_by_type(self, node, vm, type):
130-
return self.get('api2/json/nodes/{}/{}/{}/config'.format(node, type, vm))
130+
return self.get('api2/json/nodes/{0}/{1}/{2}/config'.format(node, type, vm))
131131

132132
def node_qemu(self, node):
133133
return self.vms_by_type(node, 'qemu')
@@ -145,7 +145,7 @@ def pools(self):
145145
return ProxmoxPoolList(self.get('api2/json/pools'))
146146

147147
def pool(self, poolid):
148-
return ProxmoxPool(self.get('api2/json/pools/{}'.format(poolid)))
148+
return ProxmoxPool(self.get('api2/json/pools/{0}'.format(poolid)))
149149

150150

151151
def main_list(options):

contrib/inventory/stacki.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def main():
173173
config = yaml.safe_load(stream)
174174
break
175175
if not config:
176-
sys.stderr.write("No config file found at {}\n".format(config_files))
176+
sys.stderr.write("No config file found at {0}\n".format(config_files))
177177
sys.exit(1)
178178
client, auth_creds = stack_auth(config['stacki']['auth'])
179179
header = stack_build_header(auth_creds)

contrib/vault/vault-keyring.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ def main():
9191
sys.stderr.write('Passwords do not match\n')
9292
sys.exit(1)
9393
else:
94-
sys.stdout.write('{}\n'.format(keyring.get_password(keyname,
95-
username)))
94+
sys.stdout.write('{0}\n'.format(keyring.get_password(keyname,
95+
username)))
9696

9797
sys.exit(0)
9898

examples/scripts/uptime.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ def main():
7777

7878
print("UP ***********")
7979
for host, result in callback.host_ok.items():
80-
print('{} >>> {}'.format(host, result._result['stdout']))
80+
print('{0} >>> {1}'.format(host, result._result['stdout']))
8181

8282
print("FAILED *******")
8383
for host, result in callback.host_failed.items():
84-
print('{} >>> {}'.format(host, result._result['msg']))
84+
print('{0} >>> {1}'.format(host, result._result['msg']))
8585

8686
print("DOWN *********")
8787
for host, result in callback.host_unreachable.items():
88-
print('{} >>> {}'.format(host, result._result['msg']))
88+
print('{0} >>> {1}'.format(host, result._result['msg']))
8989

9090
if __name__ == '__main__':
9191
main()

hacking/cherrypick.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@
4848
finally:
4949
os.chdir(orig_dir)
5050
except:
51-
print("Problem occurred. Patch saved in: {}".format(patchfilename))
51+
print("Problem occurred. Patch saved in: {0}".format(patchfilename))
5252
else:
5353
os.remove(patchfilename)

hacking/metadata-tool.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@ def insert_metadata(module_data, new_metadata, insertion_line, targets=('ANSIBLE
113113
pretty_metadata = pformat(new_metadata, width=1).split('\n')
114114

115115
new_lines = []
116-
new_lines.append('{} = {}'.format(assignments, pretty_metadata[0]))
116+
new_lines.append('{0} = {1}'.format(assignments, pretty_metadata[0]))
117117

118118
if len(pretty_metadata) > 1:
119119
for line in pretty_metadata[1:]:
120-
new_lines.append('{}{}'.format(' ' * (len(assignments) - 1 + len(' = {')), line))
120+
new_lines.append('{0}{1}'.format(' ' * (len(assignments) - 1 + len(' = {')), line))
121121

122122
old_lines = module_data.split('\n')
123123
lines = old_lines[:insertion_line] + new_lines + old_lines[insertion_line:]
@@ -209,7 +209,7 @@ def write_metadata(filename, new_metadata, version=None, overwrite=False):
209209
raise
210210
# Probably non-python modules. These should all have python
211211
# documentation files where we can place the data
212-
raise ParseError('Could not add metadata to {}'.format(filename))
212+
raise ParseError('Could not add metadata to {0}'.format(filename))
213213

214214
if current_metadata is None:
215215
# No current metadata so we can just add it
@@ -219,7 +219,7 @@ def write_metadata(filename, new_metadata, version=None, overwrite=False):
219219
# These aren't new-style modules
220220
return
221221

222-
raise Exception('Module file {} had no ANSIBLE_METADATA or DOCUMENTATION'.format(filename))
222+
raise Exception('Module file {0} had no ANSIBLE_METADATA or DOCUMENTATION'.format(filename))
223223

224224
module_data = insert_metadata(module_data, new_metadata, start_line, targets=('ANSIBLE_METADATA',))
225225

@@ -363,7 +363,7 @@ def add_from_csv(csv_file, version=None, overwrite=False):
363363
for module_name, new_metadata in parse_assigned_metadata(csv_file):
364364
filename = module_loader.find_plugin(module_name, mod_type='.py')
365365
if filename is None:
366-
diagnostic_messages.append('Unable to find the module file for {}'.format(module_name))
366+
diagnostic_messages.append('Unable to find the module file for {0}'.format(module_name))
367367
continue
368368

369369
try:

lib/ansible/module_utils/dimensiondata.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def __init__(self, module):
8080

8181
# Region and location are common to all Dimension Data modules.
8282
region = self.module.params['region']
83-
self.region = 'dd-{}'.format(region)
83+
self.region = 'dd-{0}'.format(region)
8484
self.location = self.module.params['location']
8585

8686
libcloud.security.VERIFY_SSL_CERT = self.module.params['validate_certs']

lib/ansible/module_utils/ovirt.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def search_by_attributes(service, **kwargs):
227227
# Check if 'list' method support search(look for search parameter):
228228
if 'search' in inspect.getargspec(service.list)[0]:
229229
res = service.list(
230-
search=' and '.join('{}={}'.format(k, v) for k, v in kwargs.items())
230+
search=' and '.join('{0}={1}'.format(k, v) for k, v in kwargs.items())
231231
)
232232
else:
233233
res = [
@@ -712,7 +712,7 @@ def action(
712712

713713
if entity is None:
714714
self._module.fail_json(
715-
msg="Entity not found, can't run action '{}'.".format(
715+
msg="Entity not found, can't run action '{0}'.".format(
716716
action
717717
)
718718
)

lib/ansible/module_utils/univention_umc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def uldap():
105105
def construct():
106106
try:
107107
secret_file = open('/etc/ldap.secret', 'r')
108-
bind_dn = 'cn=admin,{}'.format(base_dn())
108+
bind_dn = 'cn=admin,{0}'.format(base_dn())
109109
except IOError: # pragma: no cover
110110
secret_file = open('/etc/machine.secret', 'r')
111111
bind_dn = config_registry()["ldap/hostdn"]

lib/ansible/plugins/callback/context_demo.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def __init__(self, *args, **kwargs):
3636
self.play = None
3737

3838
def v2_on_any(self, *args, **kwargs):
39-
self._display.display("--- play: {} task: {} ---".format(getattr(self.play, 'name', None), self.task))
39+
self._display.display("--- play: {0} task: {1} ---".format(getattr(self.play, 'name', None), self.task))
4040

4141
self._display.display(" --- ARGS ")
4242
for i, a in enumerate(args):

lib/ansible/plugins/callback/hipchat.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def send_msg_v2(self, msg, msg_format='text', color='yellow', notify=False):
141141
response = open_url(url, data=data, headers=headers, method='POST')
142142
return response.read()
143143
except Exception as ex:
144-
self._display.warning('Could not submit message to hipchat: {}'.format(ex))
144+
self._display.warning('Could not submit message to hipchat: {0}'.format(ex))
145145

146146
def send_msg_v1(self, msg, msg_format='text', color='yellow', notify=False):
147147
"""Method for sending a message to HipChat"""
@@ -159,7 +159,7 @@ def send_msg_v1(self, msg, msg_format='text', color='yellow', notify=False):
159159
response = open_url(url, data=urlencode(params))
160160
return response.read()
161161
except Exception as ex:
162-
self._display.warning('Could not submit message to hipchat: {}'.format(ex))
162+
self._display.warning('Could not submit message to hipchat: {0}'.format(ex))
163163

164164
def v2_playbook_on_play_start(self, play):
165165
"""Display Playbook and play start messages"""

lib/ansible/plugins/callback/logentries.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def emit_formatted(self, record):
282282

283283
def emit(self, record):
284284
msg = record.rstrip('\n')
285-
msg = "{} {}".format(self.token, msg)
285+
msg = "{0} {1}".format(self.token, msg)
286286
self._appender.put(msg)
287287
self._display.vvvv("Sent event to logentries")
288288

lib/ansible/plugins/callback/selective.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def colorize(msg, color):
7171
if DONT_COLORIZE:
7272
return msg
7373
else:
74-
return '{}{}{}'.format(COLORS[color], msg, COLORS['endc'])
74+
return '{0}{1}{2}'.format(COLORS[color], msg, COLORS['endc'])
7575

7676

7777
class CallbackModule(CallbackBase):
@@ -104,15 +104,15 @@ def _print_task(self, task_name=None):
104104
line_length = 120
105105
if self.last_skipped:
106106
print()
107-
msg = colorize("# {} {}".format(task_name,
108-
'*' * (line_length - len(task_name))), 'bold')
107+
msg = colorize("# {0} {1}".format(task_name,
108+
'*' * (line_length - len(task_name))), 'bold')
109109
print(msg)
110110

111111
def _indent_text(self, text, indent_level):
112112
lines = text.splitlines()
113113
result_lines = []
114114
for l in lines:
115-
result_lines.append("{}{}".format(' ' * indent_level, l))
115+
result_lines.append("{0}{1}".format(' ' * indent_level, l))
116116
return '\n'.join(result_lines)
117117

118118
def _print_diff(self, diff, indent_level):

lib/ansible/plugins/connection/iocage.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def __init__(self, play_context, new_stdin, *args, **kwargs):
5555

5656
jail_uuid = self.get_jail_uuid()
5757

58-
kwargs[Jail.modified_jailname_key] = 'ioc-{}'.format(jail_uuid)
58+
kwargs[Jail.modified_jailname_key] = 'ioc-{0}'.format(jail_uuid)
5959

6060
display.vvv(u"Jail {iocjail} has been translated to {rawjail}".format(
6161
iocjail=self.ioc_jail, rawjail=kwargs[Jail.modified_jailname_key]),
@@ -74,6 +74,6 @@ def get_jail_uuid(self):
7474
p.wait()
7575

7676
if p.returncode != 0:
77-
raise AnsibleError(u"iocage returned an error: {}".format(stdout))
77+
raise AnsibleError(u"iocage returned an error: {0}".format(stdout))
7878

7979
return stdout.strip('\n')

lib/ansible/plugins/lookup/chef_databag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def parse_kv_args(self, args):
7575
setattr(self, arg, parsed)
7676
except ValueError:
7777
raise AnsibleError(
78-
"can't parse arg {}={} as string".format(arg, arg_raw)
78+
"can't parse arg {0}={1} as string".format(arg, arg_raw)
7979
)
8080
if args:
8181
raise AnsibleError(

lib/ansible/plugins/lookup/hiera.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def get(self, hiera_key):
7272

7373
pargs.extend(hiera_key)
7474

75-
rc, output, err = run_cmd("{} -c {} {}".format(
75+
rc, output, err = run_cmd("{0} -c {1} {2}".format(
7676
ANSIBLE_HIERA_BIN, ANSIBLE_HIERA_CFG, hiera_key[0]))
7777

7878
return output.strip()

lib/ansible/plugins/lookup/mongodb.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def _fix_sort_parameter(self, sort_parameter):
121121
return sort_parameter
122122

123123
if not isinstance(sort_parameter, list):
124-
raise AnsibleError(u"Error. Sort parameters must be a list, not [ {} ]".format(sort_parameter))
124+
raise AnsibleError(u"Error. Sort parameters must be a list, not [ {0} ]".format(sort_parameter))
125125

126126
for item in sort_parameter:
127127
self._convert_sort_string_to_constant(item)
@@ -160,7 +160,7 @@ def convert_mongo_result_to_valid_json(self, result):
160160
return (result - datetime.datetime(1970, 1, 1)). total_seconds()
161161
else:
162162
# failsafe
163-
return u"{}".format(result)
163+
return u"{0}".format(result)
164164

165165
def run(self, terms, variables, **kwargs):
166166

lib/ansible/plugins/lookup/passwordstore.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,14 @@ def parse_params(self, term):
154154
if self.paramvals['length'].isdigit():
155155
self.paramvals['length'] = int(self.paramvals['length'])
156156
else:
157-
raise AnsibleError("{} is not a correct value for length".format(self.paramvals['length']))
157+
raise AnsibleError("{0} is not a correct value for length".format(self.paramvals['length']))
158158

159159
# Set PASSWORD_STORE_DIR if directory is set
160160
if self.paramvals['directory']:
161161
if os.path.isdir(self.paramvals['directory']):
162162
os.environ['PASSWORD_STORE_DIR'] = self.paramvals['directory']
163163
else:
164-
raise AnsibleError('Passwordstore directory \'{}\' does not exist'.format(self.paramvals['directory']))
164+
raise AnsibleError('Passwordstore directory \'{0}\' does not exist'.format(self.paramvals['directory']))
165165

166166
def check_pass(self):
167167
try:
@@ -180,7 +180,7 @@ def check_pass(self):
180180
# if pass returns 1 and return string contains 'is not in the password store.'
181181
# We need to determine if this is valid or Error.
182182
if not self.paramvals['create']:
183-
raise AnsibleError('passname: {} not found, use create=True'.format(self.passname))
183+
raise AnsibleError('passname: {0} not found, use create=True'.format(self.passname))
184184
else:
185185
return False
186186
else:
@@ -199,7 +199,7 @@ def update_password(self):
199199
newpass = self.get_newpass()
200200
datetime = time.strftime("%d/%m/%Y %H:%M:%S")
201201
msg = newpass + '\n' + '\n'.join(self.passoutput[1:])
202-
msg += "\nlookup_pass: old password was {} (Updated on {})\n".format(self.password, datetime)
202+
msg += "\nlookup_pass: old password was {0} (Updated on {1})\n".format(self.password, datetime)
203203
try:
204204
check_output2(['pass', 'insert', '-f', '-m', self.passname], input=msg)
205205
except (subprocess.CalledProcessError) as e:
@@ -211,7 +211,7 @@ def generate_password(self):
211211
# use pwgen to generate the password and insert values with pass -m
212212
newpass = self.get_newpass()
213213
datetime = time.strftime("%d/%m/%Y %H:%M:%S")
214-
msg = newpass + '\n' + "lookup_pass: First generated by ansible on {}\n".format(datetime)
214+
msg = newpass + '\n' + "lookup_pass: First generated by ansible on {0}\n".format(datetime)
215215
try:
216216
check_output2(['pass', 'insert', '-f', '-m', self.passname], input=msg)
217217
except (subprocess.CalledProcessError) as e:

test/sanity/pylint/ignore.txt

-19
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
1-
contrib/inventory/proxmox.py ansible-format-automatic-specification
2-
contrib/inventory/stacki.py ansible-format-automatic-specification
3-
contrib/vault/vault-keyring.py ansible-format-automatic-specification
4-
examples/scripts/uptime.py ansible-format-automatic-specification
5-
hacking/cherrypick.py ansible-format-automatic-specification
6-
hacking/metadata-tool.py ansible-format-automatic-specification
71
lib/ansible/cli/adhoc.py syntax-error 3.7
8-
lib/ansible/module_utils/dimensiondata.py ansible-format-automatic-specification
92
lib/ansible/module_utils/network/aci/aci.py ansible-format-automatic-specification
103
lib/ansible/module_utils/network/iosxr/iosxr.py ansible-format-automatic-specification
11-
lib/ansible/module_utils/ovirt.py ansible-format-automatic-specification
12-
lib/ansible/module_utils/univention_umc.py ansible-format-automatic-specification
134
lib/ansible/modules/cloud/amazon/aws_api_gateway.py ansible-format-automatic-specification
145
lib/ansible/modules/cloud/amazon/aws_kms.py ansible-format-automatic-specification
156
lib/ansible/modules/cloud/amazon/ec2_eip.py ansible-format-automatic-specification
@@ -111,17 +102,8 @@ lib/ansible/modules/storage/infinidat/infini_vol.py ansible-format-automatic-spe
111102
lib/ansible/modules/storage/purestorage/purefa_host.py ansible-format-automatic-specification
112103
lib/ansible/modules/storage/purestorage/purefa_pg.py ansible-format-automatic-specification
113104
lib/ansible/modules/system/firewalld.py ansible-format-automatic-specification
114-
lib/ansible/plugins/callback/context_demo.py ansible-format-automatic-specification
115-
lib/ansible/plugins/callback/hipchat.py ansible-format-automatic-specification
116-
lib/ansible/plugins/callback/logentries.py ansible-format-automatic-specification
117-
lib/ansible/plugins/callback/selective.py ansible-format-automatic-specification
118105
lib/ansible/plugins/cliconf/junos.py ansible-no-format-on-bytestring 3
119106
lib/ansible/plugins/cliconf/nxos.py ansible-format-automatic-specification
120-
lib/ansible/plugins/connection/iocage.py ansible-format-automatic-specification
121-
lib/ansible/plugins/lookup/chef_databag.py ansible-format-automatic-specification
122-
lib/ansible/plugins/lookup/hiera.py ansible-format-automatic-specification
123-
lib/ansible/plugins/lookup/mongodb.py ansible-format-automatic-specification
124-
lib/ansible/plugins/lookup/passwordstore.py ansible-format-automatic-specification
125107
test/runner/importer.py missing-docstring 3.7
126108
test/runner/injector/importer.py missing-docstring 3.7
127109
test/runner/injector/injector.py missing-docstring 3.7
@@ -167,4 +149,3 @@ test/runner/shippable.py missing-docstring 3.7
167149
test/runner/test.py missing-docstring 3.7
168150
test/runner/units/test_diff.py missing-docstring 3.7
169151
test/units/modules/network/nuage/test_nuage_vspk.py syntax-error 3.7
170-
test/units/modules/remote_management/oneview/hpe_test_utils.py ansible-format-automatic-specification

test/units/modules/remote_management/oneview/hpe_test_utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def testing_module(self):
5050
EXAMPLES = yaml.load(testing_module.EXAMPLES, yaml.SafeLoader)
5151

5252
except yaml.scanner.ScannerError:
53-
message = "Something went wrong while parsing yaml from {}.EXAMPLES".format(self.testing_class.__module__)
53+
message = "Something went wrong while parsing yaml from {0}.EXAMPLES".format(self.testing_class.__module__)
5454
raise Exception(message)
5555
return testing_module
5656

@@ -152,7 +152,7 @@ def __set_module_examples(self):
152152
self.EXAMPLES = yaml.load(self.testing_module.EXAMPLES, yaml.SafeLoader)
153153

154154
except yaml.scanner.ScannerError:
155-
message = "Something went wrong while parsing yaml from {}.EXAMPLES".format(self.testing_class.__module__)
155+
message = "Something went wrong while parsing yaml from {0}.EXAMPLES".format(self.testing_class.__module__)
156156
raise Exception(message)
157157

158158

0 commit comments

Comments
 (0)