Update and fix charm as a light editor
This commit is contained in:
parent
b30a138280
commit
109a24fa68
39
charm
39
charm
@ -1,16 +1,17 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
import struct
|
import struct
|
||||||
import sys
|
import sys
|
||||||
|
import traceback
|
||||||
|
|
||||||
# see com.intellij.idea.SocketLock for the server side of this interface
|
# See com.intellij.idea.SocketLock for the server side of this interface.
|
||||||
|
|
||||||
RUN_PATH = u'/opt/pycharm-professional/bin/pycharm.sh'
|
RUN_PATH = u'/opt/pycharm-professional/bin/pycharm.sh'
|
||||||
CONFIG_PATH = u'~/.PyCharm2019.2/config'
|
CONFIG_PATH = u'~/.config/JetBrains/PyCharm2020.1'
|
||||||
SYSTEM_PATH = u'~/.PyCharm2019.2/system'
|
SYSTEM_PATH = u'~/.cache/JetBrains/PyCharm2020.1'
|
||||||
|
|
||||||
|
|
||||||
def print_usage(cmd):
|
def print_usage(cmd):
|
||||||
@ -22,29 +23,29 @@ def print_usage(cmd):
|
|||||||
' {0} merge <local> <remote> [base] <merged>').format(cmd))
|
' {0} merge <local> <remote> [base] <merged>').format(cmd))
|
||||||
|
|
||||||
|
|
||||||
def write_to_sock(sock, str):
|
def write_to_sock(sock, data):
|
||||||
if sys.version_info[0] >= 3: str = str.encode('utf-8')
|
if sys.version_info[0] >= 3:
|
||||||
sock.send(struct.pack('>h', len(str)) + str)
|
data = data.encode('utf-8')
|
||||||
|
sock.send(struct.pack('>h', len(data)) + data)
|
||||||
|
|
||||||
|
|
||||||
def read_from_sock(sock):
|
def read_from_sock(sock):
|
||||||
len = struct.unpack('>h', sock.recv(2))[0]
|
length = struct.unpack('>h', sock.recv(2))[0]
|
||||||
return sock.recv(len).decode('utf-8')
|
return sock.recv(length).decode('utf-8')
|
||||||
|
|
||||||
|
|
||||||
def read_sequence_from_sock(sock):
|
def read_sequence_from_sock(sock):
|
||||||
result = []
|
result = []
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
str = read_from_sock(sock)
|
data = read_from_sock(sock)
|
||||||
if str == '---':
|
if data == '---':
|
||||||
break
|
break
|
||||||
result.append(str)
|
result.append(data)
|
||||||
|
|
||||||
except (socket.error, IOError) as e:
|
except (socket.error, IOError) as e:
|
||||||
print("I/O error({0}): {1} ({2})".format(e.errno, e.strerror, e))
|
print("I/O error({0}): {1} ({2})".format(e.errno, e.strerror, e))
|
||||||
traceback.print_exception(*sys.exc_info())
|
traceback.print_exception(*sys.exc_info())
|
||||||
return result
|
break
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
@ -90,7 +91,7 @@ def try_activate_instance(args):
|
|||||||
port = int(pf.read())
|
port = int(pf.read())
|
||||||
with open(token_path) as tf:
|
with open(token_path) as tf:
|
||||||
token = tf.read()
|
token = tf.read()
|
||||||
except (ValueError):
|
except ValueError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
s = socket.socket()
|
s = socket.socket()
|
||||||
@ -101,15 +102,15 @@ def try_activate_instance(args):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
paths = read_sequence_from_sock(s)
|
paths = read_sequence_from_sock(s)
|
||||||
found = CONFIG_PATH in paths
|
found = CONFIG_PATH in paths or os.path.realpath(CONFIG_PATH) in paths
|
||||||
|
|
||||||
if found:
|
if found:
|
||||||
write_to_sock(s, 'activate ' + token + '\0' + os.getcwd() + '\0' + '\0'.join(args))
|
write_to_sock(s, 'activate ' + token + '\0' + os.getcwd() + '\0' + '\0'.join(args))
|
||||||
|
|
||||||
s.settimeout(None)
|
s.settimeout(None)
|
||||||
response = read_sequence_from_sock(s)
|
response = read_sequence_from_sock(s)
|
||||||
if response[0] != 'ok':
|
if len(response) < 2 or response[0] != 'ok':
|
||||||
print('bad response: ' + response)
|
print('bad response: ' + str(response))
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
if len(response) > 2:
|
if len(response) > 2:
|
||||||
@ -124,7 +125,7 @@ def start_new_instance(args):
|
|||||||
if sys.platform == 'darwin':
|
if sys.platform == 'darwin':
|
||||||
if len(args) > 0:
|
if len(args) > 0:
|
||||||
args.insert(0, '--args')
|
args.insert(0, '--args')
|
||||||
os.execvp('/usr/bin/open', ['-a', RUN_PATH] + args)
|
os.execv('/usr/bin/open', ['open', '-na', RUN_PATH] + args)
|
||||||
else:
|
else:
|
||||||
bin_file = os.path.split(RUN_PATH)[1]
|
bin_file = os.path.split(RUN_PATH)[1]
|
||||||
os.execv(RUN_PATH, [bin_file] + args)
|
os.execv(RUN_PATH, [bin_file] + args)
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
Type=Application
|
Type=Application
|
||||||
Name=Charm
|
Name=Charm
|
||||||
Icon=pycharm
|
Icon=pycharm
|
||||||
Exec=/opt/pycharm-professional/bin/charm %f
|
Exec=/usr/bin/charm %f
|
||||||
MimeType=text/x-python;application/x-ipynb+json
|
MimeType=text/x-python;application/x-ipynb+json
|
||||||
NoDisplay=true
|
NoDisplay=true
|
||||||
Terminal=false
|
Terminal=false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user