@@ -57,7 +57,10 @@ def start(cls):
57
57
executable_path = settings .get (SETTINGS_EXECUTABLE )
58
58
executable_path = os .path .expanduser (os .path .expandvars (executable_path ))
59
59
60
- if not os .path .exists (executable_path ):
60
+ if not os .path .exists (executable_path ) and not fixed_wrong_location (
61
+ executable_path
62
+ ):
63
+
61
64
if not confirm_automatic_download (executable_path ):
62
65
notify (
63
66
"no binary found, and automatic updates disabled. JSONComma will not work"
@@ -365,15 +368,21 @@ def get_default_executable_path(cls, *, expand_vars):
365
368
expand_vars , bool
366
369
), "expand_vars should be a boolean, got {}" .format (type (expand_vars ))
367
370
368
- path = {
369
- # sublime.platform() -> path for executable
370
- "windows" : "%APPDATA%\\ jsoncomma\\ jsoncomma.exe" ,
371
- "linux" : "~/.config/jsoncomma/jsoncomma" ,
372
- "osx" : "~/Library/Application Support/jsoncomma/jsoncomma" ,
373
- }[sublime .platform ()]
371
+ path = None
372
+ platform = sublime .platform ()
373
+ if platform == "windows" :
374
+ path = "%APPDATA%\\ jsoncomma\\ jsoncomma.exe"
375
+ elif platform == "osx" :
376
+ path = "~/Library/Application Support/jsoncomma/jsoncomma"
377
+ elif platform == "linux" :
378
+ xdg_data_home = os .environ .get ("XDG_DATA_HOME" , "" ) or "~/.local/share"
379
+ path = os .path .join (xdg_data_home , "jsoncomma" , "jsoncomma" )
380
+
381
+ assert path is not None , "unknown platform {!r}" .format (platform )
374
382
375
383
if expand_vars :
376
384
return os .path .expandvars (os .path .expanduser (path ))
385
+
377
386
return path
378
387
379
388
@@ -429,3 +438,45 @@ def kill_nicely(process, *, timeout=1):
429
438
except subprocess .TimeoutExpired :
430
439
process .kill ()
431
440
return process .poll ()
441
+
442
+
443
+ def fixed_wrong_location (new_path ):
444
+ """ I stuffed the location of the binary executable initially, and @WillMoggridge
445
+ pointed me towards the relevant document and paths I should use.
446
+
447
+ So, this is an automatic fix for my mistake
448
+
449
+ This returns True if it did fix anything
450
+ """
451
+ if sublime .platform () != "linux" :
452
+ return False
453
+
454
+ old_path = os .path .expanduser ("~/.config/jsoncomma/jsoncomma" )
455
+
456
+ if not os .path .isfile (old_path ):
457
+ return False
458
+
459
+ # we know what new_path doesn't exists because otherwise, this fixup wouldn't have been
460
+ # called
461
+
462
+ try :
463
+ os .makedirs (os .path .dirname (new_path ), exist_ok = True )
464
+ os .rename (old_path , new_path )
465
+ # we shouldn't have any other files in old_path's folder. If we do, rmdir is going
466
+ # to fail (which we want it to, don't want to remove files we haven't put there)
467
+ os .rmdir (os .path .dirname (old_path ))
468
+ except OSError :
469
+ import traceback
470
+
471
+ sublime .error_message (
472
+ "Failed trying to automatically move {} to {}. Accept the automatic update"
473
+ "that is going to show up next, and then delete the folder "
474
+ "~/.config/jsoncomma. More details about the error in the console" .format (
475
+ old_path , new_path
476
+ )
477
+ )
478
+ print ("JSONComma: automatic fixup error:" )
479
+ traceback .print_exc ()
480
+ return False
481
+
482
+ return True
0 commit comments