| OLD | NEW |
| (Empty) | |
| 1 # Copyright 2011 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.help_provider import HELP_NAME |
| 26 from gslib.help_provider import HELP_NAME_ALIASES |
| 27 from gslib.help_provider import HELP_ONE_LINE_SUMMARY |
| 28 from gslib.help_provider import HELP_TEXT |
| 29 from gslib.help_provider import HelpType |
| 30 from gslib.help_provider import HELP_TYPE |
| 31 from gslib.util import NO_MAX |
| 32 |
| 33 _detailed_help_text = (""" |
| 34 <B>SYNOPSIS</B> |
| 35 gsutil mb [-l location] [-p proj_id] uri... |
| 36 |
| 37 |
| 38 <B>DESCRIPTION</B> |
| 39 The mb command creates a new bucket. Google Cloud Storage has a single |
| 40 namespace, so you will not be allowed to create a bucket with a name already |
| 41 in use by another user. You can, however, carve out parts of the bucket name |
| 42 space corresponding to your company's domain name (see "gsutil help naming"). |
| 43 |
| 44 If you specify a location for the bucket (using the -l option), the |
| 45 bucket will be created in the named geographic location. Once created in |
| 46 a location, a bucket cannot be moved to a different location; you would |
| 47 instead need to create a new bucket and move the data over and then delete |
| 48 the original bucket. |
| 49 |
| 50 If you don't specify a project ID using the -p option, the bucket |
| 51 will be created using the default project ID specified in your gsutil |
| 52 configuration file (see "gsutil help config"). For more details about |
| 53 projects see "gsutil help projects". |
| 54 |
| 55 |
| 56 <B>OPTIONS</B> |
| 57 -l location Can be us or eu. Default is us. |
| 58 |
| 59 -p proj_id Specifies the project ID under which to create the bucket. |
| 60 """) |
| 61 |
| 62 |
| 63 class MbCommand(Command): |
| 64 """Implementation of gsutil mb command.""" |
| 65 |
| 66 # Command specification (processed by parent class). |
| 67 command_spec = { |
| 68 # Name of command. |
| 69 COMMAND_NAME : 'mb', |
| 70 # List of command name aliases. |
| 71 COMMAND_NAME_ALIASES : ['makebucket', 'createbucket', 'md', 'mkdir'], |
| 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 : NO_MAX, |
| 76 # Getopt-style string specifying acceptable sub args. |
| 77 SUPPORTED_SUB_ARGS : 'l:p:', |
| 78 # True if file URIs acceptable for this command. |
| 79 FILE_URIS_OK : False, |
| 80 # True if provider-only URIs acceptable for this command. |
| 81 PROVIDER_URIS_OK : False, |
| 82 # Index in args of first URI arg. |
| 83 URIS_START_ARG : 0, |
| 84 # True if must configure gsutil before running command. |
| 85 CONFIG_REQUIRED : True, |
| 86 } |
| 87 help_spec = { |
| 88 # Name of command or auxiliary help info for which this help applies. |
| 89 HELP_NAME : 'mb', |
| 90 # List of help name aliases. |
| 91 HELP_NAME_ALIASES : ['makebucket', 'createbucket', 'md', 'mkdir'], |
| 92 # Type of help: |
| 93 HELP_TYPE : HelpType.COMMAND_HELP, |
| 94 # One line summary of this help. |
| 95 HELP_ONE_LINE_SUMMARY : 'Make buckets', |
| 96 # The full help text. |
| 97 HELP_TEXT : _detailed_help_text, |
| 98 } |
| 99 |
| 100 # Command entry point. |
| 101 def RunCommand(self): |
| 102 location = '' |
| 103 if self.sub_opts: |
| 104 for o, a in self.sub_opts: |
| 105 if o == '-l': |
| 106 location = a |
| 107 elif o == '-p': |
| 108 self.proj_id_handler.SetProjectId(a) |
| 109 |
| 110 if not self.headers: |
| 111 headers = {} |
| 112 else: |
| 113 headers = self.headers.copy() |
| 114 |
| 115 for bucket_uri_str in self.args: |
| 116 bucket_uri = self.suri_builder.StorageUri(bucket_uri_str) |
| 117 self.proj_id_handler.FillInProjectHeaderIfNeeded('mb', bucket_uri, |
| 118 headers) |
| 119 print 'Creating %s...' % bucket_uri |
| 120 bucket_uri.create_bucket(headers=headers, location=location) |
| 121 |
| OLD | NEW |