Ejemplo n.º 1
0
def _version_check():
    current_version = armada_api.get('version')
    if not is_valid_response(current_version):
        # skip version check since we cannot determinate current version
        return

    with SyncOpen(VERSION_CACHE_FILE_PATH, 'r+') as f:
        data = json.load(f)
        displayed_timestamp = data['displayed']

        cache_version = data['latest_version']
        current_is_newer = StrictVersion(current_version) >= StrictVersion(
            cache_version)
        if current_is_newer or time.time(
        ) - DISPLAY_INTERVAL < displayed_timestamp:
            return

        message = 'You are using armada version {}, however version {} is available. ' \
                  'You should consider upgrading armada via "bash <(curl -sL http://armada.sh/install)"' \
            .format(armada_api.get('version'), data['latest_version'])
        print('\n' + message, file=sys.stderr)

        data['displayed'] = time.time()
        f.seek(0)
        f.truncate()
        json.dump(data, f)
Ejemplo n.º 2
0
def _cache_outdated_or_invalid():
    try:
        with SyncOpen(VERSION_CACHE_FILE_PATH, 'r') as f:
            data = json.load(f)
    except (IOError, ValueError):
        return True
    synced_timestamp = data['synced']
    return time.time() - SYNC_INTERVAL > synced_timestamp
Ejemplo n.º 3
0
def main():
    version = armada_api.get('version')
    if not is_valid_response(version):
        # skip sync if we cannot determine current version
        return
    r = requests.get('http://version.armada.sh/version_check',
                     data=dict(version=version),
                     timeout=3)
    r.raise_for_status()
    data = r.json()
    data.update({
        'displayed': 0,
        'synced': time.time(),
    })
    with SyncOpen(VERSION_CACHE_FILE_PATH, 'w') as f:
        json.dump(data, f)