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

Side by Side Diff: third_party/gsutil/gslib/commands/mv.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
« no previous file with comments | « third_party/gsutil/gslib/commands/mb.py ('k') | third_party/gsutil/gslib/commands/perfdiag.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2011 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 _detailed_help_text = ("""
35 <B>SYNOPSIS</B>
36 gsutil mv [-p] src_uri dst_uri
37 - or -
38 gsutil mv [-p] uri... dst_uri
39
40
41 <B>DESCRIPTION</B>
42 The gsutil mv command allows you to move data between your local file
43 system and the cloud, move data within the cloud, and move data between
44 cloud storage providers. For example, to move all objects from a
45 bucket to a local directory you could use:
46
47 gsutil mv gs://my_bucket dir
48
49 Similarly, to move all objects from a local directory to a bucket you could
50 use:
51
52 gsutil mv ./dir gs://my_bucket
53
54
55 <B>RENAMING BUCKET SUBDIRECTORIES</B>
56 You can use the gsutil mv command to rename subdirectories. For example,
57 the command:
58
59 gsutil mv gs://my_bucket/olddir gs://my_bucket/newdir
60
61 would rename all objects and subdirectories under gs://my_bucket/olddir to be
62 under gs://my_bucket/newdir, otherwise preserving the subdirectory structure.
63
64 If you do a rename as specified above and you want to preserve ACLs, you
65 should use the -p option (see OPTIONS).
66
67 Note that when using mv to rename bucket subdirectories you cannot specify
68 the source URI using wildcards. You need to spell out the complete name:
69
70 gsutil mv gs://my_bucket/olddir gs://my_bucket/newdir
71
72 If you have a large number of files to move you might want to use the
73 gsutil -m option, to perform a multi-threaded/multi-processing move:
74
75 gsutil -m mv gs://my_bucket/olddir gs://my_bucket/newdir
76
77
78 <B>NON-ATOMIC OPERATION</B>
79 Unlike the case with many file systems, the gsutil mv command does not
80 perform a single atomic operation. Rather, it performs a copy from source
81 to destination followed by removing the source for each object.
82
83
84 <B>OPTIONS</B>
85 -p Causes ACL to be preserved when moving in the cloud. Note that
86 this option has performance and cost implications, because it
87 is essentially performing three requests (getacl, cp, setacl).
88 (The performance issue can be mitigated to some degree by
89 using gsutil -m cp to cause multi-threaded/multi-processing
90 copying.)
91 """)
92
93
94 class MvCommand(Command):
95 """Implementation of gsutil mv command.
96 Note that there is no atomic rename operation - this command is simply
97 a shorthand for 'cp' followed by 'rm'.
98 """
99
100 # Command specification (processed by parent class).
101 command_spec = {
102 # Name of command.
103 COMMAND_NAME : 'mv',
104 # List of command name aliases.
105 COMMAND_NAME_ALIASES : ['move', 'ren', 'rename'],
106 # Min number of args required by this command.
107 MIN_ARGS : 2,
108 # Max number of args required by this command, or NO_MAX.
109 MAX_ARGS : NO_MAX,
110 # Getopt-style string specifying acceptable sub args.
111 SUPPORTED_SUB_ARGS : 'pv',
112 # True if file URIs acceptable for this command.
113 FILE_URIS_OK : True,
114 # True if provider-only URIs acceptable for this command.
115 PROVIDER_URIS_OK : False,
116 # Index in args of first URI arg.
117 URIS_START_ARG : 0,
118 # True if must configure gsutil before running command.
119 CONFIG_REQUIRED : True,
120 }
121 help_spec = {
122 # Name of command or auxiliary help info for which this help applies.
123 HELP_NAME : 'mv',
124 # List of help name aliases.
125 HELP_NAME_ALIASES : ['move', 'rename'],
126 # Type of help:
127 HELP_TYPE : HelpType.COMMAND_HELP,
128 # One line summary of this help.
129 HELP_ONE_LINE_SUMMARY : 'Move/rename objects and/or subdirectories',
130 # The full help text.
131 HELP_TEXT : _detailed_help_text,
132 }
133
134 # Command entry point.
135 def RunCommand(self):
136 # Check each source arg up, refusing to delete a bucket src URI (force users
137 # to explicitly do that as a separate operation).
138 for arg_to_check in self.args[0:-1]:
139 if self.suri_builder.StorageUri(arg_to_check).names_bucket():
140 raise CommandException('You cannot move a source bucket using the mv '
141 'command. If you meant to move\nall objects in '
142 'the bucket, you can use a command like:\n'
143 '\tgsutil mv %s/* %s' %
144 (arg_to_check, self.args[-1]))
145
146 # Insert command-line opts in front of args so they'll be picked up by cp
147 # and rm commands (e.g., for -p option). Use undocumented (internal
148 # use-only) cp -M option, which causes each original object to be deleted
149 # after successfully copying to its destination, and also causes naming
150 # behavior consistent with Unix mv naming behavior (see comments in
151 # _ConstructDstUri in cp.py).
152 unparsed_args = ['-M']
153 if self.recursion_requested:
154 unparsed_args.append('-R')
155 unparsed_args.extend(self.unparsed_args)
156 self.command_runner.RunNamedCommand('cp', unparsed_args, self.headers,
157 self.debug, self.parallel_operations)
158
159 return 0
OLDNEW
« no previous file with comments | « third_party/gsutil/gslib/commands/mb.py ('k') | third_party/gsutil/gslib/commands/perfdiag.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698