OLD | NEW |
| (Empty) |
1 # Copyright 2012 Google Inc. All Rights Reserved. | |
2 # | |
3 # Licensed under the Apache License, Version 2.0 (the "License"); | |
4 # you may not use this file except in compliance with the License. | |
5 # You may obtain a copy of the License at | |
6 # | |
7 # http://www.apache.org/licenses/LICENSE-2.0 | |
8 # | |
9 # Unless required by applicable law or agreed to in writing, software | |
10 # distributed under the License is distributed on an "AS IS" BASIS, | |
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 # See the License for the specific language governing permissions and | |
13 # limitations under the License. | |
14 | |
15 from gslib.command import Command | |
16 from gslib.command import COMMAND_NAME | |
17 from gslib.command import COMMAND_NAME_ALIASES | |
18 from gslib.command import CONFIG_REQUIRED | |
19 from gslib.command import FILE_URIS_OK | |
20 from gslib.command import MAX_ARGS | |
21 from gslib.command import MIN_ARGS | |
22 from gslib.command import PROVIDER_URIS_OK | |
23 from gslib.command import SUPPORTED_SUB_ARGS | |
24 from gslib.command import URIS_START_ARG | |
25 from gslib.exception import CommandException | |
26 from gslib.help_provider import HELP_NAME | |
27 from gslib.help_provider import HELP_NAME_ALIASES | |
28 from gslib.help_provider import HELP_ONE_LINE_SUMMARY | |
29 from gslib.help_provider import HELP_TEXT | |
30 from gslib.help_provider import HelpType | |
31 from gslib.help_provider import HELP_TYPE | |
32 from gslib.util import NO_MAX | |
33 | |
34 | |
35 _detailed_help_text = (""" | |
36 <B>SYNOPSIS</B> | |
37 gsutil setversioning [on|off] bucket_uri... | |
38 | |
39 | |
40 <B>DESCRIPTION</B> | |
41 The Versioning Configuration feature enables you to configure a Google Cloud | |
42 Storage bucket to keep old versions of objects. | |
43 | |
44 The gsutil setversioning command allows you to enable or suspend versioning | |
45 on one or more buckets. | |
46 """) | |
47 | |
48 class SetVersioningCommand(Command): | |
49 """Implementation of gsutil setversioning command.""" | |
50 | |
51 # Command specification (processed by parent class). | |
52 command_spec = { | |
53 # Name of command. | |
54 COMMAND_NAME : 'setversioning', | |
55 # List of command name aliases. | |
56 COMMAND_NAME_ALIASES : [], | |
57 # Min number of args required by this command. | |
58 MIN_ARGS : 1, | |
59 # Max number of args required by this command, or NO_MAX. | |
60 MAX_ARGS : NO_MAX, | |
61 # Getopt-style string specifying acceptable sub args. | |
62 SUPPORTED_SUB_ARGS : '', | |
63 # True if file URIs acceptable for this command. | |
64 FILE_URIS_OK : False, | |
65 # True if provider-only URIs acceptable for this command. | |
66 PROVIDER_URIS_OK : False, | |
67 # Index in args of first URI arg. | |
68 URIS_START_ARG : 1, | |
69 # True if must configure gsutil before running command. | |
70 CONFIG_REQUIRED : True, | |
71 } | |
72 help_spec = { | |
73 # Name of command or auxiliary help info for which this help applies. | |
74 HELP_NAME : 'setversioning', | |
75 # List of help name aliases. | |
76 HELP_NAME_ALIASES : [], | |
77 # Type of help) | |
78 HELP_TYPE : HelpType.COMMAND_HELP, | |
79 # One line summary of this help. | |
80 HELP_ONE_LINE_SUMMARY : 'Enable or suspend versioning for one or more ' | |
81 'buckets', | |
82 # The full help text. | |
83 HELP_TEXT : _detailed_help_text, | |
84 } | |
85 | |
86 | |
87 # Command entry point. | |
88 def RunCommand(self): | |
89 versioning_arg = self.args[0].lower() | |
90 if not versioning_arg in ('on', 'off'): | |
91 raise CommandException('Argument to %s must be either [on|off]' | |
92 % (self.command_name)) | |
93 uri_args = self.args[1:] | |
94 | |
95 # Iterate over URIs, expanding wildcards, and setting the website | |
96 # configuration on each. | |
97 some_matched = False | |
98 for uri_str in uri_args: | |
99 for blr in self.WildcardIterator(uri_str): | |
100 uri = blr.GetUri() | |
101 if not uri.names_bucket(): | |
102 raise CommandException('URI %s must name a bucket for the %s command' | |
103 % (str(uri), self.command_name)) | |
104 some_matched = True | |
105 if versioning_arg == 'on': | |
106 print 'Enabling versioning for %s...' % uri | |
107 uri.configure_versioning(True) | |
108 else: | |
109 print 'Suspending versioning for %s...' % uri | |
110 uri.configure_versioning(False) | |
111 if not some_matched: | |
112 raise CommandException('No URIs matched') | |
113 | |
114 return 0 | |
OLD | NEW |