Skip to content

Commit ba4537e

Browse files
committed
More robust install of wakatime-cli on Windows
1 parent 945a441 commit ba4537e

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

scripts/install_cli.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,11 @@ def downloadCLI():
211211
os.remove(getCliLocation())
212212
except:
213213
log(traceback.format_exc())
214+
if isCliLinked():
215+
try:
216+
os.remove(getSymlinkLocation())
217+
except:
218+
log(traceback.format_exc())
214219

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

250255

256+
def getSymlinkLocation():
257+
binary = 'wakatime-cli{ext}'.format(
258+
ext='.exe' if is_win else '',
259+
)
260+
return os.path.join(getResourcesFolder(), binary)
261+
262+
251263
def architecture():
252264
arch = platform.machine() or platform.processor()
253265
if arch == 'armv7l':
@@ -263,8 +275,12 @@ def isCliInstalled():
263275
return os.path.exists(getCliLocation())
264276

265277

278+
def isCliLinked():
279+
return os.path.exists(getSymlinkLocation())
280+
281+
266282
def isCliLatest():
267-
if not isCliInstalled():
283+
if not isCliInstalled() or not isCliLinked():
268284
return False
269285

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

533549
try:
534550
os.symlink(getCliLocation(), link)
551+
if not isCliLinked():
552+
raise Exception('Link not created.')
535553
except:
554+
log(traceback.format_exc())
555+
log('Unable to create symlink, will copy instead.')
536556
try:
537557
shutil.copy2(getCliLocation(), link)
558+
if not isCliLinked():
559+
raise Exception('File not copied.')
538560
if not is_win:
539561
os.chmod(link, 509) # 755
540562
except:
541563
log(traceback.format_exc())
564+
log('Unable to use copy2, will use copyfile.')
565+
try:
566+
shutil.copyfile(getCliLocation(), link)
567+
if not isCliLinked():
568+
raise Exception('File not copied.')
569+
if not is_win:
570+
os.chmod(link, 509) # 755
571+
except:
572+
log(traceback.format_exc())
573+
log('Unable to install wakatime-cli.')
542574

543575

544576
class SSLCertVerificationDisabled(object):

0 commit comments

Comments
 (0)