dvc: check for updates once a week

Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
Ruslan Kuprieiev
2018-05-10 15:21:14 +03:00
parent 03ebdb5cf2
commit 2f97be3782
3 changed files with 20 additions and 3 deletions
+19 -1
View File
@@ -1,3 +1,5 @@
import os
import time
import json
import requests
@@ -5,14 +7,30 @@ from dvc import VERSION_BASE
from dvc.logger import Logger
DVCAPI_URL = 'https://4ki8820rsf.execute-api.us-east-2.amazonaws.com/prod/latest-version'
CHECK_UPDATES_FILE = '.check_updates'
TIMEOUT = 7 * 24 * 60 * 60 #every week
def check_updates():
def check_updates(dvc_dir):
current = VERSION_BASE
if os.getenv('CI'):
return
fname = os.path.join(dvc_dir, CHECK_UPDATES_FILE)
if os.path.isfile(fname):
ctime = os.path.getctime(fname)
if time.time() - ctime < TIMEOUT:
msg = '{} is not old enough to check for updates'
Logger.debug(msg.format(CHECK_UPDATES_FILE))
return
os.unlink(fname)
try:
r = requests.get(DVCAPI_URL)
j = json.loads(r.content)
latest = j['version']
open(fname, 'w+').close()
except Exception as exc:
Logger.debug('Failed to obtain latest version: {}'.format(str(exc)))
return
-1
View File
@@ -1 +0,0 @@
"Hello from Lambda"
+1 -1
View File
@@ -53,7 +53,7 @@ class Project(object):
self.logger = Logger(self.config._config[Config.SECTION_CORE].get(Config.SECTION_CORE_LOGLEVEL, None))
self.cloud = DataCloud(cache=self.cache, config=self.config._config)
check_updates()
check_updates(self.dvc_dir)
@staticmethod
def init(root_dir=os.curdir, no_scm=False):