mirror of
https://github.com/wakatime/sublime-wakatime.git
synced 2023-08-10 21:13:02 +03:00
prevent executing wakatime-cli before it has been downloaded
This commit is contained in:
parent
01503b1c20
commit
2e6a87c67e
14
WakaTime.py
14
WakaTime.py
@ -14,7 +14,6 @@ __version__ = '10.0.0'
|
||||
import sublime
|
||||
import sublime_plugin
|
||||
|
||||
import contextlib
|
||||
import json
|
||||
import os
|
||||
import platform
|
||||
@ -24,7 +23,6 @@ import sys
|
||||
import time
|
||||
import threading
|
||||
import traceback
|
||||
import urllib
|
||||
import webbrowser
|
||||
import ssl
|
||||
import shutil
|
||||
@ -237,6 +235,8 @@ class FetchStatusBarCodingTime(threading.Thread):
|
||||
if not self.api_key:
|
||||
log(DEBUG, 'Missing WakaTime API key.')
|
||||
return
|
||||
if not isCliInstalled():
|
||||
return
|
||||
|
||||
ua = 'sublime/%d sublime-wakatime/%s' % (ST_VERSION, __version__)
|
||||
cmd = [
|
||||
@ -382,9 +382,12 @@ def append_heartbeat(entity, timestamp, is_write, view, project, folders):
|
||||
def process_queue(timestamp):
|
||||
global LAST_HEARTBEAT_SENT_AT
|
||||
|
||||
if not isCliInstalled():
|
||||
return
|
||||
|
||||
# Prevent sending heartbeats more often than SEND_BUFFER_SECONDS
|
||||
now = int(time.time())
|
||||
if isCliInstalled() and timestamp != LAST_HEARTBEAT['time'] and LAST_HEARTBEAT_SENT_AT > now - SEND_BUFFER_SECONDS:
|
||||
if timestamp != LAST_HEARTBEAT['time'] and LAST_HEARTBEAT_SENT_AT > now - SEND_BUFFER_SECONDS:
|
||||
return
|
||||
LAST_HEARTBEAT_SENT_AT = now
|
||||
|
||||
@ -604,6 +607,7 @@ class DownloadCLI(threading.Thread):
|
||||
def isCliInstalled():
|
||||
return os.path.exists(API_CLIENT)
|
||||
|
||||
|
||||
def isCliLatest():
|
||||
if not isCliInstalled():
|
||||
return False
|
||||
@ -630,6 +634,7 @@ def isCliLatest():
|
||||
log(INFO, 'Found an updated wakatime-cli v%s' % remoteVer)
|
||||
return False
|
||||
|
||||
|
||||
def getLatestCliVersion():
|
||||
url = getCliVersionUrl()
|
||||
try:
|
||||
@ -646,6 +651,7 @@ def getLatestCliVersion():
|
||||
except:
|
||||
return None
|
||||
|
||||
|
||||
def getCliVersionUrl():
|
||||
os = platform.system().lower().replace('darwin', 'mac')
|
||||
arch = '64' if sys.maxsize > 2**32 else '32'
|
||||
@ -655,6 +661,7 @@ def getCliVersionUrl():
|
||||
arch=arch,
|
||||
)
|
||||
|
||||
|
||||
def extractVersion(text):
|
||||
log(DEBUG, 'extracting version.')
|
||||
pattern = re.compile(r"([0-9]+\.[0-9]+\.[0-9]+)")
|
||||
@ -663,6 +670,7 @@ def extractVersion(text):
|
||||
return match.group(1)
|
||||
return None
|
||||
|
||||
|
||||
def download(url, filePath):
|
||||
try:
|
||||
urlretrieve(url, filePath)
|
||||
|
Loading…
Reference in New Issue
Block a user