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

Unified Diff: gslib/commands/versioning.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/version.py ('k') | gslib/commands/web.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gslib/commands/versioning.py
===================================================================
--- gslib/commands/versioning.py (revision 33376)
+++ gslib/commands/versioning.py (working copy)
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
# Copyright 2012 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -11,34 +12,24 @@
# 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 versioning configuration command for buckets."""
+from __future__ import absolute_import
+
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 CreateHelpText
-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.help_provider import SUBCOMMAND_HELP_TEXT
+from gslib.third_party.storage_apitools import storage_v1_messages as apitools_messages
from gslib.util import NO_MAX
_SET_SYNOPSIS = """
- gsutil versioning set [on|off] bucket_uri...
+ gsutil versioning set [on|off] bucket_url...
"""
_GET_SYNOPSIS = """
- gsutil versioning get bucket_uri
+ gsutil versioning get bucket_url...
"""
_SYNOPSIS = _SET_SYNOPSIS + _GET_SYNOPSIS.lstrip('\n')
@@ -54,17 +45,7 @@
_GET_DESCRIPTION = """
<B>GET</B>
The "get" sub-command gets the versioning configuration for a
- bucket and displays an XML representation of the configuration.
-
- In Google Cloud Storage, this would look like:
-
- <?xml version="1.0" ?>
- <VersioningConfiguration>
- <Status>
- Enabled
- </Status>
- </VersioningConfiguration>
-
+ bucket and displays whether or not it is enabled.
"""
_DESCRIPTION = """
@@ -74,109 +55,99 @@
The gsutil versioning command has two sub-commands:
""" + _SET_DESCRIPTION + _GET_DESCRIPTION
-_detailed_help_text = CreateHelpText(_SYNOPSIS, _DESCRIPTION)
+_DETAILED_HELP_TEXT = CreateHelpText(_SYNOPSIS, _DESCRIPTION)
_get_help_text = CreateHelpText(_GET_SYNOPSIS, _GET_DESCRIPTION)
_set_help_text = CreateHelpText(_SET_SYNOPSIS, _SET_DESCRIPTION)
+
class VersioningCommand(Command):
"""Implementation of gsutil versioning command."""
- # Command specification (processed by parent class).
- command_spec = {
- # Name of command.
- COMMAND_NAME : 'versioning',
- # List of command name aliases.
- COMMAND_NAME_ALIASES : ['setversioning', 'getversioning'],
- # Min number of args required by this command.
- MIN_ARGS : 2,
- # 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 : '',
- # 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 : 2,
- }
- help_spec = {
- # Name of command or auxiliary help info for which this help applies.
- HELP_NAME : 'versioning',
- # List of help name aliases.
- HELP_NAME_ALIASES : ['getversioning', 'setversioning'],
- # Type of help)
- HELP_TYPE : HelpType.COMMAND_HELP,
- # One line summary of this help.
- HELP_ONE_LINE_SUMMARY : 'Enable or suspend versioning for one or more '
- 'buckets',
- # The full help text.
- HELP_TEXT : _detailed_help_text,
- # Help text for sub-commands.
- SUBCOMMAND_HELP_TEXT : {'get' : _get_help_text,
- 'set' : _set_help_text},
- }
+ # Command specification. See base class for documentation.
+ command_spec = Command.CreateCommandSpec(
+ 'versioning',
+ command_name_aliases=['setversioning', 'getversioning'],
+ min_args=2,
+ max_args=NO_MAX,
+ supported_sub_args='',
+ file_url_ok=False,
+ provider_url_ok=False,
+ urls_start_arg=2,
+ 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='versioning',
+ help_name_aliases=['getversioning', 'setversioning'],
+ help_type='command_help',
+ help_one_line_summary=(
+ 'Enable or suspend versioning for one or more buckets'),
+ help_text=_DETAILED_HELP_TEXT,
+ subcommand_help_text={'get': _get_help_text, 'set': _set_help_text},
+ )
- def _CalculateUrisStartArg(self):
+ def _CalculateUrlsStartArg(self):
if not self.args:
self._RaiseWrongNumberOfArgumentsException()
- if (self.args[0].lower() == 'set'):
+ if self.args[0].lower() == 'set':
return 2
else:
return 1
def _SetVersioning(self):
+ """Gets versioning configuration for a bucket."""
versioning_arg = self.args[0].lower()
- if not versioning_arg in ('on', 'off'):
+ if versioning_arg not in ('on', 'off'):
raise CommandException('Argument to "%s set" must be either [on|off]'
% (self.command_name))
- uri_args = self.args[1:]
- if len(uri_args) == 0:
+ url_args = self.args[1:]
+ if not url_args:
self._RaiseWrongNumberOfArgumentsException()
- # Iterate over URIs, expanding wildcards, and setting the website
+ # Iterate over URLs, expanding wildcards and set the versioning
# configuration on each.
some_matched = False
- for uri_str in uri_args:
- for blr in self.WildcardIterator(uri_str):
- uri = blr.GetUri()
- if not uri.names_bucket():
- raise CommandException('URI %s must name a bucket for the %s command'
- % (str(uri), self.command_name))
+ for url_str in url_args:
+ bucket_iter = self.GetBucketUrlIterFromArg(url_str, bucket_fields=['id'])
+ for blr in bucket_iter:
+ url = blr.storage_url
some_matched = True
+ bucket_metadata = apitools_messages.Bucket(
+ versioning=apitools_messages.Bucket.VersioningValue())
if versioning_arg == 'on':
- self.logger.info('Enabling versioning for %s...', uri)
- uri.configure_versioning(True)
+ self.logger.info('Enabling versioning for %s...', url)
+ bucket_metadata.versioning.enabled = True
else:
- self.logger.info('Suspending versioning for %s...', uri)
- uri.configure_versioning(False)
+ self.logger.info('Suspending versioning for %s...', url)
+ bucket_metadata.versioning.enabled = False
+ self.gsutil_api.PatchBucket(url.bucket_name, bucket_metadata,
+ provider=url.scheme, fields=['id'])
if not some_matched:
- raise CommandException('No URIs matched')
-
+ raise CommandException('No URLs matched')
+
def _GetVersioning(self):
- uri_args = self.args
+ """Gets versioning configuration for one or more buckets."""
+ url_args = self.args
- # Iterate over URIs, expanding wildcards, and getting the website
+ # Iterate over URLs, expanding wildcards and getting the versioning
# configuration on each.
some_matched = False
- for uri_str in uri_args:
- for blr in self.WildcardIterator(uri_str):
- uri = blr.GetUri()
- if not uri.names_bucket():
- raise CommandException('URI %s must name a bucket for the %s command'
- % (str(uri), self.command_name))
+ for url_str in url_args:
+ bucket_iter = self.GetBucketUrlIterFromArg(url_str,
+ bucket_fields=['versioning'])
+ for blr in bucket_iter:
some_matched = True
- uri_str = '%s://%s' % (uri.scheme, uri.bucket_name)
- if uri.get_versioning_config():
- print '%s: Enabled' % uri_str
+ if blr.root_object.versioning and blr.root_object.versioning.enabled:
+ print '%s: Enabled' % blr.url_string.rstrip('/')
else:
- print '%s: Suspended' % uri_str
+ print '%s: Suspended' % blr.url_string.rstrip('/')
if not some_matched:
- raise CommandException('No URIs matched')
+ raise CommandException('No URLs matched')
- # Command entry point.
def RunCommand(self):
+ """Command entry point for the versioning command."""
action_subcommand = self.args.pop(0)
if action_subcommand == 'get':
func = self._GetVersioning
@@ -185,7 +156,7 @@
else:
raise CommandException((
'Invalid subcommand "%s" for the %s command.\n'
- 'See "gsutil help %s".') %
- (action_subcommand, self.command_name, self.command_name))
+ 'See "gsutil help %s".') % (
+ action_subcommand, self.command_name, self.command_name))
func()
return 0
« no previous file with comments | « gslib/commands/version.py ('k') | gslib/commands/web.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698