
    F                     b   S r SSKJr  SSKJr  SSKJr  SSKJr  SSKrSSKrSSKrSSK	r	SSK
r
SSKrSSKrSSKrSSKJr  SSKrSSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSK J!r!  SSK"J#r#  SSK$J%r%  SSK$J&r&  SSK$J'r'  Sr(S\(-   S\'" 5       -  -   r) " S S\5      r*g)z5Implementation of update command for updating gsutil.    )absolute_import)print_function)division)unicode_literalsN)input)Command)ApiSelector)CommandException)'CheckAndMaybePromptForAnalyticsEnabling)RegisterSignalHandler)system_util)GetConfigFilePaths)CERTIFICATE_VALIDATION_ENABLED)RELEASE_NOTES_URL)CompareVersions)DisallowUpdateIfDataInGsutilDir)LookUpGsutilVersion)GsutilPubTarballz!
  gsutil update [-f] [-n] [url]
z
<B>SYNOPSIS</B>
a	  


<B>DESCRIPTION</B>
  NOTE: This command is not available if you're using a gsutil installation
  from a package manager or the Cloud SDK. When using the Cloud SDK, use
  ``gcloud components update``.

  The gsutil update command downloads the latest gsutil release, checks its
  version, and offers to let you update to it if it differs from the version
  you're currently running.

  Once you say "Y" to the prompt of whether to install the update, the gsutil
  update command locates where the running copy of gsutil is installed,
  unpacks the new version into an adjacent directory, moves the previous version
  aside, moves the new version to where the previous version was installed,
  and removes the moved-aside old version. Because of this, users are cautioned
  not to store data in the gsutil directory, since that data will be lost
  when you update gsutil. (Some users change directories into the gsutil
  directory to run the command. We advise against doing that, for this reason.)
  Note also that the gsutil update command will refuse to run if it finds user
  data in the gsutil directory.

  By default gsutil update will retrieve the new code from
  %s, but you can optionally specify a URL to use
  instead. This is primarily used for distributing pre-release versions of
  the code to a small group of early test users.

  NOTE: gsutil periodically checks whether a more recent software update is
  available. By default this check is performed every 30 days; you can change
  (or disable) this check by editing the software_update_check_period variable
  in the .boto config file. Note also that gsutil will only check for software
  updates if stdin, stdout, and stderr are all connected to a TTY, to avoid
  interfering with cron jobs, streaming transfers, and other cases where gsutil
  input or output are redirected from/to files or pipes. Software update
  periodic checks are also disabled by the gsutil -q option (see
  'gsutil help options')


<B>OPTIONS</B>
  -f          Forces the update command to offer to let you update, even if you
              have the most current copy already. This can be useful if you have
              a corrupted local copy.

  -n          Causes update command to run without prompting [Y/n] whether to
              continue if an update is available.
c                       \ rS rSrSr\R                  " SS/\SSSSS	S\R                  \R                  /\R                  S
9r\R                  " SS/SS\0 S9rS r/ SQrS rS rS rS rSrg)UpdateCommandf   z(Implementation of gsutil update command.updaterefreshr      fnTF)
command_name_aliasesusage_synopsismin_argsmax_argssupported_sub_argsfile_url_okprovider_url_okurls_start_arggs_api_supportgs_default_apicommand_helpz#Update to the latest gsutil release)	help_namehelp_name_aliases	help_typehelp_one_line_summary	help_textsubcommand_help_textc                    [         R                  (       d  [         R                  (       a  g[        R                  " 5       n[        R
                  " [        R                  5      R                  U:X  a  g[        5       nSR                  U5      nU R                  XU5        / nU H`  n[        [
        R                  " [        R
                  " U5      [
        R                     5      5      n	UR                  SU	< SU< 35        Mb     [!        SR                  ["        R$                  " S5      5      SU< SU< SU R&                  < S	SR                  U5      < 3-   S
S9e)a  Explains what to do if sudo needed to update gsutil software.

Happens if gsutil was previously installed by a different user (typically if
someone originally installed in a shared file system location, using sudo).

Args:
  tf: Opened TarFile.
  dirs_to_remove: List of directories to remove.
  old_cwd: Path to the working directory we should chdir back to if sudo is
      needed. It's possible that we've chdir'd to a temp directory that's
      been deleted, which can cause odd behavior (e.g. OSErrors when opening
      the metrics subprocess). If this is not truthy, we won't attempt to
      chdir back to this value.

Raises:
  CommandException: if errors encountered.
N z
	sudo chmod 
a  Since it was installed by a different user previously, you will need to update using the following commands. You will be prompted for your password, and the install will run as "root". If you're unsure what this means please ask your system administrator for help:z
	sudo chmod 0644 z
	sudo env BOTO_CONFIG="z" z updateTinformational)r   	IS_CYGWIN
