analytics: remove the report after sending it

This commit is contained in:
Mr. Outis
2019-12-06 12:28:06 -06:00
parent f704e5468b
commit da064e2ede
3 changed files with 12 additions and 9 deletions
+9
View File
@@ -81,12 +81,21 @@ def is_enabled():
def send(report):
"""
Side effect: Removes the report after sending it.
The report is generated and stored in a temporary file, see:
`collect_and_send_report`. Sending happens on another process,
thus, the need of removing such file afterwards.
"""
url = "https://analytics.dvc.org"
headers = {"content-type": "application/json"}
with open(report, "rb") as fobj:
requests.post(url, data=fobj, headers=headers, timeout=5)
os.remove(report)
def scm_in_use():
try:
+2 -6
View File
@@ -1,7 +1,5 @@
from __future__ import unicode_literals
import os
from dvc.command.base import CmdBaseNoRepo
from dvc.command.base import fix_subparsers
@@ -12,6 +10,7 @@ class CmdDaemonBase(CmdBaseNoRepo):
class CmdDaemonUpdater(CmdDaemonBase):
def run(self):
import os
from dvc.repo import Repo
from dvc.updater import Updater
@@ -27,10 +26,7 @@ class CmdDaemonAnalytics(CmdDaemonBase):
def run(self):
from dvc import analytics
report = self.args.target
analytics.send(report)
os.remove(report)
analytics.send(self.args.target)
return 0
+1 -3
View File
@@ -5,13 +5,11 @@ from dvc.utils.compat import fspath
@mock.patch("dvc.analytics.send")
@mock.patch("os.remove")
def test_daemon_analytics(mock_remove, mock_send, tmp_path):
def test_daemon_analytics(mock_send, tmp_path):
report = fspath(tmp_path)
assert 0 == main(["daemon", "analytics", report])
mock_send.assert_called_with(report)
mock_remove.assert_called_with(report)
@mock.patch("dvc.daemon._spawn")