mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-19 07:18:27 +01:00
analytics: remove the report after sending it
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user