This repository has been archived by the owner on Aug 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
#16 Interactive mode #18
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
93d2f6e
#16 Interactive mode
74084fb
#16 Removed unused import
5cae539
#16 General improvements
6d2ba29
#16 Fixes PEP 8 E501
0bc80a2
#16 More PEP 8 fixes
4d291ac
#16 Added tests
6f11d58
#16 Yet more PEP 8 fixes
677ea5b
#16 Make Travis CI work?
ea072d9
#16 Better AWS region defaults
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import functools | ||
import sys | ||
from tempfile import NamedTemporaryFile | ||
from traceback import format_exception | ||
|
||
from botocore.exceptions import ClientError, NoCredentialsError | ||
|
||
|
||
def store_exception(exception: Exception) -> str: | ||
""" | ||
Stores the exception in a temporary file and returns its filename | ||
""" | ||
|
||
tracebacks = format_exception(etype=type(exception), | ||
value=exception, | ||
tb=exception.__traceback__) # type: [str] | ||
|
||
content = ''.join(tracebacks) | ||
|
||
with NamedTemporaryFile(prefix="piu-traceback-", delete=False) as error_file: | ||
file_name = error_file.name | ||
error_file.write(content.encode()) | ||
|
||
return file_name | ||
|
||
|
||
def is_credentials_expired_error(e: ClientError) -> bool: | ||
return e.response['Error']['Code'] in ['ExpiredToken', 'RequestExpired'] | ||
|
||
|
||
def handle_exceptions(func): | ||
@functools.wraps(func) | ||
def wrapper(): | ||
try: | ||
func() | ||
except NoCredentialsError as e: | ||
print('No AWS credentials found. Use the "mai" command-line tool to get a temporary access key\n' | ||
'or manually configure either ~/.aws/credentials or AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY.', | ||
file=sys.stderr) | ||
sys.exit(1) | ||
except ClientError as e: | ||
sys.stdout.flush() | ||
if is_credentials_expired_error(e): | ||
print('AWS credentials have expired.\n' | ||
'Use the "mai" command line tool to get a new temporary access key.', | ||
file=sys.stderr) | ||
sys.exit(1) | ||
else: | ||
file_name = store_exception(e) | ||
print('Unknown Error.\n' | ||
'Please create an issue with the content of {fn}'.format(fn=file_name)) | ||
sys.exit(1) | ||
except Exception as e: | ||
# Catch All | ||
|
||
file_name = store_exception(e) | ||
print('Unknown Error.\n' | ||
'Please create an issue with the content of {fn}'.format(fn=file_name)) | ||
sys.exit(1) | ||
return wrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ PyYAML | |
requests | ||
pyperclip | ||
stups-zign>=0.16 | ||
boto3>=1.3.0 | ||
botocore>=1.4.10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you move this whole part into a function?