<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> from gslib . command import Command <EOL> from gslib . command_argument import CommandArgument <EOL> from gslib . cs_api_map import ApiSelector <EOL> from gslib . exception import CommandException <EOL> from gslib . exception import NO_URLS_MATCHED_TARGET <EOL> from gslib . help_provider import CreateHelpText <EOL> from gslib . third_party . storage_apitools import storage_v1_messages as apitools_messages <EOL> from gslib . util import NO_MAX <EOL> _SET_SYNOPSIS = """<STR_LIT>""" <EOL> _GET_SYNOPSIS = """<STR_LIT>""" <EOL> _SYNOPSIS = _SET_SYNOPSIS + _GET_SYNOPSIS . lstrip ( '<STR_LIT:\n>' ) <EOL> _SET_DESCRIPTION = """<STR_LIT>""" <EOL> _GET_DESCRIPTION = """<STR_LIT>""" <EOL> _DESCRIPTION = """<STR_LIT>""" + _SET_DESCRIPTION + _GET_DESCRIPTION <EOL> _DETAILED_HELP_TEXT = CreateHelpText ( _SYNOPSIS , _DESCRIPTION ) <EOL> _get_help_text = CreateHelpText ( _GET_SYNOPSIS , _GET_DESCRIPTION ) <EOL> _set_help_text = CreateHelpText ( _SET_SYNOPSIS , _SET_DESCRIPTION ) <EOL> class VersioningCommand ( Command ) : <EOL> """<STR_LIT>""" <EOL> command_spec = Command . CreateCommandSpec ( <EOL> '<STR_LIT>' , <EOL> command_name_aliases = [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> usage_synopsis = _SYNOPSIS , <EOL> min_args = <NUM_LIT:2> , <EOL> max_args = NO_MAX , <EOL> supported_sub_args = '<STR_LIT>' , <EOL> file_url_ok = False , <EOL> provider_url_ok = False , <EOL> urls_start_arg = <NUM_LIT:2> , <EOL> gs_api_support = [ ApiSelector . XML , ApiSelector . JSON ] , <EOL> gs_default_api = ApiSelector . JSON , <EOL> argparse_arguments = { <EOL> '<STR_LIT>' : [ <EOL> CommandArgument ( '<STR_LIT>' , choices = [ '<STR_LIT>' , '<STR_LIT>' ] ) , <EOL> CommandArgument . MakeZeroOrMoreCloudBucketURLsArgument ( ) <EOL> ] , <EOL> '<STR_LIT>' : [ <EOL> CommandArgument . MakeZeroOrMoreCloudBucketURLsArgument ( ) <EOL> ] <EOL> } <EOL> ) <EOL> help_spec = Command . HelpSpec ( <EOL> help_name = '<STR_LIT>' , <EOL> help_name_aliases = [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> help_type = '<STR_LIT>' , <EOL> help_one_line_summary = ( <EOL> '<STR_LIT>' ) , <EOL> help_text = _DETAILED_HELP_TEXT , <EOL> subcommand_help_text = { '<STR_LIT>' : _get_help_text , '<STR_LIT>' : _set_help_text } , <EOL> ) <EOL> def _CalculateUrlsStartArg ( self ) : <EOL> if not self . args : <EOL> self . RaiseWrongNumberOfArgumentsException ( ) <EOL> if self . args [ <NUM_LIT:0> ] . lower ( ) == '<STR_LIT>' : <EOL> return <NUM_LIT:2> <EOL> else : <EOL> return <NUM_LIT:1> <EOL> def _SetVersioning ( self ) : <EOL> """<STR_LIT>""" <EOL> versioning_arg = self . args [ <NUM_LIT:0> ] . lower ( ) <EOL> if versioning_arg not in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> raise CommandException ( '<STR_LIT>' <EOL> % ( self . command_name ) ) <EOL> url_args = self . args [ <NUM_LIT:1> : ] <EOL> if not url_args : <EOL> self . RaiseWrongNumberOfArgumentsException ( ) <EOL> some_matched = False <EOL> for url_str in url_args : <EOL> bucket_iter = self . GetBucketUrlIterFromArg ( url_str , bucket_fields = [ '<STR_LIT:id>' ] ) <EOL> for blr in bucket_iter : <EOL> url = blr . storage_url <EOL> some_matched = True <EOL> bucket_metadata = apitools_messages . Bucket ( <EOL> versioning = apitools_messages . Bucket . VersioningValue ( ) ) <EOL> if versioning_arg == '<STR_LIT>' : <EOL> self . logger . info ( '<STR_LIT>' , url ) <EOL> bucket_metadata . versioning . enabled = True <EOL> else : <EOL> self . logger . info ( '<STR_LIT>' , url ) <EOL> bucket_metadata . versioning . enabled = False <EOL> self . gsutil_api . PatchBucket ( url . bucket_name , bucket_metadata , <EOL> provider = url . scheme , fields = [ '<STR_LIT:id>' ] ) <EOL> if not some_matched : <EOL> raise CommandException ( NO_URLS_MATCHED_TARGET % list ( url_args ) ) <EOL> def _GetVersioning ( self ) : <EOL> """<STR_LIT>""" <EOL> url_args = self . args <EOL> some_matched = False <EOL> for url_str in url_args : <EOL> bucket_iter = self . GetBucketUrlIterFromArg ( url_str , <EOL> bucket_fields = [ '<STR_LIT>' ] ) <EOL> for blr in bucket_iter : <EOL> some_matched = True <EOL> if blr . root_object . versioning and blr . root_object . versioning . enabled : <EOL> print '<STR_LIT>' % blr . url_string . rstrip ( '<STR_LIT:/>' ) <EOL> else : <EOL> print '<STR_LIT>' % blr . url_string . rstrip ( '<STR_LIT:/>' ) <EOL> if not some_matched : <EOL> raise CommandException ( NO_URLS_MATCHED_TARGET % list ( url_args ) ) <EOL> def RunCommand ( self ) : <EOL> """<STR_LIT>""" <EOL> action_subcommand = self . args . pop ( <NUM_LIT:0> ) <EOL> if action_subcommand == '<STR_LIT>' : <EOL> func = self . _GetVersioning <EOL> elif action_subcommand == '<STR_LIT>' : <EOL> func = self . _SetVersioning <EOL> else : <EOL> raise CommandException ( ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) % ( <EOL> action_subcommand , self . command_name , self . command_name ) ) <EOL> func ( ) <EOL> return <NUM_LIT:0> </s>
