
    [                        d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 dd	lmZ d
ZdZdZej                   ej                   ej"                  j$                         G d dej&                                      Zej                   ej                   ej"                  j*                         G d de                    Zy)zCImplementation of Unix-like mv command for cloud storage providers.    )absolute_import)division)unicode_literals)base)cp_command_util)errors)flags)storage_urla  
The mv command allows you to move data between your local file system and
the cloud, move data within the cloud, and move data between cloud storage
providers.

*Renaming Groups Of Objects*

You can use the mv command to rename all objects with a given prefix to
have a new prefix. For example, the following command renames all objects
under gs://my_bucket/oldprefix to be under gs://my_bucket/newprefix,
otherwise preserving the naming structure:

  $ {command} gs://my_bucket/oldprefix gs://my_bucket/newprefix

Note that when using mv to rename groups of objects with a common prefix,
you cannot specify the source URL using wildcards; you must spell out the
complete name.

If you do a rename as specified above and you want to preserve ACLs.

*Non-Atomic Operation*

Unlike the case with many file systems, the mv command does not perform a
single atomic operation. Rather, it performs a copy from source to
destination followed by removing the source for each object.

A consequence of this is that, in addition to normal network and operation
charges, if you move a Nearline Storage, Coldline Storage, or Archive
Storage object, deletion and data retrieval charges apply.
See the documentation for pricing details.
a  
To move all objects from a bucket to a local directory you could use:

  $ {command} gs://my_bucket/* dir

Similarly, to move all objects from a local directory to a bucket you
could use:

  $ {command} ./dir gs://my_bucket

The following command renames all objects under gs://my_bucket/oldprefix
to be under gs://my_bucket/newprefix, otherwise preserving the naming
structure:

  $ {command} gs://my_bucket/oldprefix gs://my_bucket/newprefix

c                   0    e Zd ZdZeedZed        Zd Z	y)MvMoves or renames objects.DESCRIPTIONEXAMPLESc                 v    t        j                  || j                                t        j                  |       y )N)r   add_cp_and_mv_flagsReleaseTrackr	   add_per_object_retention_flags)clsparsers     lib/surface/storage/mv.pyArgszMv.ArgsX   s)    ''0@0@0BC	((0    c                 V   |j                   D ]w  }t        j                  |      }t        |t        j                        r%|j                         st        j                  d      |j                  sdt        j                  d       d|_	        t        j                  |d      | _        y )NzCannot mv buckets.zCannot mv stdin.T)delete_source)sourcer
   storage_url_from_string
isinstanceCloudUrl	is_objectr   InvalidUrlErroris_stdio	recursiver   run_cp	exit_code)selfargs
url_stringurls       r   RunzMv.Run]   s    kk
//
;c	C--	.s}}$$%9::	$$%788 " DN$++DEDNr   N)
__name__
__module____qualname____doc___COMMAND_DESCRIPTION_GA_EXAMPLESdetailed_helpclassmethodr   r+    r   r   r   r   N   s0     " *-
 1 1
Fr   r   c                        e Zd ZdZeeez   dZy)MvAlphar   r   N)r,   r-   r.   r/   r0   r1   _ALPHA_EXAMPLESr2   r4   r   r   r6   r6   j   s     " *0-r   r6   N)r/   
__future__r   r   r   googlecloudsdk.callioper   "googlecloudsdk.command_lib.storager   r   r	   r
   r0   r1   r7   UniverseCompatibleReleaseTracksr   GACommandr   ALPHAr6   r4   r   r   <module>r@      s    J &  ' ( > 5 4 : >  D%%(()F F * F4 D%%++,b  - r   