def test(self): a = Analytics() a.collect() self.assertTrue(isinstance(a.info, dict)) self.assertNotEqual(a.info, {}) self.assertTrue(a.PARAM_USER_ID in a.info.keys()) self.assertTrue(a.PARAM_SYSTEM_INFO in a.info.keys()) self.assertNotEqual(a.info[a.PARAM_SYSTEM_INFO], {})
def main(argv=None): args = None cmd = None try: args = parse_args(argv) # Init loglevel early in case we'll run # into errors before setting it properly CmdBase._set_loglevel(args) cmd = args.func(args) ret = cmd.run_cmd() except KeyboardInterrupt as ex: logger.error("Interrupted by the user", ex) ret = 252 except NotDvcProjectError as ex: logger.error("", ex) ret = 253 except DvcParserError: ret = 254 except Exception as ex: logger.error('Unexpected error', ex) ret = 255 Analytics().send_cmd(cmd, args, ret) return ret
def main(argv=None): """Run dvc CLI command. Args: argv: optional list of arguments to parse. sys.argv is used by default. Returns: int: command's return code. """ args = None cmd = None outerLogLevel = logger.level try: args = parse_args(argv) if args.quiet: logger.setLevel(logging.CRITICAL) elif args.verbose: logger.setLevel(logging.DEBUG) cmd = args.func(args) ret = cmd.run() except ConfigError: logger.exception("configuration error") ret = 251 except KeyboardInterrupt: logger.exception("interrupted by the user") ret = 252 except NotDvcRepoError: logger.exception("") ret = 253 except DvcParserError: ret = 254 except Exception as exc: # pylint: disable=broad-except if isinstance(exc, UnicodeError) and is_py2: logger.exception( "unicode is not supported in DVC for Python 2 " "(end-of-life January 1, 2020), please upgrade to Python 3") else: logger.exception("unexpected error") ret = 255 finally: logger.setLevel(outerLogLevel) # Python 2 fails to close these clean occasionally and users see # weird error messages, so we do it manually close_pools() # Remove cached repos in the end of the call, these are anonymous # so won't be reused by any other subsequent run anyway. clean_repos() if ret != 0: logger.info(FOOTER) Analytics().send_cmd(cmd, args, ret) return ret
def run(self): from dvc.analytics import Analytics analytics = Analytics.load(self.args.target) analytics.send() return 0
def test_send_disabled(self, mockpost): ret = main(["config", "core.analytics", "false"]) self.assertEqual(ret, 0) with mock.patch.object(os, "getenv", new=_clean_getenv): ret = main(["daemon", "analytics", Analytics().dump(), "-v"]) self.assertEqual(ret, 0) self.assertFalse(mockpost.called)
def test_send_disabled(self, mockpost): ret = main(['config', 'core.analytics', 'false']) self.assertEqual(ret, 0) with mock.patch.object(os, 'getenv', new=_clean_getenv): ret = main(['daemon', 'analytics', Analytics().dump(), '-v']) self.assertEqual(ret, 0) self.assertFalse(mockpost.called)
def test_is_enabled(dvc_repo, config, result, monkeypatch): configobj = dvc_repo.config._repo_config configobj["core"] = config configobj.write() # reset DVC_TEST env var, which affects `is_enabled()` monkeypatch.delenv("DVC_TEST") assert result == Analytics.is_enabled()
def main(argv=None): """Run dvc CLI command. Args: argv: optional list of arguments to parse. sys.argv is used by default. Returns: int: command's return code. """ args = None cmd = None outerLogLevel = logger.level try: args = parse_args(argv) if args.quiet: logger.setLevel(logging.CRITICAL) elif args.verbose: logger.setLevel(logging.DEBUG) cmd = args.func(args) ret = cmd.run() except LockError: logger.exception("failed to lock before running a command") ret = 250 except ConfigError: logger.exception("configuration error") ret = 251 except KeyboardInterrupt: logger.exception("interrupted by the user") ret = 252 except NotDvcRepoError: logger.exception("") ret = 253 except DvcParserError: ret = 254 except Exception: # pylint: disable=broad-except logger.exception("unexpected error") ret = 255 finally: logger.setLevel(outerLogLevel) # Python 2 fails to close these clean occasionally and users see # weird error messages, so we do it manually close_pools() Analytics().send_cmd(cmd, args, ret) return ret
def main(argv=None): """Run dvc CLI command. Args: argv: optional list of arguments to parse. sys.argv is used by default. Returns: int: command's return code. """ args = None cmd = None outerLogLevel = logger.level try: args = parse_args(argv) if args.quiet: logger.setLevel(logging.CRITICAL) elif args.verbose: logger.setLevel(logging.DEBUG) logging.getLogger("paramiko").setLevel(logging.DEBUG) cmd = args.func(args) ret = cmd.run_cmd() except ConfigError: logger.exception("configuration error") ret = 251 except KeyboardInterrupt: logger.exception("interrupted by the user") ret = 252 except NotDvcRepoError: logger.exception("") ret = 253 except DvcParserError: ret = 254 except Exception: # pylint: disable=broad-except logger.exception("unexpected error") ret = 255 finally: logger.setLevel(outerLogLevel) Analytics().send_cmd(cmd, args, ret) return ret
def _welcome_message(): if Analytics.is_enabled(): logger.info( boxify( "DVC has enabled anonymous aggregate usage analytics.\n" "Read the analytics documentation (and how to opt-out) here:\n" "{blue}https://dvc.org/doc/user-guide/analytics{nc}".format( blue=colorama.Fore.BLUE, nc=colorama.Fore.RESET), border_color="red", )) msg = ("{yellow}What's next?{nc}\n" "{yellow}------------{nc}\n" "- Check out the documentation: {blue}https://dvc.org/doc{nc}\n" "- Get help and share ideas: {blue}https://dvc.org/chat{nc}\n" "- Star us on GitHub: {blue}https://github.com/iterative/dvc{nc}" ).format( yellow=colorama.Fore.YELLOW, blue=colorama.Fore.BLUE, nc=colorama.Fore.RESET, ) logger.info(msg)
def main(argv=None): """Run dvc CLI command. Args: argv: optional list of arguments to parse. sys.argv is used by default. Returns: int: command's return code. """ args = None cmd = None try: args = parse_args(argv) # Init loglevel early in case we'll run # into errors before setting it properly CmdBase.set_loglevel(args) cmd = args.func(args) ret = cmd.run_cmd() except KeyboardInterrupt: logger.error("interrupted by the user") ret = 252 except NotDvcProjectError: logger.error() ret = 253 except DvcParserError: ret = 254 except Exception: # pylint: disable=broad-except logger.error("unexpected error") ret = 255 Analytics().send_cmd(cmd, args, ret) return ret
def test_send_failed(self, mockpost, _): ret = main(["daemon", "analytics", Analytics().dump(), "-v"]) self.assertEqual(ret, 0) self.assertTrue(mockpost.called)
def test_send_failed(self, mockpost): ret = main(['daemon', 'analytics', Analytics().dump(), '-v']) self.assertEqual(ret, 0) self.assertTrue(mockpost.called)