From 7dc4f3022d1843063dce621ca09c80bb64cdb8c1 Mon Sep 17 00:00:00 2001 From: schneefux Date: Wed, 1 Oct 2014 18:48:09 +0200 Subject: Improve diagnose.py reusability --- jasper.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'jasper.py') diff --git a/jasper.py b/jasper.py index 27a8de8..5061510 100755 --- a/jasper.py +++ b/jasper.py @@ -8,8 +8,7 @@ import logging import yaml import argparse -from client.diagnose import Diagnostics -from client import vocabcompiler, tts, stt, jasperpath +from client import vocabcompiler, tts, stt, jasperpath, diagnose # Add jasperpath.LIB_PATH to sys.path sys.path.append(jasperpath.LIB_PATH) @@ -132,8 +131,7 @@ if __name__ == "__main__": if args.debug: logger.setLevel(logging.DEBUG) - if (not args.no_network_check and - not Diagnostics.check_network_connection()): + if not args.no_network_check and not diagnose.check_network_connection(): logger.warning("Network not connected. This may prevent Jasper from " + "running properly.") -- cgit v1.3.1 From fc68f5323584c8307872b02a75b76fe671f26cd4 Mon Sep 17 00:00:00 2001 From: schneefux Date: Wed, 1 Oct 2014 19:22:58 +0200 Subject: Set loglevel at least to info during diagnose run and add '--diagnose' argument to jasper.py --- client/diagnose.py | 8 +++++++- jasper.py | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'jasper.py') diff --git a/client/diagnose.py b/client/diagnose.py index 0483c22..acbec5e 100755 --- a/client/diagnose.py +++ b/client/diagnose.py @@ -98,6 +98,11 @@ class DiagnosticRunner(object): self._logger = logging.getLogger(__name__) def run(self): + # Set loglevel of this module least to info + loglvl = self._logger.getEffectiveLevel() + if loglvl == logging.NOTSET or loglvl > logging.INFO: + self._logger.setLevel(logging.INFO) + self._logger.info("Starting jasper diagnostic at %s", time.strftime("%c")) self._logger.info("Git revision: %r", get_git_revision()) @@ -141,5 +146,6 @@ class DiagnosticRunner(object): if __name__ == '__main__': logging.basicConfig(stream=sys.stdout) logger = logging.getLogger() - logger.setLevel(logging.DEBUG if '--debug' in sys.argv else logging.INFO) + if '--debug' in sys.argv: + logger.setLevel(logging.DEBUG) DiagnosticRunner().run() diff --git a/jasper.py b/jasper.py index 5061510..1e3484b 100755 --- a/jasper.py +++ b/jasper.py @@ -20,6 +20,8 @@ parser.add_argument('--local', action='store_true', help='Use text input instead of a real microphone') parser.add_argument('--no-network-check', action='store_true', help='Disable the network connection check') +parser.add_argument('--diagnose', action='store_true', + help='Run diagnose and exit') parser.add_argument('--debug', action='store_true', help='Show debug messages') args = parser.parse_args() @@ -135,6 +137,11 @@ if __name__ == "__main__": logger.warning("Network not connected. This may prevent Jasper from " + "running properly.") + if args.diagnose: + diag = diagnose.DiagnosticRunner() + failed_checks = diag.run() + sys.exit(0 if not failed_checks else 1) + try: app = Jasper() except Exception: -- cgit v1.3.1 From c182a08f3e1578f83d9c024a9c5b404d04afec4b Mon Sep 17 00:00:00 2001 From: schneefux Date: Thu, 2 Oct 2014 15:08:23 +0200 Subject: Transform DiagnosticRunner.run() into a single function --- client/diagnose.py | 82 +++++++++++++++++++++++++----------------------------- jasper.py | 3 +- 2 files changed, 39 insertions(+), 46 deletions(-) (limited to 'jasper.py') diff --git a/client/diagnose.py b/client/diagnose.py index acbec5e..b51ffc4 100644 --- a/client/diagnose.py +++ b/client/diagnose.py @@ -87,60 +87,54 @@ def get_git_revision(): return None return output - -class DiagnosticRunner(object): +def run(): """ - Performs a series of checks against the system, printing the results to the - console and also saving them to diagnostic.log + Performs a series of checks against the system and writes the results to + the logging system. """ + logger = logging.getLogger(__name__) - def __init__(self): - self._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) - def run(self): - # Set loglevel of this module least to info - loglvl = self._logger.getEffectiveLevel() - if loglvl == logging.NOTSET or loglvl > logging.INFO: - self._logger.setLevel(logging.INFO) + logger.info("Starting jasper diagnostic at %s" % time.strftime("%c")) + logger.info("Git revision: %r", get_git_revision()) - self._logger.info("Starting jasper diagnostic at %s", - time.strftime("%c")) - self._logger.info("Git revision: %r", get_git_revision()) + failed_checks = 0 - 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 - if not check_network_connection(): + 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 executable in ['phonetisaurus-g2p', 'espeak', 'say']: - if not check_executable(executable): - self._logger.warning("Executable '%s' is missing in $PATH", - executable) - failed_checks += 1 - - for req in get_pip_requirements(): - self._logger.debug("Checking PIP package '%s'...", req.name) - if not req.check_if_exists(): - self._logger.warning("PIP package '%s' is missing", req.name) - failed_checks += 1 - else: - self._logger.debug("PIP package '%s' found", req.name) - - for fname in [os.path.join(jasperpath.APP_PATH, os.pardir, - "phonetisaurus", "g014b2b.fst")]: - self._logger.debug("Checking file '%s'...", fname) - if not os.access(fname, os.R_OK): - self._logger.warning("File '%s' is missing", fname) - failed_checks += 1 - else: - self._logger.debug("File '%s' found", fname) - - if not failed_checks: - logger.info("All checks passed") + for fname in [os.path.join(jasperpath.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.info("%d checks failed" % failed_checks) + 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 + return failed_checks if __name__ == '__main__': @@ -148,4 +142,4 @@ if __name__ == '__main__': logger = logging.getLogger() if '--debug' in sys.argv: logger.setLevel(logging.DEBUG) - DiagnosticRunner().run() + run() diff --git a/jasper.py b/jasper.py index 1e3484b..d116ce9 100755 --- a/jasper.py +++ b/jasper.py @@ -138,8 +138,7 @@ if __name__ == "__main__": "running properly.") if args.diagnose: - diag = diagnose.DiagnosticRunner() - failed_checks = diag.run() + failed_checks = diagnose.run() sys.exit(0 if not failed_checks else 1) try: -- cgit v1.3.1