Skip to content

Commit 36148ad

Browse files
author
Jonathan Abrahams
committed
SERVER-23312 Format Python files with yapf
1 parent d62d631 commit 36148ad

File tree

131 files changed

+3113
-4036
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+3113
-4036
lines changed

buildscripts/.style.yapf renamed to .style.yapf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
based_on_style = pep8
44
column_limit = 100
55
indent_dictionary_value = True
6-
6+
split_before_named_assigns = False
7+
each_dict_entry_on_separate_line = False

buildscripts/.pylintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# See https://www.pylint.org/
22
[MESSAGES CONTROL]
33
# C0301 - line-too-long - some of the type annotations are longer then 100 columns
4+
# C0330 - bad-continuation - ignore conflicts produced by yapf formatting
45
# E0401 - import-error - ignore imports that fail to load
56
# I0011 - locally-disabled - ignore warnings about disable pylint checks
67
# R0903 - too-few-public-method - pylint does not always know best
78
# W0511 - fixme - ignore TODOs in comments
89
# W0611 - unused-import - typing module is needed for mypy
910

10-
disable=fixme,import-error,line-too-long,locally-disabled,too-few-public-methods,unused-import
11+
disable=bad-continuation,fixme,import-error,line-too-long,locally-disabled,too-few-public-methods,unused-import

buildscripts/aggregate_tracefiles.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
import os
33
import sys
44
from optparse import OptionParser
5-
65
""" This script aggregates several tracefiles into one tracefile
76
All but the last argument are input tracefiles or .txt files which list tracefiles.
87
The last argument is the tracefile to which the output will be written
98
"""
9+
10+
1011
def aggregate(inputs, output):
1112
"""Aggregates the tracefiles given in inputs to a tracefile given by output"""
1213
args = ['lcov']
@@ -17,18 +18,20 @@ def aggregate(inputs, output):
1718
args += ['-o', output]
1819

1920
print ' '.join(args)
20-
21-
return subprocess.call(args)
21+
22+
return subprocess.call(args)
23+
2224

2325
def getfilesize(path):
2426
if not os.path.isfile(path):
2527
return 0
2628
return os.path.getsize(path)
2729

28-
def main ():
30+
31+
def main():
2932
inputs = []
3033

31-
usage = "usage: %prog input1.info input2.info ... output.info"
34+
usage = "usage: %prog input1.info input2.info ... output.info"
3235
parser = OptionParser(usage=usage)
3336

3437
(options, args) = parser.parse_args()
@@ -43,12 +46,12 @@ def main ():
4346
inputs.append(path)
4447

4548
elif ext == '.txt':
46-
inputs += [line.strip() for line in open(path)
47-
if getfilesize(line.strip()) > 0]
49+
inputs += [line.strip() for line in open(path) if getfilesize(line.strip()) > 0]
4850
else:
4951
return "unrecognized file type"
5052

5153
return aggregate(inputs, args[-1])
5254

55+
5356
if __name__ == '__main__':
5457
sys.exit(main())

buildscripts/aws_ec2.py

Lines changed: 57 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python
2-
32
"""AWS EC2 instance launcher and controller."""
43

54
from __future__ import print_function
@@ -21,16 +20,9 @@ class AwsEc2(object):
2120
"""Class to support controlling AWS EC2 istances."""
2221

2322
InstanceStatus = collections.namedtuple("InstanceStatus", [
24-
"instance_id",
25-
"image_id",
26-
"instance_type",
27-
"state",
28-
"private_ip_address",
29-
"public_ip_address",
30-
"private_dns_name",
31-
"public_dns_name",
32-
"tags"
33-
])
23+
"instance_id", "image_id", "instance_type", "state", "private_ip_address",
24+
"public_ip_address", "private_dns_name", "public_dns_name", "tags"
25+
])
3426

