Skip to content

Commit

Permalink
More robust install of wakatime-cli on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhamlett committed Oct 24, 2023
1 parent 945a441 commit ba4537e
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion scripts/install_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ def downloadCLI():
os.remove(getCliLocation())
except:
log(traceback.format_exc())
if isCliLinked():
try:
os.remove(getSymlinkLocation())
except:
log(traceback.format_exc())

log('Extracting wakatime-cli...')
with contextlib.closing(ZipFile(zip_file)) as zf:
Expand Down Expand Up @@ -248,6 +253,13 @@ def getCliLocation():
return WAKATIME_CLI_LOCATION


def getSymlinkLocation():
binary = 'wakatime-cli{ext}'.format(
ext='.exe' if is_win else '',
)
return os.path.join(getResourcesFolder(), binary)


def architecture():
arch = platform.machine() or platform.processor()
if arch == 'armv7l':
Expand All @@ -263,8 +275,12 @@ def isCliInstalled():
return os.path.exists(getCliLocation())


def isCliLinked():
return os.path.exists(getSymlinkLocation())


def isCliLatest():
if not isCliInstalled():
if not isCliInstalled() or not isCliLinked():
return False

args = [getCliLocation(), '--version']
Expand Down Expand Up @@ -532,13 +548,29 @@ def createSymlink():

try:
os.symlink(getCliLocation(), link)
if not isCliLinked():
raise Exception('Link not created.')
except:
log(traceback.format_exc())
log('Unable to create symlink, will copy instead.')
try:
shutil.copy2(getCliLocation(), link)
if not isCliLinked():
raise Exception('File not copied.')
if not is_win:
os.chmod(link, 509) # 755
except:
log(traceback.format_exc())
log('Unable to use copy2, will use copyfile.')
try:
shutil.copyfile(getCliLocation(), link)
if not isCliLinked():
raise Exception('File not copied.')
if not is_win:
os.chmod(link, 509) # 755
except:
log(traceback.format_exc())
log('Unable to install wakatime-cli.')


class SSLCertVerificationDisabled(object):
Expand Down

0 comments on commit ba4537e

Please sign in to comment.