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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from outime/issue-16
#16 Interactive mode
- Loading branch information
Showing
4 changed files
with
154 additions
and
8 deletions.
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