<s> import os <EOL> import sys <EOL> import time <EOL> import socket <EOL> import subprocess <EOL> import pkgutil <EOL> import logging <EOL> import pip . req <EOL> import jasperpath <EOL> if sys . version_info < ( <NUM_LIT:3> , <NUM_LIT:3> ) : <EOL> from distutils . spawn import find_executable <EOL> else : <EOL> from shutil import which as find_executable <EOL> logger = logging . getLogger ( __name__ ) <EOL> def check_network_connection ( server = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> logger = logging . getLogger ( __name__ ) <EOL> logger . debug ( "<STR_LIT>" , server ) <EOL> try : <EOL> host = socket . gethostbyname ( server ) <EOL> socket . create_connection ( ( host , <NUM_LIT> ) , <NUM_LIT:2> ) <EOL> except Exception : <EOL> logger . debug ( "<STR_LIT>" ) <EOL> return False <EOL> else : <EOL> logger . debug ( "<STR_LIT>" ) <EOL> return True <EOL> def check_executable ( executable ) : <EOL> """<STR_LIT>""" <EOL> logger = logging . getLogger ( __name__ ) <EOL> logger . debug ( "<STR_LIT>" , executable ) <EOL> executable_path = find_executable ( executable ) <EOL> found = executable_path is not None <EOL> if found : <EOL> logger . debug ( "<STR_LIT>" , executable , <EOL> executable_path ) <EOL> else : <EOL> logger . debug ( "<STR_LIT>" , executable ) <EOL> return found <EOL> def check_python_import ( package_or_module ) : <EOL> """<STR_LIT>""" <EOL> logger = logging . getLogger ( __name__ ) <EOL> logger . debug ( "<STR_LIT>" , package_or_module ) <EOL> loader = pkgutil . get_loader ( package_or_module ) <EOL> found = loader is not None <EOL> if found : <EOL> logger . debug ( "<STR_LIT>" , <EOL> "<STR_LIT>" if loader . is_package ( package_or_module ) <EOL> else "<STR_LIT>" , package_or_module , loader . get_filename ( ) ) <EOL> else : <EOL> logger . debug ( "<STR_LIT>" , package_or_module ) <EOL> return found <EOL> def get_pip_requirements ( fname = os . path . join ( jasperpath . LIB_PATH , <EOL> '<STR_LIT>' ) ) : <EOL> """<STR_LIT>""" <EOL> logger = logging . getLogger ( __name__ ) <EOL> if os . access ( fname , os . R_OK ) : <EOL> reqs = list ( pip . req . parse_requirements ( fname ) ) <EOL> logger . debug ( "<STR_LIT>" , len ( reqs ) , <EOL> fname ) <EOL> return reqs <EOL> else : <EOL> logger . debug ( "<STR_LIT>" , <EOL> fname ) <EOL> def get_git_revision ( ) : <EOL> """<STR_LIT>""" <EOL> logger = logging . getLogger ( __name__ ) <EOL> if not check_executable ( '<STR_LIT>' ) : <EOL> logger . warning ( "<STR_LIT>" ) <EOL> return None <EOL> output = subprocess . check_output ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) . strip ( ) <EOL> if not output : <EOL> logger . warning ( "<STR_LIT>" ) <EOL> return None <EOL> return output <EOL> def run ( ) : <EOL> """<STR_LIT>""" <EOL> logger = logging . getLogger ( __name__ ) <EOL> loglvl = logger . getEffectiveLevel ( ) <EOL> if loglvl == logging . NOTSET or loglvl > logging . INFO : <EOL> logger . setLevel ( logging . INFO ) <EOL> logger . info ( "<STR_LIT>" % time . strftime ( "<STR_LIT>" ) ) <EOL> logger . info ( "<STR_LIT>" , get_git_revision ( ) ) <EOL> failed_checks = <NUM_LIT:0> <EOL> if not check_network_connection ( ) : <EOL> failed_checks += <NUM_LIT:1> <EOL> for executable in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if not check_executable ( executable ) : <EOL> logger . warning ( "<STR_LIT>" , executable ) <EOL> failed_checks += <NUM_LIT:1> <EOL> for req in get_pip_requirements ( ) : <EOL> logger . debug ( "<STR_LIT>" , req . name ) <EOL> if not req . check_if_exists ( ) : <EOL> logger . warning ( "<STR_LIT>" , req . name ) <EOL> failed_checks += <NUM_LIT:1> <EOL> else : <EOL> logger . debug ( "<STR_LIT>" , req . name ) <EOL> for fname in [ os . path . join ( jasperpath . APP_PATH , os . pardir , "<STR_LIT>" , <EOL> "<STR_LIT>" ) ] : <EOL> logger . debug ( "<STR_LIT>" , fname ) <EOL> if not os . access ( fname , os . R_OK ) : <EOL> logger . warning ( "<STR_LIT>" , fname ) <EOL> failed_checks += <NUM_LIT:1> <EOL> else : <EOL> logger . debug ( "<STR_LIT>" , fname ) <EOL> if not failed_checks : <EOL> logger . info ( "<STR_LIT>" ) <EOL> else : <EOL> logger . info ( "<STR_LIT>" % failed_checks ) <EOL> return failed_checks <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> logging . basicConfig ( stream = sys . stdout ) <EOL> logger = logging . getLogger ( ) <EOL> if '<STR_LIT>' in sys . argv : <EOL> logger . setLevel ( logging . DEBUG ) <EOL> run ( ) </s>
