CURRENT PATH:
/
opt
/
gsutil
/
gslib
/
commands
/
__pycache__
/
[ ⬅ KEMBALI ]
|
[ HOME ]
Upload File:
Upload Ke Sini
Dir Baru
File Baru
Editing:
update.cpython-39.pyc
a +(Wg�F � @ sN d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlZddlZddlZddl Z ddl Z ddlZddlZddl Z ddlmZ ddlZddlmZ dd lmZ dd lmZ ddlmZ ddlmZ dd lmZ ddlmZ ddlmZ ddl m!Z! ddl"m#Z# ddl$m%Z% ddl$m&Z& ddl$m'Z' dZ(de( de'� Z)G dd� de�Z*dS )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 @ s� e Zd ZdZejddgeddddddejej gej d �Z ejddgd dei d�Z d d� Zg d�Zdd� Zdd� Zdd� Zdd� ZdS )� UpdateCommandz(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 C s� t jst jrdS t�� }t�tj�j|kr.dS t � }d� |�}| �|||� g }|D ]0}tt� t�|�tj ��} |�d| |f � qTtd� t�d��d||| jd� |�f dd��dS ) 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 %s %s� 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 %s sudo env BOTO_CONFIG="%s" %s update%sT�� 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_idZconfig_file_listZconfig_filesZ chmod_cmds�config_file�mode� rF �$/opt/gsutil/gslib/commands/update.py�_ExplainIfSudoNeeded� s2 ����� �z"UpdateCommand._ExplainIfSudoNeeded))Zapplications�auto�binZbootZdesktop�devzdocuments and settings�etc�export�homeZkernel�libZlib32�libraryz lost+foundZmach_kernel�mediaZmnt�net�null�network�opt�private�procz program filesZpython�rootZsbin�scriptsZsrv�sys�system�tmpZusersZusr�varZvolumes�win�win32�windowsZwinntc C s8 |D ].}|sd}|� tj��� | jv rtd| ��qdS )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. rS zKEnsureDirsSafeForUpdate: encountered unsafe directory (%s); aborting updateN)�lstripr0 �sep�lower�unsafe_update_dirsr )r? �dirs�drF rF rG �_EnsureDirsSafeForUpdate� s �z&UpdateCommand._EnsureDirsSafeForUpdatec C st |r|� � | �|� |D ].}zt�|� W q tyF tjsB� Y q0 q|rpzt�|� W n tyn Y n0 dS )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) �closerg �shutil�rmtree�OSErrorr r/ r0 �chdir)r? r@ rA rB � directoryrF rF rG r7 � s z#UpdateCommand._CleanUpUpdateCommandc C s� t jrtd��t�� rtd��t}|s.td��t� d}d}| jrj| jD ] \}}|dkr\d}|dkrHd}qHg }t� � }|� |� t�� }t� |� |s�| j�d� | j�r4| jd } | �d �s�td��t| �| ��D ]\\} }| d kr�td��|j}|�� �r|�� �s|�s0td ��q�|�� �r(|�� s�td��q�nt� } t| j| �} | �rRd}nT| �| �}|�� ttj� dd�d��}|�!� �"� } W d � n1 �s�0 Y |�s�t j#| k�r�| �$|||� | j�r�td| dd��ntddd��|�sBt%� t&| t j#�\}}|�r0t'd� t(�)d| t j*t+f ��� nt'd| t j*f � | �,|||� |�r\d}nt-d�}|�r||�.� d dk�r�| �$|||� tddd��|�s�| �| �}t/t0j1t0j2� tj�3tj� t j*d��}tj |d�}tj |d�}|� |� |� |� | �4|� z|j|d� W n@ t5�yR } z&| �$|||� td| ��W Y d}~n d}~0 0 tj6�s`t�7|�D ]�\}}}|D ]H}t�tj� ||�tj8�}t�9|t:j;t:j<B t:j=B t:j>B � t�?|� �qt|D ]N}t�tj� ||�tj8�}t�9|t:j@t:jAB t:jBB t:j=B t:j>B � t�?|� �qqft�tj� |dd�tj8�}t�9|t:j@t:j=B t:jAB t:j>B t:jBB � t�?|� t�Ct j*tj� |d �� t�Ctj� |d�t j*� | �$|||� t/t0j1t0jD� | j�d!� d S )"z+Command entry point for the update command.z�The 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.z�Your boto configuration has https_validate_certificates = False. The update command cannot be run this way, for security reasons.Fz-fTz-nzChecking 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�rzYou already have %s installed.r, z5You already have the latest gsutil release installed.r+ z�This command will update to the "%s" version of gsutil at %s. NOTE: This a major new version, so it is strongly recommended that you review the release note details at %s before updating to this version, especially if you use gsutil in scripts.z<This command will update to the "%s" version of gsutil at %s�yzProceed? [y/N] zNot running update.z..)�dir)�pathzUpdate failed: %s.�oldzUpdate complete.)Er3 �IS_PACKAGE_INSTALLr r �InvokedViaCloudSdkr r �sub_opts�tempfile�mkdtempr; r0 �getcwdrl �logger�info�args�endswith� enumerate�WildcardIterator�storage_url� IsFileUrl�IsDirectory� IsCloudUrl�IsObjectr r � gsutil_api�_FetchAndOpenGsutilTarball� extractall�openrs r6 �read�stripro r7 r r �printr<