#NEWLINE# def check_github( self ) : #NEWLINE# #INDENT# '\n        If the requirement is frozen to a github url, check for new commits.\n\n        API Tokens\n        ----------\n        For more than 50 github api calls per hour, pipchecker requires\n        authentication with the github api by settings the environemnt\n        variable ``GITHUB_API_TOKEN`` or setting the command flag\n        --github-api-token=\'mytoken\'``.\n\n        To create a github api token for use at the command line::\n             curl -u \'rizumu\' -d \'{"scopes":["repo"], "note":"pipchecker"}\' https://api.github.com/authorizations\n\n        For more info on github api tokens:\n            https://help.github.com/articles/creating-an-oauth-token-for-command-line-use\n            http://developer.github.com/v3/oauth/#oauth-authorizations-api\n\n        Requirement Format\n        ------------------\n        Pipchecker gets the sha of frozen repo and checks if it is\n        found at the head of any branches. If it is not found then\n        the requirement is considered to be out of date.\n\n        Therefore, freezing at the commit hash will provide the expected\n        results, but if freezing at a branch or tag name, pipchecker will\n        not be able to determine with certainty if the repo is out of date.\n\n        Freeze at the commit hash (sha)::\n            git+git://github.com/django/django.git@393c268e725f5b229ecb554f3fac02cfc250d2df#egg=Django\n\n        Freeze with a branch name::\n            git+git://github.com/django/django.git@master#egg=Django\n\n        Freeze with a tag::\n            git+git://github.com/django/django.git@1.5b2#egg=Django\n\n        Do not freeze::\n            git+git://github.com/django/django.git#egg=Django\n\n        ' #NEWLINE# for ( name , req ) in list ( self . reqs . items ( ) ) : #NEWLINE# #INDENT# req_url = req [ 'url' ] #NEWLINE# if ( not req_url ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# req_url = str ( req_url ) #NEWLINE# if ( req_url . startswith ( 'git' ) and ( 'github.com/' not in req_url ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( req_url . endswith ( '.tar.gz' ) or req_url . endswith ( '.tar.bz2' ) or req_url . endswith ( '.zip' ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# headers = { #NEWLINE# #INDENT# 'content-type' : 'application/json' , #NEWLINE# #UNINDENT# } #NEWLINE# if self . github_api_token : #NEWLINE# #INDENT# headers [ 'Authorization' ] = 'token {0}' . format ( self . github_api_token ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# ( user , repo ) = urlparse ( req_url ) . path . split ( '#' ) [ 0 ] . strip ( '/' ) . rstrip ( '/' ) . split ( '/' ) #NEWLINE# #UNINDENT# except ( ValueError , IndexError ) as e : #NEWLINE# #INDENT# print ( self . style . ERROR ( ( '\nFailed to parse %r: %s\n' % ( req_url , e ) ) ) ) #NEWLINE# continue #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# test_auth = requests . get ( 'https://api.github.com/django/' , headers = headers ) . json ( ) #NEWLINE# #UNINDENT# except HTTPError as e : #NEWLINE# #INDENT# print ( ( '\n%s\n' % str ( e ) ) ) #NEWLINE# return #NEWLINE# #UNINDENT# if ( ( 'message' in test_auth ) and ( test_auth [ 'message' ] == 'Bad credentials' ) ) : #NEWLINE# #INDENT# print ( self . style . ERROR ( '\nGithub API: Bad credentials. Aborting!\n' ) ) #NEWLINE# return #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( 'message' in test_auth ) and test_auth [ 'message' ] . startswith ( 'API Rate Limit Exceeded' ) ) : #NEWLINE# #INDENT# print ( self . style . ERROR ( '\nGithub API: Rate Limit Exceeded. Aborting!\n' ) ) #NEWLINE# return #NEWLINE# #UNINDENT# #UNINDENT# frozen_commit_sha = None #NEWLINE# if ( '.git' in repo ) : #NEWLINE# #INDENT# ( repo_name , frozen_commit_full ) = repo . split ( '.git' ) #NEWLINE# if frozen_commit_full . startswith ( '@' ) : #NEWLINE# #INDENT# frozen_commit_sha = frozen_commit_full [ 1 : ] #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( '@' in repo ) : #NEWLINE# #INDENT# ( repo_name , frozen_commit_sha ) = repo . split ( '@' ) #NEWLINE# #UNINDENT# #UNINDENT# if ( frozen_commit_sha is None ) : #NEWLINE# #INDENT# msg = self . style . ERROR ( 'repo is not frozen' ) #NEWLINE# #UNINDENT# if frozen_commit_sha : #NEWLINE# #INDENT# branch_url = 'https://api.github.com/repos/{0}/{1}/branches' . format ( user , repo_name ) #NEWLINE# branch_data = requests . get ( branch_url , headers = headers ) . json ( ) #NEWLINE# frozen_commit_url = 'https://api.github.com/repos/{0}/{1}/commits/{2}' . format ( user , repo_name , frozen_commit_sha ) #NEWLINE# frozen_commit_data = requests . get ( frozen_commit_url , headers = headers ) . json ( ) #NEWLINE# if ( ( 'message' in frozen_commit_data ) and ( frozen_commit_data [ 'message' ] == 'Not Found' ) ) : #NEWLINE# #INDENT# msg = self . style . ERROR ( '{0} not found in {1}. Repo may be private.' . format ( frozen_commit_sha [ : 10 ] , name ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( frozen_commit_sha in [ branch [ 'commit' ] [ 'sha' ] for branch in branch_data ] ) : #NEWLINE# #INDENT# msg = self . style . BOLD ( 'up to date' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# msg = self . style . INFO ( '{0} is not the head of any branch' . format ( frozen_commit_data [ 'sha' ] [ : 10 ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( 'dist' in req ) : #NEWLINE# #INDENT# pkg_info = '{dist.project_name} {dist.version}' . format ( dist = req [ 'dist' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( frozen_commit_sha is None ) : #NEWLINE# #INDENT# pkg_info = name #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# pkg_info = '{0} {1}' . format ( name , frozen_commit_sha [ : 10 ] ) #NEWLINE# #UNINDENT# #UNINDENT# print ( '{pkg_info:40} {msg}' . format ( pkg_info = pkg_info , msg = msg ) ) #NEWLINE# del self . reqs [ name ]