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 | |
33 | |
34 _detailed_help_text = (""" | |
35 <B>SYNOPSIS</B> | |
36 gsutil getversioning bucket_uri | |
37 | |
38 | |
39 <B>DESCRIPTION</B> | |
40 The Versioning Configuration feature enables you to configure a Google Cloud | |
41 Storage bucket to keep old versions of objects. | |
42 | |
43 The gsutil getversioning command gets the versioning configuration for a | |
44 bucket, and displays an XML representation of the configuration. | |
45 | |
46 In Google Cloud Storage, this would look like: | |
47 | |
48 <?xml version="1.0" ?> | |
49 <VersioningConfiguration> | |
50 <Status> | |
51 Enabled | |
52 </Status> | |
53 </VersioningConfiguration> | |
54 """) | |
55 | |
56 class GetVersioningCommand(Command): | |
57 """Implementation of gsutil getversioning command.""" | |
58 | |
59 # Command specification (processed by parent class). | |
60 command_spec = { | |
61 # Name of command. | |
62 COMMAND_NAME : 'getversioning', | |
63 # List of command name aliases. | |
64 COMMAND_NAME_ALIASES : [], | |
65 # Min number of args required by this command. | |
66 MIN_ARGS : 1, | |
67 # Max number of args required by this command, or NO_MAX. | |
68 MAX_ARGS : 1, | |
69 # Getopt-style string specifying acceptable sub args. | |
70 SUPPORTED_SUB_ARGS : '', | |
71 # True if file URIs acceptable for this command. | |
72 FILE_URIS_OK : False, | |
73 # True if provider-only URIs acceptable for this command. | |
74 PROVIDER_URIS_OK : False, | |
75 # Index in args of first URI arg. | |
76 URIS_START_ARG : 1, | |
77 # True if must configure gsutil before running command. | |
78 CONFIG_REQUIRED : True, | |
79 } | |
80 help_spec = { | |
81 # Name of command or auxiliary help info for which this help applies. | |
82 HELP_NAME : 'getversioning', | |
83 # List of help name aliases. | |
84 HELP_NAME_ALIASES : [], | |
85 # Type of help) | |
86 HELP_TYPE : HelpType.COMMAND_HELP, | |
87 # One line summary of this help. | |
88 HELP_ONE_LINE_SUMMARY : 'Get the versioning configuration ' | |
89 'for one or more buckets', | |
90 # The full help text. | |
91 HELP_TEXT : _detailed_help_text, | |
92 } | |
93 | |
94 # Command entry point. | |
95 def RunCommand(self): | |
96 uri_args = self.args | |
97 | |
98 # Iterate over URIs, expanding wildcards, and getting the website | |
99 # configuration on each. | |
100 some_matched = False | |
101 for uri_str in uri_args: | |
102 for blr in self.WildcardIterator(uri_str): | |
103 uri = blr.GetUri() | |
104 if not uri.names_bucket(): | |
105 raise CommandException('URI %s must name a bucket for the %s command' | |
106 % (str(uri), self.command_name)) | |
107 some_matched = True | |
108 uri_str = '%s://%s' % (uri.scheme, uri.bucket_name) | |
109 if uri.get_versioning_config(): | |
110 print '%s: Enabled' % uri_str | |
111 else: | |
112 print '%s: Suspended' % uri_str | |
113 if not some_matched: | |
114 raise CommandException('No URIs matched') | |
115 | |
116 return 0 | |
OLD | NEW |