def check_python(self, name): # We can query packages using the pip module. # import pip _now_ since it may not exist at script launch import pip import pip.req import pkg_resources # if we installed a package, this is out of date reload(pkg_resources) req = pip.req.InstallRequirement.from_line(name) req.check_if_exists() return req.satisfied_by != None
def run(): """ Performs a series of checks against the system and writes the results to the logging system. Returns: The number of failed checks as integer """ logger = logging.getLogger(__name__) # Set loglevel of this module least to info loglvl = logger.getEffectiveLevel() if loglvl == logging.NOTSET or loglvl > logging.INFO: logger.setLevel(logging.INFO) logger.info("Starting main diagnostic at %s" % time.strftime("%c")) logger.info("Git revision: %r", get_git_revision()) failed_checks = 0 if not check_network_connection(): failed_checks += 1 #for executable in ['phonetisaurus-g2p', 'espeak', 'say']: #espeak说话很机器人,say必须用在Mac系统, for executable in ['phonetisaurus-g2p', 'alsamixer']: if not check_executable(executable): logger.warning("Executable '%s' is missing in $PATH", executable) failed_checks += 1 for req in get_pip_requirements(): logger.debug("Checking PIP package '%s'...", req.name) if not req.check_if_exists(): logger.warning("PIP package '%s' is missing", req.name) failed_checks += 1 else: logger.debug("PIP package '%s' found", req.name) for fname in [ os.path.join(configuration.CONFIG_PATH, "g014b2b", "g014b2b.fst") ]: logger.debug("Checking file '%s'...", fname) if not os.access(fname, os.R_OK): logger.warning("File '%s' is missing", fname) failed_checks += 1 else: logger.debug("File '%s' found", fname) if not failed_checks: logger.info("All checks passed") else: logger.info("%d checks failed" % failed_checks) return failed_checks
def run(): """ Performs a series of checks against the system and writes the results to the logging system. Returns: The number of failed checks as integer """ logger = logging.getLogger(__name__) # Set loglevel of this module least to info loglvl = logger.getEffectiveLevel() if loglvl == logging.NOTSET or loglvl > logging.INFO: logger.setLevel(logging.INFO) logger.info("Starting dingdang diagnostic at %s" % time.strftime("%c")) logger.info("Git revision: %r", get_git_revision()) failed_checks = 0 if not check_network_connection(): failed_checks += 1 for executable in ['phonetisaurus-g2p', 'espeak', 'say']: if not check_executable(executable): logger.warning("Executable '%s' is missing in $PATH", executable) failed_checks += 1 for req in get_pip_requirements(): logger.debug("Checking PIP package '%s'...", req.name) if not req.check_if_exists(): logger.warning("PIP package '%s' is missing", req.name) failed_checks += 1 else: logger.debug("PIP package '%s' found", req.name) for fname in [os.path.join(dingdangpath.APP_PATH, os.pardir, "phonetisaurus", "g014b2b.fst")]: logger.debug("Checking file '%s'...", fname) if not os.access(fname, os.R_OK): logger.warning("File '%s' is missing", fname) failed_checks += 1 else: logger.debug("File '%s' found", fname) if not failed_checks: logger.info("All checks passed") else: logger.info("%d checks failed" % failed_checks) return failed_checks
def run(): """ Performs a series of checks against the system and writes the results to the logging system. Returns: The number of failed checks as integer """ # Set loglevel of this module least to info # loglvl = logger.getEffectiveLevel() # if loglvl == logging.NOTSET or loglvl > logging.INFO: # logger.setLevel(logging.INFO) print("Starting dingdang diagnostic at %s" % time.strftime("%c")) print("Git revision: %r", get_git_revision()) failed_checks = 0 if not check_network_connection(): failed_checks += 1 for executable in ['phonetisaurus-g2p', 'espeak', 'say']: if not check_executable(executable): print("Executable '%s' is missing in $PATH", executable) failed_checks += 1 for req in get_pip_requirements(): print("Checking PIP package '%s'...", req.name) if not req.check_if_exists(): print("PIP package '%s' is missing", req.name) failed_checks += 1 else: print("PIP package '%s' found", req.name) for fname in [ os.path.join(dingdangpath.APP_PATH, os.pardir, "phonetisaurus", "g014b2b.fst") ]: print("Checking file '%s'...", fname) if not os.access(fname, os.R_OK): print("File '%s' is missing", fname) failed_checks += 1 else: print("File '%s' found", fname) if not failed_checks: print("All checks passed") else: print("%d checks failed" % failed_checks) return failed_checks