From c9520fd4e3a562e30a1cdb50fa4ab9c72854076f Mon Sep 17 00:00:00 2001 From: Benjamin Attal Date: Sun, 1 Jun 2014 01:29:28 -0400 Subject: [PATCH] Add function to start parse servers in parser/__init__.py --- bitshift/parser/__init__.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/bitshift/parser/__init__.py b/bitshift/parser/__init__.py index 927b397..7979f09 100644 --- a/bitshift/parser/__init__.py +++ b/bitshift/parser/__init__.py @@ -2,13 +2,24 @@ import json import sys import socket import struct +import subprocess +from os import path from pygments import lexers as pgl, util from ..languages import LANGS 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): pass @@ -72,6 +83,22 @@ def _recv_data(server_socket): server_socket.close() 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): """ Dispatches the codelet to the correct parser based on its language. @@ -87,7 +114,7 @@ def parse(codelet): lang = _lang(codelet) source = codelet.code codelet.language = lang - server_socket_number = 5000 + lang + server_socket_number = 5001 + lang if lang == LANGS.index('Python'): parse_py(codelet)