<s> import collections <EOL> import os <EOL> import re <EOL> import sys <EOL> from bs4 import BeautifulSoup as bs <EOL> from oslo_config import cfg <EOL> import pkg_resources <EOL> import requests <EOL> PROJECT_ROOT = os . path . abspath ( os . path . join ( <EOL> os . path . dirname ( os . path . realpath ( __file__ ) ) , '<STR_LIT:..>' ) ) <EOL> if PROJECT_ROOT not in sys . path : <EOL> sys . path . insert ( <NUM_LIT:0> , PROJECT_ROOT ) <EOL> from kolla . common import config as common_config <EOL> NOT_PROJECTS = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> TARBALLS_BASE_URL = '<STR_LIT>' <EOL> VERSIONS = { '<STR_LIT>' : dict ( ) } <EOL> def retrieve_upstream_versions ( ) : <EOL> upstream_versions = dict ( ) <EOL> for project in VERSIONS [ '<STR_LIT>' ] : <EOL> winner = None <EOL> series = VERSIONS [ '<STR_LIT>' ] [ project ] . split ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] <EOL> base = '<STR_LIT>' . format ( TARBALLS_BASE_URL , project ) <EOL> r = requests . get ( base ) <EOL> s = bs ( r . text , '<STR_LIT>' ) <EOL> for link in s . find_all ( '<STR_LIT:a>' ) : <EOL> version = link . get ( '<STR_LIT>' ) <EOL> if ( version . endswith ( '<STR_LIT>' ) and <EOL> version . startswith ( '<STR_LIT>' . format ( project , series ) ) ) : <EOL> split = '<STR_LIT>' . format ( project ) <EOL> candidate = re . split ( split , version ) [ <NUM_LIT:1> ] <EOL> if candidate . startswith ( '<STR_LIT>' ) : <EOL> continue <EOL> if not winner or more_recent ( candidate , winner ) : <EOL> winner = candidate <EOL> if not winner : <EOL> print ( '<STR_LIT>' . format ( project ) ) <EOL> continue <EOL> if '<STR_LIT:->' in winner : <EOL> winner = winner . split ( '<STR_LIT:->' ) [ <NUM_LIT:1> ] <EOL> upstream_versions [ project ] = winner <EOL> VERSIONS [ '<STR_LIT>' ] = collections . OrderedDict ( <EOL> sorted ( upstream_versions . items ( ) ) ) <EOL> def retrieve_local_versions ( ) : <EOL> for section in common_config . SOURCES : <EOL> if section not in NOT_PROJECTS : <EOL> project = section . split ( '<STR_LIT:->' ) [ <NUM_LIT:0> ] <EOL> version = common_config . SOURCES [ section ] [ '<STR_LIT:location>' ] . split ( <EOL> '<STR_LIT:/>' ) [ - <NUM_LIT:1> ] . split ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> if '<STR_LIT:->' in version : <EOL> version = version . split ( '<STR_LIT:->' ) [ <NUM_LIT:1> ] <EOL> VERSIONS [ '<STR_LIT>' ] [ project ] = version <EOL> def more_recent ( candidate , reference ) : <EOL> return pkg_resources . parse_version ( candidate ) > pkg_resources . parse_version ( reference ) <EOL> def diff_link ( project , old_ref , new_ref ) : <EOL> return "<STR_LIT>" . format ( <EOL> project , old_ref , new_ref ) <EOL> def compare_versions ( ) : <EOL> up_to_date = True <EOL> for project in VERSIONS [ '<STR_LIT>' ] : <EOL> if project in VERSIONS [ '<STR_LIT>' ] : <EOL> upstream_version = VERSIONS [ '<STR_LIT>' ] [ project ] <EOL> local_version = VERSIONS [ '<STR_LIT>' ] [ project ] <EOL> if more_recent ( upstream_version , local_version ) : <EOL> print ( "<STR_LIT>" . format ( <EOL> project , upstream_version , local_version , <EOL> diff_link ( project , local_version , upstream_version ) ) ) <EOL> up_to_date = False <EOL> if up_to_date : <EOL> print ( "<STR_LIT>" ) <EOL> def main ( ) : <EOL> conf = cfg . ConfigOpts ( ) <EOL> common_config . parse ( conf , sys . argv [ <NUM_LIT:1> : ] , prog = '<STR_LIT>' ) <EOL> retrieve_local_versions ( ) <EOL> retrieve_upstream_versions ( ) <EOL> compare_versions ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
