Skip to content

Commit

Permalink
Cleanup code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesls committed Feb 2, 2015
1 parent a5c8468 commit fb51db1
Showing 1 changed file with 76 additions and 36 deletions.
112 changes: 76 additions & 36 deletions awscli/customizations/s3/subcommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,39 @@
SizeAndLastModifiedSync, NeverSync



RECURSIVE = {'name': 'recursive', 'action': 'store_true', 'dest': 'dir_op',
'help_text': (
"Command is performed on all files or objects "
"under the specified directory or prefix.")}


HUMAN_READABLE = {'name': 'human-readable', 'action': 'store_true',
'help_text': "Displays file sizes in human readable format."}

SUMMARIZE = {'name': 'summarize', 'action': 'store_true', 'help_text': (
"Displays summary information (number of objects, total size).")}

SUMMARIZE = {'name': 'summarize', 'action': 'store_true',
'help_text': (
"Displays summary information "
"(number of objects, total size).")}


DRYRUN = {'name': 'dryrun', 'action': 'store_true',
'help_text': (
"Displays the operations that would be performed using the "
"specified command without actually running them.")}


QUIET = {'name': 'quiet', 'action': 'store_true',
'help_text': (
"Does not display the operations performed from the specified "
"command.")}


FORCE = {'name': 'force', 'action': 'store_true',
'help_text': (
"Deletes all objects in the bucket including the bucket itself.")}


FOLLOW_SYMLINKS = {'name': 'follow-symlinks', 'action': 'store_true',
'default': True, 'group_name': 'follow_symlinks',
'help_text': (
Expand All @@ -69,34 +76,40 @@
"nor ``--no-follow-symlinks`` is specifed, the default "
"is to follow symlinks.")}


NO_FOLLOW_SYMLINKS = {'name': 'no-follow-symlinks', 'action': 'store_false',
'dest': 'follow_symlinks', 'default': True,
'group_name': 'follow_symlinks'}


NO_GUESS_MIME_TYPE = {'name': 'no-guess-mime-type', 'action': 'store_false',
'dest': 'guess_mime_type', 'default': True,
'help_text': (
"Do not try to guess the mime type for "
"uploaded files. By default the mime type of a "
"file is guessed when it is uploaded.")}


CONTENT_TYPE = {'name': 'content-type', 'nargs': 1,
'help_text': (
"Specify an explicit content type for this operation. "
"This value overrides any guessed mime types.")}


EXCLUDE = {'name': 'exclude', 'action': AppendFilter, 'nargs': 1,
'dest': 'filters',
'help_text': (
"Exclude all files or objects from the command that matches "
"the specified pattern.")}


INCLUDE = {'name': 'include', 'action': AppendFilter, 'nargs': 1,
'dest': 'filters',
'help_text': (
"Don't exclude files or objects "
"in the command that match the specified pattern")}


ACL = {'name': 'acl', 'nargs': 1,
'choices': ['private', 'public-read', 'public-read-write',
'authenticated-read', 'bucket-owner-read',
Expand All @@ -108,39 +121,46 @@
"``bucket-owner-read``, ``bucket-owner-full-control`` and "
"``log-delivery-write``.")}

GRANTS = {'name': 'grants', 'nargs': '+',
'help_text': (
"Grant specific permissions to individual users or groups. You "
"can supply a list of grants of the form::<p/> --grants "
"Permission=Grantee_Type=Grantee_ID [Permission=Grantee_Type="
"Grantee_ID ...]<p/>Each value contains the following elements:"
"<p/><ul><li><code>Permission</code> - Specifies "
"the granted permissions, and can be set to read, readacl, "
"writeacl, or full.</li><li><code>Grantee_Type</code> - "
"Specifies how the grantee is to be identified, and can be set "
"to uri, emailaddress, or id.</li><li><code>Grantee_ID</code> - "
"Specifies the grantee based on Grantee_Type.</li></ul>The "
"<code>Grantee_ID</code> value can be one of:<ul><li><b>uri</b> "
"- The group's URI. For more information, see "
'<a href="http://docs.aws.amazon.com/AmazonS3/latest/dev/ACLOverview.html#SpecifyingGrantee">'
"Who Is a Grantee?</a></li>"
"<li><b>emailaddress</b> - The account's email address.</li>"
"<li><b>id</b> - The account's canonical ID</li></ul>"
"</li></ul>"
"For more information on Amazon S3 access control, see "
'<a href="http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingAuthAccess.html">Access Control</a>')}

GRANTS = {
'name': 'grants', 'nargs': '+',
'help_text': (
'Grant specific permissions to individual users or groups. You '
'can supply a list of grants of the form::<p/> --grants '
'Permission=Grantee_Type=Grantee_ID [Permission=Grantee_Type='
'Grantee_ID ...]<p/>Each value contains the following elements:'
'<p/><ul><li><code>Permission</code> - Specifies '
'the granted permissions, and can be set to read, readacl, '
'writeacl, or full.</li><li><code>Grantee_Type</code> - '
'Specifies how the grantee is to be identified, and can be set '
'to uri, emailaddress, or id.</li><li><code>Grantee_ID</code> - '
'Specifies the grantee based on Grantee_Type.</li></ul>The '
'<code>Grantee_ID</code> value can be one of:<ul><li><b>uri</b> '
'- The group\'s URI. For more information, see '
'<a href="http://docs.aws.amazon.com/AmazonS3/latest/dev/'
'ACLOverview.html#SpecifyingGrantee">'
'Who Is a Grantee?</a></li>'
'<li><b>emailaddress</b> - The account\'s email address.</li>'
'<li><b>id</b> - The account\'s canonical ID</li></ul>'
'</li></ul>'
'For more information on Amazon S3 access control, see '
'<a href="http://docs.aws.amazon.com/AmazonS3/latest/dev/'
'UsingAuthAccess.html">Access Control</a>')}


