Kaynağa Gözat

Add function to start parse servers in parser/__init__.py

tags/v1.0^2
Benjamin Attal 10 yıl önce
ebeveyn
işleme
c9520fd4e3
1 değiştirilmiş dosya ile 29 ekleme ve 2 silme
  1. +29
    -2
      bitshift/parser/__init__.py

+ 29
- 2
bitshift/parser/__init__.py Dosyayı Görüntüle

@@ -2,13 +2,24 @@ import json
import sys import sys
import socket import socket
import struct import struct
import subprocess


from os import path
from pygments import lexers as pgl, util from pygments import lexers as pgl, util


from ..languages import LANGS from ..languages import LANGS
from .python import parse_py from .python import parse_py


_all__ = ["parse"]
_all__ = ["parse", "start_parse_servers"]

PARSER_COMMANDS = [
('Java', ['mvn', '-f',
path.join(path.dirname(__file__), "../../parsers/java/pom.xml"),
'exec:java', '-Dexec.args="%d"']),
('Ruby', ['rake', '-f',
path.join(path.dirname(__file__), "../../parsers/ruby/Rakefile"),
"'start_server[%d]'"])
]


class UnsupportedFileError(Exception): class UnsupportedFileError(Exception):
pass pass
@@ -72,6 +83,22 @@ def _recv_data(server_socket):
server_socket.close() server_socket.close()
return ''.join(total_data) return ''.join(total_data)


def start_parse_servers():
"""
Starts all the parse servers for languages besides python.

:rtype: list
"""

procs = []

for (lang, cmd) in PARSER_COMMANDS:
procs.append(
subprocess.Popen(' '.join(cmd) % (5001 + LANGS.index(lang)),
shell=True))

return procs

def parse(codelet): def parse(codelet):
""" """
Dispatches the codelet to the correct parser based on its language. Dispatches the codelet to the correct parser based on its language.
@@ -87,7 +114,7 @@ def parse(codelet):
lang = _lang(codelet) lang = _lang(codelet)
source = codelet.code source = codelet.code
codelet.language = lang codelet.language = lang
server_socket_number = 5000 + lang
server_socket_number = 5001 + lang


if lang == LANGS.index('Python'): if lang == LANGS.index('Python'):
parse_py(codelet) parse_py(codelet)


Yükleniyor…
İptal
Kaydet