Skip to content
This repository has been archived by the owner on May 26, 2021. It is now read-only.

Commit

Permalink
style: updated black
Browse files Browse the repository at this point in the history
  • Loading branch information
kazhala committed Sep 12, 2020
1 parent a0d225b commit 6d8b3ca
Show file tree
Hide file tree
Showing 19 changed files with 90 additions and 34 deletions.
3 changes: 2 additions & 1 deletion fzfaws/cloudformation/changeset_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def describe_changes(cloudformation: Cloudformation, changeset_name: str) -> Non
:type changeset_name: str
"""
response = cloudformation.client.describe_change_set(
ChangeSetName=changeset_name, StackName=cloudformation.stack_name,
ChangeSetName=changeset_name,
StackName=cloudformation.stack_name,
)
print("StackName: %s" % (cloudformation.stack_name))
print("ChangeSetName: %s" % (changeset_name))
Expand Down
2 changes: 1 addition & 1 deletion fzfaws/cloudformation/create_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def construct_s3_creation_args(
:param cloudformation: Cloudformation instance
:type cloudformation: Cloudformation
:param bucket: bucket name
:type bucket:
:type bucket:
:return: return the formated cloudformation argument thats ready to use by boto3
:rtype: Dict[str, Any]
"""
Expand Down
4 changes: 3 additions & 1 deletion fzfaws/cloudformation/delete_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def delete_stack(

logical_id_list: List[str] = []
if cloudformation.stack_details["StackStatus"] == "DELETE_FAILED":
header: str = "stack is in the failed state, specify any resource to skip during deletion"
header: str = (
"stack is in the failed state, specify any resource to skip during deletion"
)
logical_id_list = cloudformation.get_stack_resources(
empty_allow=True, header=header
)
Expand Down
2 changes: 1 addition & 1 deletion fzfaws/cloudformation/helper/cloudformationargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def _set_creation(self) -> None:

def _set_rollback(self, update: bool = False) -> None:
"""Set rollback configuration for cloudformation.
:param update: show previous values and set default values if true
:type update: bool, optional
"""
Expand Down
15 changes: 11 additions & 4 deletions fzfaws/cloudformation/helper/paramprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def _get_user_input(
) -> Union[str, List[str]]:
"""Get user input.
:param parameter_key: the current parameter key to obtain user input
:param parameter_key: the current parameter key to obtain user input
:type parameter_key: str
:param parameter_type: type of the parameter
:type parameter_type: str
Expand Down Expand Up @@ -228,7 +228,11 @@ def _get_user_input(
else:
print(param_header.rstrip())
questions = [
{"type": "input", "message": parameter_key, "name": "answer",}
{
"type": "input",
"message": parameter_key,
"name": "answer",
}
]
if default:
questions[0]["default"] = default
Expand Down Expand Up @@ -259,7 +263,7 @@ def _get_selected_param_value(self, type_name: str, param_header: str) -> str:
:type type_name: str
:param param_header: information about current parameter
:type param_header: str
:return: return the selected value
:return: return the selected value
:rtype: str
"""
fzf = Pyfzf()
Expand Down Expand Up @@ -359,7 +363,10 @@ def _get_param_selection(self) -> List[str]:
else:
original_value = self.original_params.get(parameter_key)
if original_value:
title = "%s: %s" % (parameter_key, original_value,)
title = "%s: %s" % (
parameter_key,
original_value,
)
choices.append({"name": title})
else:
choices.append({"name": parameter_key})
Expand Down
2 changes: 1 addition & 1 deletion fzfaws/cloudformation/ls_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def ls_stack(
:type region: Union[str, bool], optional
:param resource: display resource information rather than stack information
:type resource: bool, optional
:param name: display name of stack or resource instead of the entire information
:param name: display name of stack or resource instead of the entire information
:type name: bool, optional
:param arn: display arn of the stack instead of the entire stack information
:type arn: bool, optional
Expand Down
3 changes: 2 additions & 1 deletion fzfaws/cloudformation/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ def cloudformation(raw_args: List[Any]) -> None:
)

validate_cmd = subparsers.add_parser(
"validate", description="Validate the selected template.",
"validate",
description="Validate the selected template.",
)
validate_cmd.add_argument(
"-b",
Expand Down
3 changes: 2 additions & 1 deletion fzfaws/ec2/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def ec2(raw_args: List[Any]) -> None:
:type raw_args: List[Any]
"""
parser = argparse.ArgumentParser(
description="Perform operations and interact with aws EC2.", prog="fzfaws ec2",
description="Perform operations and interact with aws EC2.",
prog="fzfaws ec2",
)
subparsers = parser.add_subparsers(dest="subparser_name")

Expand Down
22 changes: 17 additions & 5 deletions fzfaws/ec2/ssh_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,13 @@ def ssh_instance(
os.getenv("FZFAWS_EC2_KEYPAIRS", default="~/.ssh")
)
os.chdir(ssh_key_location)
ssh_key: str = os.path.join(
ssh_key_location, "%s.pem" % ec2.instance_list[0].get("KeyName", "")
) if not keypath else keypath
ssh_key: str = (
os.path.join(
ssh_key_location, "%s.pem" % ec2.instance_list[0].get("KeyName", "")
)
if not keypath
else keypath
)

if not tunnel:
instance_ip = get_instance_ip(ec2.instance_list[0])
Expand All @@ -120,7 +124,11 @@ def ssh_instance(
dest_username = username
dest_ip = get_instance_ip(ec2.instance_list[0])
cmd_list: list = construct_tunnel_ssh(
ssh_key, jumpbox_ip, jumpbox_username, dest_ip, dest_username,
ssh_key,
jumpbox_ip,
jumpbox_username,
dest_ip,
dest_username,
)

ssh = subprocess.Popen(cmd_list, shell=False)
Expand Down Expand Up @@ -158,7 +166,11 @@ def construct_normal_ssh(
cmd_list.append("-A")
# if for custom VPC doesn't have public dns name, use public ip address
cmd_list.extend(
["-i", ssh_key, "%s@%s" % (username, instance_ip),]
[
"-i",
ssh_key,
"%s@%s" % (username, instance_ip),
]
)
else:
raise EC2Error("Key pair not detected in the specified location")
Expand Down
4 changes: 3 additions & 1 deletion fzfaws/ec2/start_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ def start_instance(

ec2.print_instance_details()
if get_confirmation("Above instance will be started, continue?"):
response = ec2.client.start_instances(InstanceIds=ec2.instance_ids,)
response = ec2.client.start_instances(
InstanceIds=ec2.instance_ids,
)
response.pop("ResponseMetadata", None)
print(json.dumps(response, indent=4, default=str))
print(80 * "-")
Expand Down
5 changes: 4 additions & 1 deletion fzfaws/iam/iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ def set_arns(
):
fzf.append_fzf(
"RoleName: %s Arn: %s"
% (role.get("RoleName"), role.get("Arn"),)
% (
role.get("RoleName"),
role.get("Arn"),
)
)
else:
fzf.process_list(result.get("Roles", []), "RoleName", "Arn")
Expand Down
2 changes: 1 addition & 1 deletion fzfaws/lambdaf/lambdaf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Lambdaf(BaseSession):
Handles the initialisation of lambda client, selection of lambda
functions.
:param profile: use a different profile for this opeartion
:type profile: Union[str, bool], optional
:param region: use a different region for this operation
Expand Down
6 changes: 4 additions & 2 deletions fzfaws/s3/delete_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ def delete_s3(
for s3_path in s3.path_list:
print("delete: s3://%s/%s" % (s3.bucket_name, s3_path))
s3.client.delete_object(
Bucket=s3.bucket_name, Key=s3_path,
Bucket=s3.bucket_name,
Key=s3_path,
)


Expand Down Expand Up @@ -222,7 +223,8 @@ def delete_object_recursive(
for s3_key, _ in file_list:
print("delete: s3://%s/%s" % (s3.bucket_name, s3_key))
s3.client.delete_object(
Bucket=s3.bucket_name, Key=s3_key,
Bucket=s3.bucket_name,
Key=s3_key,
)


Expand Down
3 changes: 2 additions & 1 deletion fzfaws/s3/helper/s3args.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,8 @@ def set_tags(
original_values: str = ""
if not version:
tags = self.s3.client.get_object_tagging(
Bucket=self.s3.bucket_name, Key=self.s3.path_list[0],
Bucket=self.s3.bucket_name,
Key=self.s3.path_list[0],
)
for tag in tags.get("TagSet", []):
original_tags.append("%s=%s" % (tag.get("Key"), tag.get("Value")))
Expand Down
6 changes: 5 additions & 1 deletion fzfaws/s3/helper/s3progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ class S3Progress(object):
"""

def __init__(
self, filename: str, bucket: str = None, client=None, version_id: str = None,
self,
filename: str,
bucket: str = None,
client=None,
version_id: str = None,
) -> None:
"""Construct the progress bar instance."""
self._filename: str = filename
Expand Down
13 changes: 11 additions & 2 deletions fzfaws/s3/ls_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ def ls_s3(
if bucket and url:
response = s3.client.get_bucket_location(Bucket=s3.bucket_name)
bucket_location = response["LocationConstraint"]
print("https://s3-%s.amazonaws.com/%s/" % (bucket_location, s3.bucket_name,))
print(
"https://s3-%s.amazonaws.com/%s/"
% (
bucket_location,
s3.bucket_name,
)
)
return
if bucket and uri:
print("s3://%s/" % s3.bucket_name)
Expand Down Expand Up @@ -187,7 +193,10 @@ def get_detailed_info(

else:
for s3_key in s3.path_list:
response = s3.client.head_object(Bucket=s3.bucket_name, Key=s3_key,)
response = s3.client.head_object(
Bucket=s3.bucket_name,
Key=s3_key,
)
tags = s3.client.get_object_tagging(Bucket=s3.bucket_name, Key=s3_key)
acls = s3.client.get_object_acl(Bucket=s3.bucket_name, Key=s3_key)
response.pop("ResponseMetadata", None)
Expand Down
8 changes: 6 additions & 2 deletions fzfaws/s3/object_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ def object_s3(


def update_object_version(
s3: S3, allversion: bool = False, acl: bool = False, tagging: bool = False,
s3: S3,
allversion: bool = False,
acl: bool = False,
tagging: bool = False,
) -> None:
"""Update versions of object's attributes.
Expand Down Expand Up @@ -313,7 +316,8 @@ def update_object_name(s3: S3, version: bool = False) -> None:
Config=s3transferwrapper.transfer_config,
)
s3.client.delete_object(
Bucket=s3.bucket_name, Key=s3.path_list[0],
Bucket=s3.bucket_name,
Key=s3.path_list[0],
)

else:
Expand Down
19 changes: 13 additions & 6 deletions fzfaws/s3/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def set_bucket_and_path(self, bucket: str = None) -> None:
"""Set both bucket and path.
This is used to process argument of "-b bucket/object", if any of them is set,
skip further fzf selection.
skip further fzf selection.
E.g. if bucket is set, skip select bucket. If both bucket and object is set, skip
all fzf selection.
Expand Down Expand Up @@ -93,7 +93,12 @@ def set_s3_path(self, download: bool = False) -> None:
:raises NoSelectionMade: when user did not make a bucket selection, exit
"""
selected_option = self._get_path_option(download=download)
questions: List[Dict[str, str]] = [{"type": "input", "name": "s3_path",}]
questions: List[Dict[str, str]] = [
{
"type": "input",
"name": "s3_path",
}
]

if selected_option == "input":
questions[0]["message"] = "Input the path(newname or newpath/)"
Expand Down Expand Up @@ -241,7 +246,7 @@ def get_object_version(
no_progress: bool = False,
) -> List[Dict[str, str]]:
"""List object versions through fzf.
:param bucket: object's bucketname, if not set, class instance's bucket_name will be used
:type bucket: str, optional
:param key: object's key, if not set, class instance's path_list[0] will be used
Expand Down Expand Up @@ -400,7 +405,9 @@ def get_s3_destination_key(self, local_path: str, recursive: bool = False) -> st
def _validate_input_path(
self, user_input
) -> Union[
Tuple[str, Sequence[str]], Tuple[str, Sequence[str]], Tuple[None, None],
Tuple[str, Sequence[str]],
Tuple[str, Sequence[str]],
Tuple[None, None],
]:
"""Validate if the user input path is valid format.
Expand Down Expand Up @@ -496,7 +503,7 @@ def _uniq_object_generator(
solutions, although this handle one less edge case (if user delete a version object
but then created a new object with the same name), this is much faster and better
in memory usage.
:param results: the result from boto3 paginator
:type results: List[Dict[str, Any]]
:param onlydelete: boolean indicator indicates whether to only show deletemark.
Expand Down
2 changes: 1 addition & 1 deletion fzfaws/utils/pyfzf.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def execute_fzf(
fzf.append_fzf('World: world')
fzf.append_fzf('\n')
print(fzf.execute_fzf(empty_allow=True, print_col=1, preview='cat {}', multi_select=True))
The selected string would look like "Hello: hello".
Above example would return 'Hello:'' if the first entry is selected, print col is 1,
if print_col was 2, 'hello' would be printed.
Expand Down

0 comments on commit 6d8b3ca

Please sign in to comment.