SSE = {'name': 'sse', 'action': 'store_true',
'help_text': (
"Enable Server Side Encryption of the object in S3")}


STORAGE_CLASS = {'name': 'storage-class', 'nargs': 1,
'choices': ['STANDARD', 'REDUCED_REDUNDANCY'],
'help_text': (
"The type of storage to use for the object. "
"Valid choices are: STANDARD | REDUCED_REDUNDANCY. "
"Defaults to 'STANDARD'")}


WEBSITE_REDIRECT = {'name': 'website-redirect', 'nargs': 1,
'help_text': (
"If the bucket is configured as a website, "
Expand All @@ -149,26 +169,31 @@
"stores the value of this header in the object "
"metadata.")}


CACHE_CONTROL = {'name': 'cache-control', 'nargs': 1,
'help_text': (
"Specifies caching behavior along the "
"request/reply chain.")}


CONTENT_DISPOSITION = {'name': 'content-disposition', 'nargs': 1,
'help_text': (
"Specifies presentational information "
"for the object.")}


CONTENT_ENCODING = {'name': 'content-encoding', 'nargs': 1,
'help_text': (
"Specifies what content encodings have been "
"applied to the object and thus what decoding "
"mechanisms must be applied to obtain the media-type "
"referenced by the Content-Type header field.")}


CONTENT_LANGUAGE = {'name': 'content-language', 'nargs': 1,
'help_text': ("The language the content is in.")}


SOURCE_REGION = {'name': 'source-region', 'nargs': 1,
'help_text': (
"When transferring objects from an s3 bucket to an s3 "
Expand All @@ -179,8 +204,13 @@
"specified the region of the source will be the same "
"as the region of the destination bucket.")}

EXPIRES = {'name': 'expires', 'nargs': 1, 'help_text': ("The date and time at "
"which the object is no longer cacheable.")}

EXPIRES = {
'name': 'expires', 'nargs': 1,
'help_text': (
"The date and time at which the object is no longer cacheable.")
}


INDEX_DOCUMENT = {'name': 'index-document',
'help_text': (
Expand All @@ -192,16 +222,19 @@
'images/index.html) The suffix must not be empty and '
'must not include a slash character.')}


ERROR_DOCUMENT = {'name': 'error-document',
'help_text': (
'The object key name to use when '
'a 4XX class error occurs.')}


ONLY_SHOW_ERRORS = {'name': 'only-show-errors', 'action': 'store_true',
'help_text': (
'Only errors and warnings are displayed. All other '
'output is suppressed.')}


EXPECTED_SIZE = {'name': 'expected-size',
'help_text': (
'This argument specifies the expected size of a stream '
Expand All @@ -213,10 +246,10 @@


PAGE_SIZE = {'name': 'page-size', 'cli_type_name': 'integer',
'help_text': (
'The number of results to return in each response to a list '
'operation. The default value is 1000 (the maximum allowed). '
'Using a lower value may help if an operation times out.')}
'help_text': (
'The number of results to return in each response to a list '
'operation. The default value is 1000 (the maximum allowed). '
'Using a lower value may help if an operation times out.')}


TRANSFER_ARGS = [DRYRUN, QUIET, RECURSIVE, INCLUDE, EXCLUDE, ACL,
Expand Down Expand Up @@ -355,15 +388,18 @@ def _make_last_mod_str(self, last_mod):
str(last_mod.day).zfill(2),
str(last_mod.hour).zfill(2),
str(last_mod.minute).zfill(2),
str(last_mod.second).zfill(2))
str(last_mod.second).zfill(2))
last_mod_str = "%s-%s-%s %s:%s:%s" % last_mod_tup
return last_mod_str.ljust(19, ' ')

def _make_size_str(self, size):
"""
This function creates the size string when objects are being listed.
"""
size_str = human_readable_size(size) if self._human_readable else str(size)
if self._human_readable:
size_str = human_readable_size(size)
else:
size_str = str(size)
return size_str.rjust(10, ' ')

def _print_summary(self):
Expand All @@ -372,7 +408,10 @@ def _print_summary(self):
"""
print_str = str(self._total_objects)
uni_print("\nTotal Objects: ".rjust(15, ' ') + print_str + "\n")
print_str = human_readable_size(self._size_accumulator) if self._human_readable else str(self._size_accumulator)
if self._human_readable:
print_str = human_readable_size(self._size_accumulator)
else:
print_str = str(self._size_accumulator)
uni_print("Total Size: ".rjust(15, ' ') + print_str + "\n")


Expand Down Expand Up @@ -668,8 +707,9 @@ def run(self):
service=self._service,
endpoint=self._endpoint,
is_stream=True)]
file_info_builder = FileInfoBuilder(self._service, self._endpoint,
self._source_endpoint, self.parameters)
file_info_builder = FileInfoBuilder(
self._service, self._endpoint,
self._source_endpoint, self.parameters)
s3handler = S3Handler(self.session, self.parameters,
result_queue=result_queue)
s3_stream_handler = S3StreamHandler(self.session, self.parameters,
Expand All @@ -689,7 +729,7 @@ def run(self):
's3_handler': [s3handler]}
elif self.cmd == 'cp' and self.parameters['is_stream']:
command_dict = {'setup': [stream_file_info],
's3_handler': [s3_stream_handler]}
's3_handler': [s3_stream_handler]}
elif self.cmd == 'cp':
command_dict = {'setup': [files],
'file_generator': [file_generator],
Expand Down

0 comments on commit fb51db1

Please sign in to comment.