3527
def __init__(self):
3628
try:
@@ -46,8 +38,7 @@ def wait_for_state(instance, state, wait_time_secs=0, show_progress=False):
4638
"""Wait up to 'wait_time_secs' for instance to be in 'state'.
4739
Return 0 if 'state' reached, 1 otherwise."""
4840
if show_progress:
49-
print("Waiting for instance {} to reach '{}' state".format(instance, state),
50-
end="",
41+
print("Waiting for instance {} to reach '{}' state".format(instance, state), end="",
5142
file=sys.stdout)
5243
reached_state = False
5344
end_time = time.time() + wait_time_secs
@@ -83,8 +74,7 @@ def wait_for_state(instance, state, wait_time_secs=0, show_progress=False):
8374
def control_instance(self, mode, image_id, wait_time_secs=0, show_progress=False):
8475
"""Controls an AMI instance. Returns 0 & status information, if successful."""
8576
if mode not in _MODES:
86-
raise ValueError(
87-
"Invalid mode '{}' specified, choose from {}.".format(mode, _MODES))
77+
raise ValueError("Invalid mode '{}' specified, choose from {}.".format(mode, _MODES))
8878

8979
sys.stdout.flush()
9080
instance = self.connection.Instance(image_id)
@@ -112,23 +102,17 @@ def control_instance(self, mode, image_id, wait_time_secs=0, show_progress=False
112102

113103
ret = 0
114104
if wait_time_secs > 0:
115-
ret = self.wait_for_state(
116-
instance=instance,
117-
state=state,
118-
wait_time_secs=wait_time_secs,
119-
show_progress=show_progress)
105+
ret = self.wait_for_state(instance=instance, state=state, wait_time_secs=wait_time_secs,
106+
show_progress=show_progress)
120107
try:
121108
# Always provide status after executing command.
122109
status = self.InstanceStatus(
123-
getattr(instance, "instance_id", None),
124-
getattr(instance, "image_id", None),
125-
getattr(instance, "instance_type", None),
126-
getattr(instance, "state", None),
110+
getattr(instance, "instance_id", None), getattr(instance, "image_id", None),
111+
getattr(instance, "instance_type", None), getattr(instance, "state", None),
127112
getattr(instance, "private_ip_address", None),
128113
getattr(instance, "public_ip_address", None),
129114
getattr(instance, "private_dns_name", None),
130-
getattr(instance, "public_dns_name", None),
131-
getattr(instance, "tags", None))
115+
getattr(instance, "public_dns_name", None), getattr(instance, "tags", None))
132116
except botocore.exceptions.ClientError as err:
133117
return 1, err.message
134118

@@ -151,18 +135,9 @@ def tag_instance(self, image_id, tags):
151135
time.sleep(i + 1)
152136
instance.create_tags(Tags=tags)
153137

154-
def launch_instance(self,
155-
ami,
156-
instance_type,
157-
block_devices=None,
158-
key_name=None,
159-
security_group_ids=None,
160-
security_groups=None,
161-
subnet_id=None,
162-
tags=None,
163-
wait_time_secs=0,
164-
show_progress=False,
165-
**kwargs):
138+
def launch_instance(self, ami, instance_type, block_devices=None, key_name=None,
139+
security_group_ids=None, security_groups=None, subnet_id=None, tags=None,
140+
wait_time_secs=0, show_progress=False, **kwargs):
166141
"""Launches and tags an AMI instance.
167142
168143
Returns the tuple (0, status_information), if successful."""
@@ -187,22 +162,15 @@ def launch_instance(self,
187162
kwargs["KeyName"] = key_name
188163

189164
try:
190-
instances = self.connection.create_instances(
191-
ImageId=ami,
192-
InstanceType=instance_type,
193-
MaxCount=1,
194-
MinCount=1,
195-
**kwargs)
165+
instances = self.connection.create_instances(ImageId=ami, InstanceType=instance_type,
166+
MaxCount=1, MinCount=1, **kwargs)
196167
except (botocore.exceptions.ClientError, botocore.exceptions.ParamValidationError) as err:
197168
return 1, err.message
198169

199170
instance = instances[0]
200171
if wait_time_secs > 0:
201-
self.wait_for_state(
202-
instance=instance,
203-
state="running",
204-
wait_time_secs=wait_time_secs,
205-
show_progress=show_progress)
172+
self.wait_for_state(instance=instance, state="running", wait_time_secs=wait_time_secs,
173+
show_progress=show_progress)
206174

207175
self.tag_instance(instance.instance_id, tags)
208176

@@ -218,93 +186,60 @@ def main():
218186
control_options = optparse.OptionGroup(parser, "Control options")
219187
create_options = optparse.OptionGroup(parser, "Create options")
220188

221-
parser.add_option("--mode",
222-
dest="mode",
223-
choices=_MODES,
224-
default="status",
225-
help="Operations to perform on an EC2 instance, choose one of"
226-
" '{}', defaults to '%default'.".format(", ".join(_MODES)))
189+
parser.add_option("--mode", dest="mode", choices=_MODES, default="status",
190+
help=("Operations to perform on an EC2 instance, choose one of"
191+
" '{}', defaults to '%default'.".format(", ".join(_MODES))))
227192

228-
control_options.add_option("--imageId",
229-
dest="image_id",
230-
default=None,
193+
control_options.add_option("--imageId", dest="image_id", default=None,
231194
help="EC2 image_id to perform operation on [REQUIRED for control].")
232195

233-
control_options.add_option("--waitTimeSecs",
234-
dest="wait_time_secs",
235-
type=int,
236-
default=5 * 60,
237-
help="Time to wait for EC2 instance to reach it's new state,"
238-
" defaults to '%default'.")
196+
control_options.add_option("--waitTimeSecs", dest="wait_time_secs", type=int, default=5 * 60,
197+
help=("Time to wait for EC2 instance to reach it's new state,"
198+
" defaults to '%default'."))
239199

240-
create_options.add_option("--ami",
241-
dest="ami",
242-
default=None,
200+
create_options.add_option("--ami", dest="ami", default=None,
243201
help="EC2 AMI to launch [REQUIRED for create].")
244202

245-
create_options.add_option("--blockDevice",
246-
dest="block_devices",
247-
metavar="DEVICE-NAME DEVICE-SIZE-GB",
248-
action="append",
249-
default=[],
203+
create_options.add_option("--blockDevice", dest="block_devices",
204+
metavar="DEVICE-NAME DEVICE-SIZE-GB", action="append", default=[],
250205
nargs=2,
251-
help="EBS device name and volume size in GiB."
252-
" More than one device can be attached, by specifying"
253-
" this option more than once."
254-
" The device will be deleted on termination of the instance.")
255-
256-
create_options.add_option("--instanceType",
257-
dest="instance_type",
258-
default="t1.micro",
206+
help=("EBS device name and volume size in GiB."
207+
" More than one device can be attached, by specifying"
208+
" this option more than once."
209+
" The device will be deleted on termination of the instance."))
210+
211+
create_options.add_option("--instanceType", dest="instance_type", default="t1.micro",
259212
help="EC2 instance type to launch, defaults to '%default'.")
260213

261-
create_options.add_option("--keyName",
262-
dest="key_name",
263-
default=None,
214+
create_options.add_option("--keyName", dest="key_name", default=None,
264215
help="EC2 key name [REQUIRED for create].")
265216

266-
create_options.add_option("--securityGroupIds",
267-
dest="security_group_ids",
268-
action="append",
217+
create_options.add_option("--securityGroupIds", dest="security_group_ids", action="append",
269218
default=[],
270-
help="EC2 security group ids. More than one security group id can be"
271-
" added, by specifying this option more than once.")
219+
help=("EC2 security group ids. More than one security group id can be"
220+
" added, by specifying this option more than once."))
272221

273-
create_options.add_option("--securityGroup",
274-
dest="security_groups",
275-
action="append",
222+
create_options.add_option("--securityGroup", dest="security_groups", action="append",
276223
default=[],
277-
help="EC2 security group. More than one security group can be added,"
278-
" by specifying this option more than once.")
224+
help=("EC2 security group. More than one security group can be added,"
225+
" by specifying this option more than once."))
279226

280-
create_options.add_option("--subnetId",
281-
dest="subnet_id",
282-
default=None,
227+
create_options.add_option("--subnetId", dest="subnet_id", default=None,
283228
help="EC2 subnet id to use in VPC.")
284229

285-
create_options.add_option("--tagExpireHours",
286-
dest="tag_expire_hours",
287-
type=int,
288-
default=2,
230+
create_options.add_option("--tagExpireHours", dest="tag_expire_hours", type=int, default=2,
289231
help="EC2 tag expire time in hours, defaults to '%default'.")
290232

291-
create_options.add_option("--tagName",
292-
dest="tag_name",
293-
default="",
233+
create_options.add_option("--tagName", dest="tag_name", default="",
294234
help="EC2 tag and instance name.")
295235

296-
create_options.add_option("--tagOwner",
297-
dest="tag_owner",
298-
default="",
299-
help="EC2 tag owner.")
236+
create_options.add_option("--tagOwner", dest="tag_owner", default="", help="EC2 tag owner.")
300237

301-
create_options.add_option("--extraArgs",
302-
dest="extra_args",
303-
metavar="{key1: value1, key2: value2, ..., keyN: valueN}",
304-
default=None,
305-
help="EC2 create instance keyword args. The argument is specified as"
306-
" bracketed YAML - i.e. JSON with support for single quoted"
307-
" and unquoted keys. Example, '{DryRun: True}'")
238+
create_options.add_option(
239+
"--extraArgs", dest="extra_args", metavar="{key1: value1, key2: value2, ..., keyN: valueN}",
240+
default=None, help=("EC2 create instance keyword args. The argument is specified as"
241+
" bracketed YAML - i.e. JSON with support for single quoted"
242+
" and unquoted keys. Example, '{DryRun: True}'"))
308243

309244
parser.add_option_group(control_options)
310245
parser.add_option_group(create_options)
@@ -331,34 +266,25 @@ def main():
331266
# The 'expire-on' key is a UTC time.
332267
expire_dt = datetime.datetime.utcnow() + datetime.timedelta(hours=options.tag_expire_hours)
333268
tags = [{"Key": "expire-on", "Value": expire_dt.strftime("%Y-%m-%d %H:%M:%S")},
334-
{"Key": "Name", "Value": options.tag_name},
335-
{"Key": "owner", "Value": options.tag_owner}]
269+
{"Key": "Name",
270+
"Value": options.tag_name}, {"Key": "owner", "Value": options.tag_owner}]
336271

337272
my_kwargs = {}
338273
if options.extra_args is not None:
339274
my_kwargs = yaml.safe_load(options.extra_args)
340275

341276
(ret_code, instance_status) = aws_ec2.launch_instance(
342-
ami=options.ami,
343-
instance_type=options.instance_type,
344-
block_devices=block_devices,
345-
key_name=options.key_name,
346-
security_group_ids=options.security_group_ids,
347-
security_groups=options.security_groups,
348-
subnet_id=options.subnet_id,
349-
tags=tags,
350-
wait_time_secs=options.wait_time_secs,
351-
show_progress=True,
352-
**my_kwargs)
277+
ami=options.ami, instance_type=options.instance_type, block_devices=block_devices,
278+
key_name=options.key_name, security_group_ids=options.security_group_ids,
279+
security_groups=options.security_groups, subnet_id=options.subnet_id, tags=tags,
280+
wait_time_secs=options.wait_time_secs, show_progress=True, **my_kwargs)
353281
else:
354282
if not getattr(options, "image_id", None):
355283
parser.print_help()
356284
parser.error("Missing required control option")
357285

358286
(ret_code, instance_status) = aws_ec2.control_instance(
359-
mode=options.mode,
360-
image_id=options.image_id,
361-
wait_time_secs=options.wait_time_secs,
287+
mode=options.mode, image_id=options.image_id, wait_time_secs=options.wait_time_secs,
362288
show_progress=True)
363289

364290
print("Return code: {}, Instance status:".format(ret_code))
@@ -370,5 +296,6 @@ def main():
370296

371297
sys.exit(ret_code)
372298

299+
373300
if __name__ == "__main__":
374301
main()

0 commit comments

Comments
 (0)