disable analytics warning message on init if disabled globally/system… (#2268)

* disable analytics warning message on init if disabled globally/system-wide

* rename Analytics._is_enabled
Analytics.is_enabled

* refactor trying reduce cognitive complexity metric

* fix missing imports

* fix mistaken reference of self
This commit is contained in:
mindsbackyard
2019-07-14 23:29:30 +03:00
committed by Ruslan Kuprieiev
parent 10121411e0
commit 5976b5e466
2 changed files with 31 additions and 23 deletions
+20 -14
View File
@@ -213,10 +213,20 @@ class Analytics(object):
return core.get(Config.SECTION_CORE_ANALYTICS, True)
@staticmethod
def _is_enabled(cmd=None):
def _get_current_config():
from dvc.config import Config
from dvc.repo import Repo
from dvc.exceptions import NotDvcRepoError
try:
dvc_dir = Repo.find_dvc_dir()
config = Config(dvc_dir)
except NotDvcRepoError:
config = Config(validate=False)
return config
@staticmethod
def is_enabled(cmd=None):
from dvc.command.daemon import CmdDaemonBase
if os.getenv("DVC_TEST"):
@@ -225,17 +235,13 @@ class Analytics(object):
if isinstance(cmd, CmdDaemonBase):
return False
if cmd is None or not hasattr(cmd, "config"):
try:
dvc_dir = Repo.find_dvc_dir()
config = Config(dvc_dir)
assert config is not None
except NotDvcRepoError:
config = Config(validate=False)
assert config is not None
else:
config = cmd.config
assert config is not None
config = (
Analytics._get_current_config()
if cmd is None or not hasattr(cmd, "config")
else cmd.config
)
assert config is not None
enabled = Analytics._is_enabled_config(config)
logger.debug(
@@ -253,7 +259,7 @@ class Analytics(object):
"""
from dvc.daemon import daemon
if not Analytics._is_enabled(cmd):
if not Analytics.is_enabled(cmd):
return
analytics = Analytics()
@@ -264,7 +270,7 @@ class Analytics(object):
"""Collect and send analytics."""
import requests
if not self._is_enabled():
if not self.is_enabled():
return
self.collect()
+11 -9
View File
@@ -7,21 +7,23 @@ from dvc.scm import SCM, NoSCM
from dvc.config import Config
from dvc.exceptions import InitError
from dvc.utils import boxify, relpath, remove
from dvc.analytics import Analytics
logger = logging.getLogger(__name__)
def _welcome_message():
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",
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"