Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Unified Diff: gslib/commands/cat.py

Issue 698893003: Update checked in version of gsutil to version 4.6 (Closed) Base URL: http://dart.googlecode.com/svn/third_party/gsutil/
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gslib/commands/acl.py ('k') | gslib/commands/compose.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gslib/commands/cat.py
===================================================================
--- gslib/commands/cat.py (revision 33376)
+++ gslib/commands/cat.py (working copy)
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
# Copyright 2011 Google Inc. All Rights Reserved.
# Copyright 2011, Nexenta Systems Inc.
#
@@ -12,39 +13,28 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+"""Implementation of Unix-like cat command for cloud storage providers."""
+from __future__ import absolute_import
+
import re
-import sys
+from gslib.cat_helper import CatHelper
from gslib.command import Command
-from gslib.command import COMMAND_NAME
-from gslib.command import COMMAND_NAME_ALIASES
-from gslib.command import FILE_URIS_OK
-from gslib.command import MAX_ARGS
-from gslib.command import MIN_ARGS
-from gslib.command import PROVIDER_URIS_OK
-from gslib.command import SUPPORTED_SUB_ARGS
-from gslib.command import URIS_START_ARG
+from gslib.cs_api_map import ApiSelector
from gslib.exception import CommandException
-from gslib.help_provider import HELP_NAME
-from gslib.help_provider import HELP_NAME_ALIASES
-from gslib.help_provider import HELP_ONE_LINE_SUMMARY
-from gslib.help_provider import HELP_TEXT
-from gslib.help_provider import HelpType
-from gslib.help_provider import HELP_TYPE
from gslib.util import NO_MAX
-from gslib.wildcard_iterator import ContainsWildcard
-_detailed_help_text = ("""
+_DETAILED_HELP_TEXT = ("""
<B>SYNOPSIS</B>
- gsutil cat [-h] uri...
+ gsutil cat [-h] url...
<B>DESCRIPTION</B>
- The cat command outputs the contents of one or more URIs to stdout.
+ The cat command outputs the contents of one or more URLs to stdout.
It is equivalent to doing:
- gsutil cp uri... -
+ gsutil cp url... -
(The final '-' causes gsutil to stream the output to stdout.)
@@ -82,89 +72,55 @@
class CatCommand(Command):
"""Implementation of gsutil cat command."""
- # Command specification (processed by parent class).
- command_spec = {
- # Name of command.
- COMMAND_NAME : 'cat',
- # List of command name aliases.
- COMMAND_NAME_ALIASES : [],
- # Min number of args required by this command.
- MIN_ARGS : 0,
- # Max number of args required by this command, or NO_MAX.
- MAX_ARGS : NO_MAX,
- # Getopt-style string specifying acceptable sub args.
- SUPPORTED_SUB_ARGS : 'hvr:',
- # True if file URIs acceptable for this command.
- FILE_URIS_OK : False,
- # True if provider-only URIs acceptable for this command.
- PROVIDER_URIS_OK : False,
- # Index in args of first URI arg.
- URIS_START_ARG : 0,
- }
- help_spec = {
- # Name of command or auxiliary help info for which this help applies.
- HELP_NAME : 'cat',
- # List of help name aliases.
- HELP_NAME_ALIASES : [],
- # Type of help:
- HELP_TYPE : HelpType.COMMAND_HELP,
- # One line summary of this help.
- HELP_ONE_LINE_SUMMARY : 'Concatenate object content to stdout',
- # The full help text.
- HELP_TEXT : _detailed_help_text,
- }
+ # Command specification. See base class for documentation.
+ command_spec = Command.CreateCommandSpec(
+ 'cat',
+ command_name_aliases=[],
+ min_args=0,
+ max_args=NO_MAX,
+ supported_sub_args='hr:',
+ file_url_ok=False,
+ provider_url_ok=False,
+ urls_start_arg=0,
+ gs_api_support=[ApiSelector.XML, ApiSelector.JSON],
+ gs_default_api=ApiSelector.JSON,
+ )
+ # Help specification. See help_provider.py for documentation.
+ help_spec = Command.HelpSpec(
+ help_name='cat',
+ help_name_aliases=[],
+ help_type='command_help',
+ help_one_line_summary='Concatenate object content to stdout',
+ help_text=_DETAILED_HELP_TEXT,
+ subcommand_help_text={},
+ )
- def _UriIterator(self, uri_str):
- # Generator that returns URI(s) for uri_str. If uri_str is a wildcard we
- # iterate over matches, else we return a single URI.
- if not ContainsWildcard(uri_str):
- yield self.suri_builder.StorageUri(uri_str)
- else:
- for uri in self.WildcardIterator(uri_str).IterUris():
- yield uri
-
# Command entry point.
def RunCommand(self):
+ """Command entry point for the cat command."""
show_header = False
request_range = None
+ start_byte = 0
+ end_byte = None
if self.sub_opts:
for o, a in self.sub_opts:
if o == '-h':
show_header = True
elif o == '-r':
request_range = a.strip()
- if not re.match('^[0-9]+-[0-9]*$|^-[0-9]+$', request_range):
+ range_matcher = re.compile(
+ '^(?P<start>[0-9]+)-(?P<end>[0-9]*)$|^(?P<endslice>-[0-9]+)$')
+ range_match = range_matcher.match(request_range)
+ if not range_match:
raise CommandException('Invalid range (%s)' % request_range)
- elif o == '-v':
- self.logger.info('WARNING: The %s -v option is no longer'
- ' needed, and will eventually be removed.\n'
- % self.command_name)
+ if range_match.group('start'):
+ start_byte = long(range_match.group('start'))
+ if range_match.group('end'):
+ end_byte = long(range_match.group('end'))
+ if range_match.group('endslice'):
+ start_byte = long(range_match.group('endslice'))
- printed_one = False
- # We manipulate the stdout so that all other data other than the Object
- # contents go to stderr.
- cat_outfd = sys.stdout
- sys.stdout = sys.stderr
- did_some_work = False
-
- for uri_str in self.args:
- for uri in self._UriIterator(uri_str):
- if not uri.names_object():
- raise CommandException('"%s" command must specify objects.' %
- self.command_name)
- did_some_work = True
- if show_header:
- if printed_one:
- print
- print '==> %s <==' % uri.__str__()
- printed_one = True
- key = uri.get_key(False, self.headers)
- headers = self.headers.copy()
- if request_range:
- headers['range'] = 'bytes=%s' % str(request_range)
- key.get_file(cat_outfd, headers)
- sys.stdout = cat_outfd
- if not did_some_work:
- raise CommandException('No URIs matched')
-
- return 0
+ return CatHelper(self).CatUrlStrings(self.args,
+ show_header=show_header,
+ start_byte=start_byte,
+ end_byte=end_byte)
« no previous file with comments | « gslib/commands/acl.py ('k') | gslib/commands/compose.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698