IS_WINDOWSosgetuidstatgslib
GSUTIL_DIRst_uidr   join_CleanUpUpdateCommandoctS_IMODEST_MODEappendr
   textwrapwrapgsutil_path)
selftfdirs_to_removeold_cwduser_idconfig_file_listconfig_files
chmod_cmdsconfig_filemodes
             (platform/gsutil/gslib/commands/update.py_ExplainIfSudoNeeded"UpdateCommand._ExplainIfSudoNeeded   s   &  6 6iikG	wwu ''72 *+88,-Lr7;
 J'rww{3DLLACDd$DE ( 499H	IJ &|T5E5E*-M// *.	/ 	/    ))applicationsautobinbootdesktopdevzdocuments and settingsetcexporthomekernelliblib32libraryz
lost+foundmach_kernelmediamntnetnullnetworkoptprivateproczprogram filespythonrootsbinscriptssrvsyssystemtmpusersusrvarvolumeswinwin32windowswinntc                     U HU  nU(       d  SnUR                  [        R                  5      R                  5       U R                  ;   d  MI  [        SU-  5      e   g)a  Raises Exception if any of dirs is known to be unsafe for gsutil update.

This provides a fail-safe check to ensure we don't try to overwrite
or delete any important directories. (That shouldn't happen given the
way we construct tmp dirs, etc., but since the gsutil update cleanup
uses shutil.rmtree() it's prudent to add extra checks.)

Args:
  dirs: List of directories to check.

Raises:
  CommandException: If unsafe directory encountered.
rb   zKEnsureDirsSafeForUpdate: encountered unsafe directory (%s); aborting updateN)lstripr4   seplowerunsafe_update_dirsr
   )rC   dirsds      rM   _EnsureDirsSafeForUpdate&UpdateCommand._EnsureDirsSafeForUpdate   sX     	
"&&				!T%<%<	<  ACD E F 	F	 rP   c                 @   U(       a  UR                  5         U R                  U5        U H  n [        R                  " U5        M     U(       a   [        R                  " U5        gg! [         a    [
        R                  (       d  e  Ma  f = f! [         a     gf = f)a  Cleans up temp files etc. from running update command.

Args:
  tf: Opened TarFile, or None if none currently open.
  dirs_to_remove: List of directories to remove.
  old_cwd: Path to the working directory we should chdir back to. It's
      possible that we've chdir'd to a temp directory that's been deleted,
      which can cause odd behavior (e.g. OSErrors when opening the metrics
      subprocess). If this is not truthy, we won't attempt to chdir back
      to this value.
N)	closer~   shutilrmtreeOSErrorr   r3   r4   chdir)rC   rD   rE   rF   	directorys        rM   r;   #UpdateCommand._CleanUpUpdateCommand   s     
hhj!!.1#	i  $ 
   
 %%
 &  s#   A)B ) BB
BBc                 6   [         R                  (       a  [        S5      e[        R                  " 5       (       a  [        S5      e[
        nU(       d  [        S5      e[        5         SnSnU R                  (       a'  U R                   H  u  pEUS:X  a  SnUS:X  d  M  SnM     / n[        R                  " 5       nUR                  U5        [        R                  " 5       n[        R                  " U5        U(       d  U R                  R                  S5        U R                   (       a  U R                   S	   n	U	R#                  S
5      (       d  [        S5      e[%        U R'                  U	5      5       H  u  pU
S	:  a  [        S5      eUR(                  nUR+                  5       (       a)  UR-                  5       (       d  U(       d  [        S5      eM`  UR/                  5       (       a  UR1                  5       (       a  M  [        S5      e   O
[3        5       n	[5        U R6                  U	5      nU(       a  SnOrU R9                  U	5      nUR;                  5         [=        [        R>                  RA                  SS5      S5       nURC                  5       RE                  5       nSSS5        U(       dN  [         RF                  U:X  a:  U RI                  XU5        U R                   (       a  [        SU	-  SS9e[        SSS9eU(       d  [K        5         [M        U[         RF                  5      u  nnU(       aN  [O        SRA                  [P        RR                  " SU< S[         RT                  < S[V        < S35      5      5        O![O        SU< S[         RT                  < 35        U RY                  XU5        U(       a  SnO[[        S5      nU(       a  UR]                  5       S	   S:w  a  U RI                  XU5        [        SSS9eU(       d  U R9                  U	5      n[_        [`        Rb                  [`        Rd                  5        [        R>                  Rg                  [        R>                  RA                  [         RT                  S5      5      n[        R                  " US 9n[        R                  " US 9nUR                  U5        UR                  U5        U Ri                  U5         UR;                  US!9  [        Rl                  (       Gdk  [        Rn                  " U5       GH  u  nnnU H  n[        R<                  " [        R>                  RA                  UU5      [        Rp                  5      n[        Rr                  " U[t        Rv                  [t        Rx                  -  [t        Rz                  -  [t        R|                  -  5        [        R~                  " U5        M     U H  n[        R<                  " [        R>                  RA                  UU5      [        Rp                  5      n[        Rr                  " U[t        R                  [t        R                  -  [t        R                  -  [t        Rz                  -  [t        R|                  -  5        [        R~                  " U5        M     GM     [        R<                  " [        R>                  RA                  USS5      [        Rp                  5      n[        Rr                  " U[t        R                  [t        Rz                  -  [t        R                  -  [t        R|                  -  [t        R                  -  5        [        R~                  " U5        [        R                  " [         RT                  [        R>                  RA                  US#5      5        [        R                  " [        R>                  RA                  US5      [         RT                  5        U RI                  XU5        [_        [`        Rb                  [`        R                  5        U R                  R                  S$5        g	! , (       d  f       GN= f! [j         a%  nU RI                  XU5        [        S"U-  5      eSnAff = f)%z+Command entry point for the update command.zThe update command is only available for gsutil installed from a tarball. If you installed gsutil via another method, use the same method to update it.aP  The update command is disabled for Cloud SDK installs. Please run "gcloud components update" to update it. Note: the Cloud SDK incorporates updates to the underlying tools approximately every 2 weeks, so if you are attempting to update to a recently created release / pre-release of gsutil it may not yet be available via the Cloud SDK.zYour boto configuration has https_validate_certificates = False.
The update command cannot be run this way, for security reasons.Fz-fTz-nzChecking for software update...r   z.tar.gzz0The update command only works with tar.gz files.z4Invalid update URL. Must name a single .tar.gz file.zG"update" command does not support "file://" URLs without the -f option.z;Invalid update object URL. Must name a single .tar.gz file.NgsutilVERSIONrzYou already have %s installed.r0   z5You already have the latest gsutil release installed.r/   z!This command will update to the "z" version of gsutil at zl. NOTE: This a major new version, so it is strongly recommended that you review the release note details at zJ before updating to this version, especially if you use gsutil in scripts.z" version of
gsutil at yzProceed? [y/N] zNot running update.z..)dir)pathzUpdate failed: %s.oldzUpdate complete.)Er7   IS_PACKAGE_INSTALLr
   r   InvokedViaCloudSdkr   r   sub_optstempfilemkdtempr?   r4   getcwdr   loggerinfoargsendswith	enumerateWildcardIteratorstorage_url	IsFileUrlIsDirectory
IsCloudUrlIsObjectr   r   
gsutil_api_FetchAndOpenGsutilTarball
extractallopenr   r:   readstripr   r;   r   r   printr@   rA   r8   r   rN   r   rz   r   signalSIGINTSIG_IGNnormpathr~   	Exceptionr3   walkO_RDONLYfchmodr6   S_IWRITES_IRUSRS_IRGRPS_IROTHr   S_IRWXUS_IXGRPS_IXOTHrenameSIG_DFL)rC   https_validate_certificatesforce_update	no_promptounused_arE   tmp_dirrF   update_from_url_striresultr   tarball_versionrD   ver_file_majoranswergsutil_bin_parent_dirold_dirnew_diredirnamesubdirs	filenamesfilenamefdsubdirs                                rM   
RunCommandUpdateCommand.RunCommand  s]    !" "
 %%''  #A&MN N $%LI}}+!9,9)	 ' N G'"iikGHHW
kk89yy IIaL )))44>@ 	@ !6!67J!KL)!q5 DF F((  "";+B+B+D+D"     ((**{/C/C/E/E KM M M -. *$//;NOOb**+>?bmmoXy1378"--///1 8 EMM_<
  W=	?2 3-13 	3   	 
 -/"?EMMBjq%	tyyMM
 !%"2"24E	GHI 	K 	!1!13 	5b':f&'fV\\^A&#-
  W=2$GG**+>?b &--8 GG,,
U%%t,. #89G#89G'"'"!!.17mmm! !!! *,)9
%'7I!Hwwrww||GX6D"
))BMMDLL04<<?$,,NP
((2,	 "
 Fwwrww||GV4bkkB"
))$,,-<t||Kll ((2,  *: 77277<<8<bkkJbii
dllT\\)DLL84<<G
,, 	hhrl IIeWe <=IIbggll7H-u/?/?@r7;&--8KK'(I 87z  7
  W=1A5667s$   a+a) 
a&)
b3 bbc                     U R                   R                  SUS/U R                  U R                  SS9  [        R
                  " S5      nSUl        U$ )Ncpzfile://gsutil.tar.gzT)skip_update_checkzgsutil.tar.gzr   )command_runnerRunNamedCommandheadersdebugtarfiler   
errorlevel)rC   r   rD   s      rM   r   (UpdateCommand._FetchAndOpenGsutilTarball  sT    ''	45

 (  
o	&BBMIrP    N)__name__
__module____qualname____firstlineno____doc__r   CreateCommandSpec	_SYNOPSISr	   XMLJSONcommand_specHelpSpec_DETAILED_HELP_TEXT	help_specrN   r{   r~   r;   r   r   __static_attributes__r   rP   rM   r   r   f   s    0 **%;!oo{'7'78 %%, "A#)1/j*XF*>n`rP   r   )+r   
__future__r   r   r   r   r4   r   r   r6   rl   r   r   r@   	six.movesr   r7   gslib.commandr   gslib.cs_api_mapr	   gslib.exceptionr
   gslib.metricsr   gslib.sig_handlingr   gslib.utilsr   gslib.utils.boto_utilr   r   gslib.utils.constantsr   gslib.utils.text_utilr   gslib.utils.update_utilr   r   r   r   r   r   r   rP   rM   <module>r      s    < & %  ' 	    
      ! ( , A 4 # 4 @ 3 1 C 7 4	.\ ].0 fkG krP   