def get_cached_latest_versions(versions=None): """ Get the latest versions from a cached file""" import os import datetime from azure.cli.core._environment import get_config_dir from azure.cli.core._session import VERSIONS if not versions: versions = _get_local_versions() VERSIONS.load(os.path.join(get_config_dir(), 'versionCheck.json')) if VERSIONS[_VERSION_UPDATE_TIME]: version_update_time = datetime.datetime.strptime( VERSIONS[_VERSION_UPDATE_TIME], '%Y-%m-%d %H:%M:%S.%f') if datetime.datetime.now() < version_update_time + datetime.timedelta( days=1): cache_versions = VERSIONS['versions'] if cache_versions and cache_versions['azure-cli'][ 'local'] == versions['azure-cli']['local']: return cache_versions.copy(), True versions, success = _update_latest_from_pypi(versions) if success: VERSIONS['versions'] = versions VERSIONS[_VERSION_UPDATE_TIME] = str(datetime.datetime.now()) return versions.copy(), success
def __init__(self, **kwargs): super(AzCli, self).__init__(**kwargs) from azure.cli.core.commands import register_cache_arguments from azure.cli.core.commands.arm import ( register_ids_argument, register_global_subscription_argument) from azure.cli.core.cloud import get_active_cloud from azure.cli.core.commands.transform import register_global_transforms from azure.cli.core._session import ACCOUNT, CONFIG, SESSION, INDEX, VERSIONS from azure.cli.core.style import format_styled_text from azure.cli.core.util import handle_version_update from azure.cli.core.commands.query_examples import register_global_query_examples_argument from knack.util import ensure_dir self.data['headers'] = {} self.data['command'] = 'unknown' self.data['command_extension_name'] = None self.data['completer_active'] = ARGCOMPLETE_ENV_NAME in os.environ self.data['query_active'] = False azure_folder = self.config.config_dir ensure_dir(azure_folder) ACCOUNT.load(os.path.join(azure_folder, 'azureProfile.json')) CONFIG.load(os.path.join(azure_folder, 'az.json')) SESSION.load(os.path.join(azure_folder, 'az.sess'), max_age=3600) INDEX.load(os.path.join(azure_folder, 'commandIndex.json')) VERSIONS.load(os.path.join(azure_folder, 'versionCheck.json')) handle_version_update() self.cloud = get_active_cloud(self) logger.debug('Current cloud config:\n%s', str(self.cloud.name)) self.local_context = AzCLILocalContext(self) register_global_transforms(self) register_global_subscription_argument(self) register_global_query_examples_argument(self) register_ids_argument( self) # global subscription must be registered first! register_cache_arguments(self) self.progress_controller = None if self.enable_color: theme = self.config.get('core', 'theme', fallback='dark') else: theme = 'none' format_styled_text.theme = theme
def show_updates_available(new_line_before=False, new_line_after=False): import os from azure.cli.core._session import VERSIONS import datetime from azure.cli.core._environment import get_config_dir VERSIONS.load(os.path.join(get_config_dir(), 'versionCheck.json')) if VERSIONS[_VERSION_CHECK_TIME]: version_check_time = datetime.datetime.strptime(VERSIONS[_VERSION_CHECK_TIME], '%Y-%m-%d %H:%M:%S.%f') if datetime.datetime.now() < version_check_time + datetime.timedelta(days=7): return _, updates_available = get_az_version_string(use_cache=True) if updates_available > 0: if new_line_before: logger.warning("") show_updates(updates_available) if new_line_after: logger.warning("") VERSIONS[_VERSION_CHECK_TIME] = str(datetime.datetime.now())