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

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

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

Powered by Google App Engine
This is Rietveld 408576698