mirror of
https://github.com/wakatime/sublime-wakatime.git
synced 2023-08-10 21:13:02 +03:00
Compare commits
29 Commits
11.0.1
...
feature/ap
Author | SHA1 | Date | |
---|---|---|---|
![]() |
a387c08b44 | ||
![]() |
3c2947cf79 | ||
![]() |
54e6772a80 | ||
![]() |
b576dfafe6 | ||
![]() |
5299efd6fa | ||
![]() |
74583a6845 | ||
![]() |
31f1f8ecdc | ||
![]() |
c1f58fd05d | ||
![]() |
28063e3ac4 | ||
![]() |
4d56aca1a1 | ||
![]() |
e15c514ef3 | ||
![]() |
fe582c84b9 | ||
![]() |
d7ee8675d8 | ||
![]() |
da17125b97 | ||
![]() |
847223cdce | ||
![]() |
b405f99cff | ||
![]() |
b5210b77ce | ||
![]() |
fac1192228 | ||
![]() |
4d6533b2ee | ||
![]() |
7d2bd0b7c5 | ||
![]() |
66f5f48f33 | ||
![]() |
e337afcc53 | ||
![]() |
033c07f070 | ||
![]() |
c09767b58d | ||
![]() |
ac80c4268b | ||
![]() |
e5331d3086 | ||
![]() |
bebb46dda6 | ||
![]() |
9767790063 | ||
![]() |
75c219055d |
56
HISTORY.rst
56
HISTORY.rst
@@ -3,6 +3,62 @@ History
|
|||||||
-------
|
-------
|
||||||
|
|
||||||
|
|
||||||
|
11.1.0 (2022-11-11)
|
||||||
|
++++++++++++++++++
|
||||||
|
|
||||||
|
- Support for api key vault cmd config
|
||||||
|
|
||||||
|
|
||||||
|
11.0.8 (2022-08-23)
|
||||||
|
++++++++++++++++++
|
||||||
|
|
||||||
|
- Bugfix to prevent using empty selection object.
|
||||||
|
`#116 <https://github.com/wakatime/sublime-wakatime/issues/116>`_
|
||||||
|
|
||||||
|
|
||||||
|
11.0.7 (2022-06-25)
|
||||||
|
++++++++++++++++++
|
||||||
|
|
||||||
|
- Check wakatime-cli versions in background thread.
|
||||||
|
`#115 <https://github.com/wakatime/sublime-wakatime/issues/115>`_
|
||||||
|
|
||||||
|
|
||||||
|
11.0.6 (2022-06-08)
|
||||||
|
++++++++++++++++++
|
||||||
|
|
||||||
|
- Fix call to log helper.
|
||||||
|
`#113 <https://github.com/wakatime/sublime-wakatime/issues/113>`_
|
||||||
|
|
||||||
|
|
||||||
|
11.0.5 (2022-04-29)
|
||||||
|
++++++++++++++++++
|
||||||
|
|
||||||
|
- Bugfix to not overwrite global urlopener in embedded Python.
|
||||||
|
`#110 <https://github.com/wakatime/sublime-wakatime/issues/110>`_
|
||||||
|
- Chmod wakatime-cli to be executable after updating on non-Windows platforms.
|
||||||
|
|
||||||
|
|
||||||
|
11.0.4 (2022-01-06)
|
||||||
|
++++++++++++++++++
|
||||||
|
|
||||||
|
- Copy wakatime-cli when symlink fails on Windows.
|
||||||
|
`vim-wakatime#122 <https://github.com/wakatime/vim-wakatime/issues/122>`_
|
||||||
|
- Fix lineno, cursorpos, and lines-in-file arguments.
|
||||||
|
|
||||||
|
|
||||||
|
11.0.3 (2021-12-31)
|
||||||
|
++++++++++++++++++
|
||||||
|
|
||||||
|
- Bugfix to not delete old wakatime-cli until finished downloading new version.
|
||||||
|
`#107 <https://github.com/wakatime/sublime-wakatime/issues/107>`_
|
||||||
|
|
||||||
|
|
||||||
|
11.0.2 (2021-11-17)
|
||||||
|
++++++++++++++++++
|
||||||
|
|
||||||
|
- Bugfix to encode extra heartbeats cursorpos as int not str when sending to wakatime-cli.
|
||||||
|
|
||||||
|
|
||||||
11.0.1 (2021-11-16)
|
11.0.1 (2021-11-16)
|
||||||
++++++++++++++++++
|
++++++++++++++++++
|
||||||
|
|
||||||
|
@@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
[WakaTime][wakatime] is an open source Sublime Text plugin for metrics, insights, and time tracking automatically generated from your programming activity.
|
[WakaTime][wakatime] is an open source Sublime Text plugin for metrics, insights, and time tracking automatically generated from your programming activity.
|
||||||
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
1. Install [Package Control](https://packagecontrol.io/installation).
|
1. Install [Package Control](https://packagecontrol.io/installation).
|
||||||
@@ -19,12 +18,10 @@
|
|||||||
|
|
||||||
6. Use Sublime and your coding activity will be displayed on your [WakaTime dashboard](https://wakatime.com).
|
6. Use Sublime and your coding activity will be displayed on your [WakaTime dashboard](https://wakatime.com).
|
||||||
|
|
||||||
|
|
||||||
## Screen Shots
|
## Screen Shots
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|
||||||
## Unresponsive Plugin Warning
|
## Unresponsive Plugin Warning
|
||||||
|
|
||||||
In Sublime Text 2, if you get a warning message:
|
In Sublime Text 2, if you get a warning message:
|
||||||
@@ -35,7 +32,6 @@ To fix this, go to `Preferences → Settings - User` then add the following sett
|
|||||||
|
|
||||||
`"detect_slow_plugins": false`
|
`"detect_slow_plugins": false`
|
||||||
|
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
||||||
First, turn on debug mode in your `WakaTime.sublime-settings` file.
|
First, turn on debug mode in your `WakaTime.sublime-settings` file.
|
||||||
|
201
WakaTime.py
201
WakaTime.py
@@ -8,7 +8,7 @@ Website: https://wakatime.com/
|
|||||||
==========================================================="""
|
==========================================================="""
|
||||||
|
|
||||||
|
|
||||||
__version__ = '11.0.1'
|
__version__ = '11.0.8'
|
||||||
|
|
||||||
|
|
||||||
import sublime
|
import sublime
|
||||||
@@ -18,6 +18,7 @@ import json
|
|||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import re
|
import re
|
||||||
|
import shutil
|
||||||
import ssl
|
import ssl
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
@@ -39,9 +40,9 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
from configparser import ConfigParser, Error as ConfigParserError
|
from configparser import ConfigParser, Error as ConfigParserError
|
||||||
try:
|
try:
|
||||||
from urllib2 import urlopen, urlretrieve, ProxyHandler, build_opener, install_opener, HTTPError
|
from urllib2 import Request, urlopen, HTTPError
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from urllib.request import urlopen, urlretrieve, ProxyHandler, build_opener, install_opener
|
from urllib.request import Request, urlopen
|
||||||
from urllib.error import HTTPError
|
from urllib.error import HTTPError
|
||||||
|
|
||||||
|
|
||||||
@@ -105,8 +106,8 @@ class Popen(subprocess.Popen):
|
|||||||
"""Patched Popen to prevent opening cmd window on Windows platform."""
|
"""Patched Popen to prevent opening cmd window on Windows platform."""
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
if is_win:
|
||||||
startupinfo = kwargs.get('startupinfo')
|
startupinfo = kwargs.get('startupinfo')
|
||||||
if is_win or True:
|
|
||||||
try:
|
try:
|
||||||
startupinfo = startupinfo or subprocess.STARTUPINFO()
|
startupinfo = startupinfo or subprocess.STARTUPINFO()
|
||||||
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
||||||
@@ -193,11 +194,32 @@ class ApiKey(object):
|
|||||||
if key:
|
if key:
|
||||||
self._key = key
|
self._key = key
|
||||||
return self._key
|
return self._key
|
||||||
|
|
||||||
|
apiKeyFromVault = self.__readFromVaultCmd()
|
||||||
|
if apiKeyFromVault:
|
||||||
|
self._key = apiKeyFromVault
|
||||||
|
return self._key
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return self._key
|
return self._key
|
||||||
|
|
||||||
|
def __readFromVaultCmd(self):
|
||||||
|
apiKeyCmd = SETTINGS.get('api_key_vault_cmd')
|
||||||
|
if not apiKeyCmd:
|
||||||
|
return None
|
||||||
|
|
||||||
|
try:
|
||||||
|
p = Popen(apiKeyCmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
|
||||||
|
stdout, stderr = p.communicate()
|
||||||
|
if p.returncode == 0:
|
||||||
|
return stdout.strip()
|
||||||
|
log(WARNING, u(stderr))
|
||||||
|
except:
|
||||||
|
log(ERROR, traceback.format_exc())
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
def write(self, key):
|
def write(self, key):
|
||||||
global SETTINGS
|
global SETTINGS
|
||||||
self._key = key
|
self._key = key
|
||||||
@@ -416,10 +438,16 @@ def append_heartbeat(entity, timestamp, is_write, view, project, folders):
|
|||||||
'entity': entity,
|
'entity': entity,
|
||||||
'timestamp': timestamp,
|
'timestamp': timestamp,
|
||||||
'is_write': is_write,
|
'is_write': is_write,
|
||||||
'cursorpos': view.sel()[0].begin() if view.sel() else None,
|
|
||||||
'project': project,
|
'project': project,
|
||||||
'folders': folders,
|
'folders': folders,
|
||||||
|
'lines_in_file': view.rowcol(view.size())[0] + 1,
|
||||||
}
|
}
|
||||||
|
selections = view.sel()
|
||||||
|
if selections and len(selections) > 0:
|
||||||
|
rowcol = view.rowcol(selections[0].begin())
|
||||||
|
row, col = rowcol[0] + 1, rowcol[1] + 1
|
||||||
|
heartbeat['lineno'] = row
|
||||||
|
heartbeat['cursorpos'] = col
|
||||||
HEARTBEATS.put_nowait(heartbeat)
|
HEARTBEATS.put_nowait(heartbeat)
|
||||||
|
|
||||||
# make this heartbeat the LAST_HEARTBEAT
|
# make this heartbeat the LAST_HEARTBEAT
|
||||||
@@ -492,7 +520,8 @@ class SendHeartbeatsThread(threading.Thread):
|
|||||||
self.send_heartbeats()
|
self.send_heartbeats()
|
||||||
|
|
||||||
def build_heartbeat(self, entity=None, timestamp=None, is_write=None,
|
def build_heartbeat(self, entity=None, timestamp=None, is_write=None,
|
||||||
cursorpos=None, project=None, folders=None):
|
lineno=None, cursorpos=None, lines_in_file=None,
|
||||||
|
project=None, folders=None):
|
||||||
"""Returns a dict for passing to wakatime-cli as arguments."""
|
"""Returns a dict for passing to wakatime-cli as arguments."""
|
||||||
|
|
||||||
heartbeat = {
|
heartbeat = {
|
||||||
@@ -508,8 +537,12 @@ class SendHeartbeatsThread(threading.Thread):
|
|||||||
if project_name:
|
if project_name:
|
||||||
heartbeat['alternate_project'] = project_name
|
heartbeat['alternate_project'] = project_name
|
||||||
|
|
||||||
|
if lineno is not None:
|
||||||
|
heartbeat['lineno'] = lineno
|
||||||
if cursorpos is not None:
|
if cursorpos is not None:
|
||||||
heartbeat['cursorpos'] = '{0}'.format(cursorpos)
|
heartbeat['cursorpos'] = cursorpos
|
||||||
|
if lines_in_file is not None:
|
||||||
|
heartbeat['lines-in-file'] = lines_in_file
|
||||||
|
|
||||||
return heartbeat
|
return heartbeat
|
||||||
|
|
||||||
@@ -528,8 +561,12 @@ class SendHeartbeatsThread(threading.Thread):
|
|||||||
cmd.append('--write')
|
cmd.append('--write')
|
||||||
if heartbeat.get('alternate_project'):
|
if heartbeat.get('alternate_project'):
|
||||||
cmd.extend(['--alternate-project', heartbeat['alternate_project']])
|
cmd.extend(['--alternate-project', heartbeat['alternate_project']])
|
||||||
|
if heartbeat.get('lineno') is not None:
|
||||||
|
cmd.extend(['--lineno', '{0}'.format(heartbeat['lineno'])])
|
||||||
if heartbeat.get('cursorpos') is not None:
|
if heartbeat.get('cursorpos') is not None:
|
||||||
cmd.extend(['--cursorpos', heartbeat['cursorpos']])
|
cmd.extend(['--cursorpos', '{0}'.format(heartbeat['cursorpos'])])
|
||||||
|
if heartbeat.get('lines_in_file') is not None:
|
||||||
|
cmd.extend(['--lines-in-file', '{0}'.format(heartbeat['lines_in_file'])])
|
||||||
for pattern in self.ignore:
|
for pattern in self.ignore:
|
||||||
cmd.extend(['--exclude', pattern])
|
cmd.extend(['--exclude', pattern])
|
||||||
for pattern in self.include:
|
for pattern in self.include:
|
||||||
@@ -578,9 +615,7 @@ def plugin_loaded():
|
|||||||
log(INFO, 'Initializing WakaTime plugin v%s' % __version__)
|
log(INFO, 'Initializing WakaTime plugin v%s' % __version__)
|
||||||
update_status_bar('Initializing...')
|
update_status_bar('Initializing...')
|
||||||
|
|
||||||
if not isCliLatest():
|
UpdateCLI().start()
|
||||||
thread = DownloadCLI()
|
|
||||||
thread.start()
|
|
||||||
|
|
||||||
after_loaded()
|
after_loaded()
|
||||||
|
|
||||||
@@ -616,28 +651,34 @@ class WakatimeDashboardCommand(sublime_plugin.ApplicationCommand):
|
|||||||
webbrowser.open_new_tab('https://wakatime.com/dashboard')
|
webbrowser.open_new_tab('https://wakatime.com/dashboard')
|
||||||
|
|
||||||
|
|
||||||
class DownloadCLI(threading.Thread):
|
class UpdateCLI(threading.Thread):
|
||||||
"""Non-blocking thread for downloading latest wakatime-cli from GitHub.
|
"""Non-blocking thread for downloading latest wakatime-cli from GitHub.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
if isCliLatest():
|
||||||
|
return
|
||||||
|
|
||||||
log(INFO, 'Downloading wakatime-cli...')
|
log(INFO, 'Downloading wakatime-cli...')
|
||||||
|
|
||||||
|
if os.path.isdir(os.path.join(RESOURCES_FOLDER, 'wakatime-cli')):
|
||||||
|
shutil.rmtree(os.path.join(RESOURCES_FOLDER, 'wakatime-cli'))
|
||||||
|
|
||||||
if not os.path.exists(RESOURCES_FOLDER):
|
if not os.path.exists(RESOURCES_FOLDER):
|
||||||
os.makedirs(RESOURCES_FOLDER)
|
os.makedirs(RESOURCES_FOLDER)
|
||||||
|
|
||||||
if isCliInstalled():
|
|
||||||
try:
|
|
||||||
os.remove(getCliLocation())
|
|
||||||
except:
|
|
||||||
log(DEBUG, traceback.format_exc())
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
url = cliDownloadUrl()
|
url = cliDownloadUrl()
|
||||||
log(DEBUG, 'Downloading wakatime-cli from {url}'.format(url=url))
|
log(DEBUG, 'Downloading wakatime-cli from {url}'.format(url=url))
|
||||||
zip_file = os.path.join(RESOURCES_FOLDER, 'wakatime-cli.zip')
|
zip_file = os.path.join(RESOURCES_FOLDER, 'wakatime-cli.zip')
|
||||||
download(url, zip_file)
|
download(url, zip_file)
|
||||||
|
|
||||||
|
if isCliInstalled():
|
||||||
|
try:
|
||||||
|
os.remove(getCliLocation())
|
||||||
|
except:
|
||||||
|
log(DEBUG, traceback.format_exc())
|
||||||
|
|
||||||
log(INFO, 'Extracting wakatime-cli...')
|
log(INFO, 'Extracting wakatime-cli...')
|
||||||
with ZipFile(zip_file) as zf:
|
with ZipFile(zip_file) as zf:
|
||||||
zf.extractall(RESOURCES_FOLDER)
|
zf.extractall(RESOURCES_FOLDER)
|
||||||
@@ -652,6 +693,8 @@ class DownloadCLI(threading.Thread):
|
|||||||
except:
|
except:
|
||||||
log(DEBUG, traceback.format_exc())
|
log(DEBUG, traceback.format_exc())
|
||||||
|
|
||||||
|
createSymlink()
|
||||||
|
|
||||||
log(INFO, 'Finished extracting wakatime-cli.')
|
log(INFO, 'Finished extracting wakatime-cli.')
|
||||||
|
|
||||||
|
|
||||||
@@ -725,10 +768,7 @@ def getLatestCliVersion():
|
|||||||
try:
|
try:
|
||||||
configs = parseConfigFile(INTERNAL_CONFIG_FILE)
|
configs = parseConfigFile(INTERNAL_CONFIG_FILE)
|
||||||
if configs:
|
if configs:
|
||||||
if configs.has_option('internal', 'cli_version'):
|
last_modified, last_version = lastModifiedAndVersion(configs)
|
||||||
last_version = configs.get('internal', 'cli_version')
|
|
||||||
if last_version and configs.has_option('internal', 'cli_version_last_modified'):
|
|
||||||
last_modified = configs.get('internal', 'cli_version_last_modified')
|
|
||||||
except:
|
except:
|
||||||
log(DEBUG, traceback.format_exc())
|
log(DEBUG, traceback.format_exc())
|
||||||
|
|
||||||
@@ -762,6 +802,17 @@ def getLatestCliVersion():
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def lastModifiedAndVersion(configs):
|
||||||
|
last_modified, last_version = None, None
|
||||||
|
if configs.has_option('internal', 'cli_version'):
|
||||||
|
last_version = configs.get('internal', 'cli_version')
|
||||||
|
if last_version and configs.has_option('internal', 'cli_version_last_modified'):
|
||||||
|
last_modified = configs.get('internal', 'cli_version_last_modified')
|
||||||
|
if last_modified and last_version and extractVersion(last_version):
|
||||||
|
return last_modified, last_version
|
||||||
|
return None, None
|
||||||
|
|
||||||
|
|
||||||
def extractVersion(text):
|
def extractVersion(text):
|
||||||
pattern = re.compile(r"([0-9]+\.[0-9]+\.[0-9]+)")
|
pattern = re.compile(r"([0-9]+\.[0-9]+\.[0-9]+)")
|
||||||
match = pattern.search(text)
|
match = pattern.search(text)
|
||||||
@@ -818,34 +869,27 @@ def reportMissingPlatformSupport(osname, arch):
|
|||||||
|
|
||||||
|
|
||||||
def request(url, last_modified=None):
|
def request(url, last_modified=None):
|
||||||
|
req = Request(url)
|
||||||
|
req.add_header('User-Agent', 'github.com/wakatime/sublime-wakatime')
|
||||||
|
|
||||||
proxy = SETTINGS.get('proxy')
|
proxy = SETTINGS.get('proxy')
|
||||||
if proxy:
|
if proxy:
|
||||||
opener = build_opener(ProxyHandler({
|
req.set_proxy(proxy, 'https')
|
||||||
'http': proxy,
|
|
||||||
'https': proxy,
|
|
||||||
}))
|
|
||||||
else:
|
|
||||||
opener = build_opener()
|
|
||||||
|
|
||||||
headers = [('User-Agent', 'github.com/wakatime/sublime-wakatime')]
|
|
||||||
if last_modified:
|
if last_modified:
|
||||||
headers.append(('If-Modified-Since', last_modified))
|
req.add_header('If-Modified-Since', last_modified)
|
||||||
|
|
||||||
opener.addheaders = headers
|
|
||||||
|
|
||||||
install_opener(opener)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
resp = urlopen(url)
|
resp = urlopen(req)
|
||||||
headers = dict(resp.getheaders()) if is_py2 else resp.headers
|
headers = dict(resp.getheaders()) if is_py2 else resp.headers
|
||||||
return headers, resp.read(), resp.getcode()
|
return headers, resp.read(), resp.getcode()
|
||||||
except HTTPError as err:
|
except HTTPError as err:
|
||||||
if err.code == 304:
|
if err.code == 304:
|
||||||
return None, None, 304
|
return None, None, 304
|
||||||
if is_py2:
|
if is_py2:
|
||||||
ssl._create_default_https_context = ssl._create_unverified_context
|
with SSLCertVerificationDisabled():
|
||||||
try:
|
try:
|
||||||
resp = urlopen(url)
|
resp = urlopen(req)
|
||||||
headers = dict(resp.getheaders()) if is_py2 else resp.headers
|
headers = dict(resp.getheaders()) if is_py2 else resp.headers
|
||||||
return headers, resp.read(), resp.getcode()
|
return headers, resp.read(), resp.getcode()
|
||||||
except HTTPError as err2:
|
except HTTPError as err2:
|
||||||
@@ -860,7 +904,7 @@ def request(url, last_modified=None):
|
|||||||
raise
|
raise
|
||||||
except IOError:
|
except IOError:
|
||||||
if is_py2:
|
if is_py2:
|
||||||
ssl._create_default_https_context = ssl._create_unverified_context
|
with SSLCertVerificationDisabled():
|
||||||
try:
|
try:
|
||||||
resp = urlopen(url)
|
resp = urlopen(url)
|
||||||
headers = dict(resp.getheaders()) if is_py2 else resp.headers
|
headers = dict(resp.getheaders()) if is_py2 else resp.headers
|
||||||
@@ -876,22 +920,79 @@ def request(url, last_modified=None):
|
|||||||
|
|
||||||
|
|
||||||
def download(url, filePath):
|
def download(url, filePath):
|
||||||
|
req = Request(url)
|
||||||
|
req.add_header('User-Agent', 'github.com/wakatime/sublime-wakatime')
|
||||||
|
|
||||||
proxy = SETTINGS.get('proxy')
|
proxy = SETTINGS.get('proxy')
|
||||||
if proxy:
|
if proxy:
|
||||||
opener = build_opener(ProxyHandler({
|
req.set_proxy(proxy, 'https')
|
||||||
'http': proxy,
|
|
||||||
'https': proxy,
|
|
||||||
}))
|
|
||||||
else:
|
|
||||||
opener = build_opener()
|
|
||||||
opener.addheaders = [('User-Agent', 'github.com/wakatime/sublime-wakatime')]
|
|
||||||
|
|
||||||
install_opener(opener)
|
|
||||||
|
|
||||||
|
with open(filePath, 'wb') as fh:
|
||||||
try:
|
try:
|
||||||
urlretrieve(url, filePath)
|
resp = urlopen(req)
|
||||||
|
fh.write(resp.read())
|
||||||
|
except HTTPError as err:
|
||||||
|
if err.code == 304:
|
||||||
|
return None, None, 304
|
||||||
|
if is_py2:
|
||||||
|
with SSLCertVerificationDisabled():
|
||||||
|
try:
|
||||||
|
resp = urlopen(req)
|
||||||
|
fh.write(resp.read())
|
||||||
|
return
|
||||||
|
except HTTPError as err2:
|
||||||
|
log(DEBUG, err.read().decode())
|
||||||
|
log(DEBUG, err2.read().decode())
|
||||||
|
raise
|
||||||
|
except IOError:
|
||||||
|
raise
|
||||||
|
log(DEBUG, err.read().decode())
|
||||||
|
raise
|
||||||
except IOError:
|
except IOError:
|
||||||
if is_py2:
|
if is_py2:
|
||||||
ssl._create_default_https_context = ssl._create_unverified_context
|
with SSLCertVerificationDisabled():
|
||||||
urlretrieve(url, filePath)
|
try:
|
||||||
|
resp = urlopen(url)
|
||||||
|
fh.write(resp.read())
|
||||||
|
return
|
||||||
|
except HTTPError as err:
|
||||||
|
log(DEBUG, err.read().decode())
|
||||||
raise
|
raise
|
||||||
|
except IOError:
|
||||||
|
raise
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
def is_symlink(path):
|
||||||
|
try:
|
||||||
|
return os.is_symlink(path)
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def createSymlink():
|
||||||
|
link = os.path.join(RESOURCES_FOLDER, 'wakatime-cli')
|
||||||
|
if is_win:
|
||||||
|
link = link + '.exe'
|
||||||
|
elif os.path.exists(link) and is_symlink(link):
|
||||||
|
return # don't re-create symlink on Unix-like platforms
|
||||||
|
|
||||||
|
try:
|
||||||
|
os.symlink(getCliLocation(), link)
|
||||||
|
except:
|
||||||
|
try:
|
||||||
|
shutil.copy2(getCliLocation(), link)
|
||||||
|
if not is_win:
|
||||||
|
os.chmod(link, 509) # 755
|
||||||
|
except:
|
||||||
|
log(WARNING, traceback.format_exc())
|
||||||
|
|
||||||
|
|
||||||
|
class SSLCertVerificationDisabled(object):
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
self.original_context = ssl._create_default_https_context
|
||||||
|
ssl._create_default_https_context = ssl._create_unverified_context
|
||||||
|
|
||||||
|
def __exit__(self, *args, **kwargs):
|
||||||
|
ssl._create_default_https_context = self.original_context
|
||||||
|
Reference in New Issue
Block a user