2
0

Added a charm app for opening a single file with Pycharm

This commit is contained in:
XavierCLL 2016-04-20 10:50:47 -05:00
parent fe1bffee56
commit b35dab2954
3 changed files with 127 additions and 4 deletions

View File

@ -2,7 +2,7 @@
pkgname=pycharm-professional
pkgver=2016.1.2
pkgrel=2
pkgrel=3
pkgdesc="Powerful Python and Django IDE. Professional version."
arch=('any')
options=('!strip')
@ -15,7 +15,9 @@ depends=('java-runtime-common' 'java-runtime>=8' 'ttf-font' 'libxtst' 'libxslt')
source=(https://download.jetbrains.com/python/$pkgname-$pkgver-no-jdk.tar.gz
'pycharm-professional.desktop'
'pycharm-professional.install'
'pycharm')
'pycharm'
'charm.desktop'
'charm')
optdepends=('ipython2: For enhanced interactive Python shell v2 inside Pycharm'
'ipython: For enhanced interactive Python shell v3 inside Pycharm'
'openssh: For deployment and remote connections'
@ -34,8 +36,10 @@ optdepends=('ipython2: For enhanced interactive Python shell v2 inside Pycharm'
'python-tox: Python environments for testing tool with Python 3')
sha256sums=('5525914782ab7c0b2e4dafa228d053525494acbe4cb47e84e6a44be2c21a646d'
'016db1860a8b36d408c827f90aeb04b9d55cf21ea36788a9d8510cc54fae1c49'
'6442ec9f0690f743da697a2a65b0784017de501e7f39d5de0879153fbf85dc7a'
'ad59415f8ac2c623f9c61453caf70bf75b6b14db2f09807e4ea339a2dc740be9')
'438fbf23fa2020392df6360d39516a27dfadfa00654ae25f596ba04054121d4e'
'ad59415f8ac2c623f9c61453caf70bf75b6b14db2f09807e4ea339a2dc740be9'
'a90a2b645e733627fefe568ae82fc96716772c13b4431760a822c0c64b0596e9'
'0d6c311067aa925e4f73ab41f4955b033dbc00e0a65c940ceb27e6dae5bb7bb0')
package() {
# base
@ -56,6 +60,10 @@ package() {
# app file desktop
install -Dm 644 pycharm-professional.desktop $pkgdir/usr/share/applications/
# install charm application - for edit a single file in Pycharm
install -Dm 755 charm $pkgdir/opt/pycharm-professional/bin/
install -Dm 644 charm.desktop $pkgdir/usr/share/applications/
# delete some conflicts files for i686
if [[ $CARCH = 'i686' ]]; then
rm -f $pkgdir/opt/$pkgname/bin/libyjpagent-linux64.so

105
charm Executable file
View File

@ -0,0 +1,105 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import socket
import struct
import sys
import os
import time
# see com.intellij.idea.SocketLock for the server side of this interface
RUN_PATH = u'/opt/pycharm-professional/bin/pycharm.sh'
CONFIG_PATH = u'~/.PyCharm2016.1/config'
args = []
skip_next = False
for i, arg in enumerate(sys.argv[1:]):
if arg == '-h' or arg == '-?' or arg == '--help':
print(('Usage:\n' +
' {0} -h |-? | --help\n' +
' {0} [-l|--line line] file[:line]\n' +
' {0} diff <left> <right>\n' +
' {0} merge <local> <remote> [base] <merged>').format(sys.argv[0]))
exit(0)
elif arg == 'diff' and i == 0:
args.append(arg)
elif arg == 'merge' and i == 0:
args.append(arg)
elif arg == '-l' or arg == '--line':
args.append(arg)
skip_next = True
elif skip_next:
args.append(arg)
skip_next = False
else:
if ':' in arg:
file_path, line_number = arg.rsplit(':', 1)
if line_number.isdigit():
args.append('-l')
args.append(line_number)
args.append(os.path.abspath(file_path))
else:
args.append(os.path.abspath(arg))
else:
args.append(os.path.abspath(arg))
def launch_with_port(port):
found = False
s = socket.socket()
s.settimeout(0.3)
try:
s.connect(('127.0.0.1', port))
except:
return False
while True:
try:
path_len = struct.unpack(">h", s.recv(2))[0]
path = s.recv(path_len)
if os.path.abspath(path) == os.path.abspath(CONFIG_PATH):
found = True
break
except:
break
if found:
if args:
cmd = "activate " + os.getcwd() + "\0" + "\0".join(args)
encoded = struct.pack(">h", len(cmd)) + cmd
s.send(encoded)
time.sleep(0.5) # don't close socket immediately
return True
return False
port = -1
try:
f = open(os.path.join(CONFIG_PATH, 'port'))
port = int(f.read())
except Exception:
type, value, traceback = sys.exc_info()
print('No IDE instance has been found. New one will be started.')
port = -1
if port == -1:
# SocketLock actually allows up to 50 ports, but the checking takes too long
for port in range(6942, 6942 + 10):
if launch_with_port(port):
exit()
else:
if launch_with_port(port):
exit()
if sys.platform == "darwin":
# OS X: RUN_PATH is *.app path
if len(args):
args.insert(0, "--args")
os.execvp("open", ["-a", RUN_PATH] + args)
else:
# unix common
bin_dir, bin_file = os.path.split(RUN_PATH)
os.execv(RUN_PATH, [bin_file] + args)

10
charm.desktop Normal file
View File

@ -0,0 +1,10 @@
[Desktop Entry]
Name=Charm
Icon=pycharm
Exec=source ~/.bash_profile;/opt/pycharm-professional/bin/charm
MimeType=text/x-python;
NoDisplay=true
Type=Application
Terminal=false
StartupNotify=true
StartupWMClass=jetbrains-pycharm