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

Side by Side Diff: third_party/gsutil/gslib/commands/getwebcfg.py

Issue 2280023003: depot_tools: Remove third_party/gsutil (Closed)
Patch Set: Created 4 years, 3 months 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 unified diff | Download patch
OLDNEW
(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 import sys
16
17 from gslib.command import Command
18 from gslib.command import COMMAND_NAME
19 from gslib.command import COMMAND_NAME_ALIASES
20 from gslib.command import CONFIG_REQUIRED
21 from gslib.command import FILE_URIS_OK
22 from gslib.command import MAX_ARGS
23 from gslib.command import MIN_ARGS
24 from gslib.command import PROVIDER_URIS_OK
25 from gslib.command import SUPPORTED_SUB_ARGS
26 from gslib.command import URIS_START_ARG
27 from gslib.exception import CommandException
28 from gslib.help_provider import HELP_NAME
29 from gslib.help_provider import HELP_NAME_ALIASES
30 from gslib.help_provider import HELP_ONE_LINE_SUMMARY
31 from gslib.help_provider import HELP_TEXT
32 from gslib.help_provider import HelpType
33 from gslib.help_provider import HELP_TYPE
34 from xml.dom.minidom import parseString as XmlParseString
35
36
37 _detailed_help_text = ("""
38 <B>SYNOPSIS</B>
39 gsutil getwebcfg bucket_uri
40
41
42 <B>DESCRIPTION</B>
43 The Website Configuration feature enables you to configure a Google Cloud
44 Storage bucket to simulate the behavior of a static website. You can define
45 main pages or directory indices (for example, index.html) for buckets and
46 "directories". Also, you can define a custom error page in case a requested
47 resource does not exist.
48
49 The gsutil getwebcfg command gets the web semantics configuration for a
50 bucket, and displays an XML representation of the configuration.
51
52 In Google Cloud Storage, this would look like:
53
54 <?xml version="1.0" ?>
55 <WebsiteConfiguration>
56 <MainPageSuffix>
57 index.html
58 </MainPageSuffix>
59 <NotFoundPage>
60 404.html
61 </NotFoundPage>
62 </WebsiteConfiguration>
63 """)
64
65 class GetWebcfgCommand(Command):
66 """Implementation of gsutil getwebcfg command."""
67
68 # Command specification (processed by parent class).
69 command_spec = {
70 # Name of command.
71 COMMAND_NAME : 'getwebcfg',
72 # List of command name aliases.
73 COMMAND_NAME_ALIASES : [],
74 # Min number of args required by this command.
75 MIN_ARGS : 1,
76 # Max number of args required by this command, or NO_MAX.
77 MAX_ARGS : 1, # Getopt-style string specifying acceptable sub args.
78 SUPPORTED_SUB_ARGS : '',
79 # True if file URIs acceptable for this command.
80 FILE_URIS_OK : False,
81 # True if provider-only URIs acceptable for this command.
82 PROVIDER_URIS_OK : False,
83 # Index in args of first URI arg.
84 URIS_START_ARG : 1,
85 # True if must configure gsutil before running command.
86 CONFIG_REQUIRED : True,
87 }
88 help_spec = {
89 # Name of command or auxiliary help info for which this help applies.
90 HELP_NAME : 'getwebcfg',
91 # List of help name aliases.
92 HELP_NAME_ALIASES : [],
93 # Type of help)
94 HELP_TYPE : HelpType.COMMAND_HELP,
95 # One line summary of this help.
96 HELP_ONE_LINE_SUMMARY : ('Get the website configuration '
97 'for one or more buckets'),
98 # The full help text.
99 HELP_TEXT : _detailed_help_text,
100 }
101
102 # Command entry point.
103 def RunCommand(self):
104 uri_args = self.args
105
106 # Iterate over URIs, expanding wildcards, and getting the website
107 # configuration on each.
108 some_matched = False
109 for uri_str in uri_args:
110 for blr in self.WildcardIterator(uri_str):
111 uri = blr.GetUri()
112 if not uri.names_bucket():
113 raise CommandException('URI %s must name a bucket for the %s command'
114 % (str(uri), self.command_name))
115 some_matched = True
116 sys.stderr.write('Getting website config on %s...\n' % uri)
117 _, xml_body = uri.get_website_config()
118 sys.stdout.write(XmlParseString(xml_body).toprettyxml())
119 if not some_matched:
120 raise CommandException('No URIs matched')
121
122 return 0
OLDNEW
« no previous file with comments | « third_party/gsutil/gslib/commands/getversioning.py ('k') | third_party/gsutil/gslib/commands/help.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698