<commit_before># -*- coding: utf-8 -*-
'''
Simple RPC
Copyright (c) 2013, <NAME>
'''
import os
from simplerpc.base.SimpleRpcLogicBase import SimpleRpcLogicBase
from simplerpc.expose_api.javascript.JsTranslateUtil import JsTranslateUtil
from simplerpc.common.FileManager import FileManager
import subprocess
import sys

class NodeJsRunner(SimpleRpcLogicBase):
  def __post_init__(self):
    self.js_util = JsTranslateUtil(self.context)
    self.file_manager = FileManager(self.context)

  def setNodePath(self):
    NODE_PATH = 'NODE_PATH'
    path = self.js_util._getProjectJsPath()
    if NODE_PATH not in os.environ:
      os.environ[NODE_PATH] = path
    else:
      os.environ[NODE_PATH] += ':' + path

  def __printJasmineErrors(self, file_path, ret_val, out, err):
    if ret_val:
      path = self.file_manager.formatFilePath(file_path)
      self.log.w('Error running jasmine test return value %s:\n%s' %
                 (ret_val, path))
      self.log.w('Stdout:\n%s' % out)
      self.log.w('Stderr:\%s' % err)
    return ret_val

  def runJasmineTest(self, file_path):
    argv = [self.context.jasmine_node_command, file_path, '--matchall',
            '--captureExceptions', '--noColor']
    return self.__printJasmineErrors(file_path, *self.runNodeJs(argv, pipe=True))


  def runNodeJs(self, argv=None, pipe=False):
    self.setNodePath()
    #node_command = 'node'
    if not argv:
      argv = sys.argv[1:]
    argv = [self.context.node_command] + argv
    if pipe:
      p = subprocess.Popen(argv, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
      return p.wait(), p.stdout.read(), p.stderr.read()
    else:
      p = subprocess.Popen(argv)
      return p.wait()

def smokeTestModule():
  from simplerpc.context.SimpleRpcContext import SimpleRpcContext
  context = SimpleRpcContext('run node.js')
  NodeJsRunner(context)#.runNodeJs()

if __name__ == "__main__":
  smokeTestModule()<commit_msg>Fix jasmine command bug<commit_after># -*- coding: utf-8 -*-
'''
Simple RPC
Copyright (c) 2013, <NAME>
'''
import os
from simplerpc.base.SimpleRpcLogicBase import SimpleRpcLogicBase
from simplerpc.expose_api.javascript.JsTranslateUtil import JsTranslateUtil
from simplerpc.common.FileManager import FileManager
import subprocess
import sys

class NodeJsRunner(SimpleRpcLogicBase):
  def __post_init__(self):
    self.js_util = JsTranslateUtil(self.context)
    self.file_manager = FileManager(self.context)

  def setNodePath(self):
    NODE_PATH = 'NODE_PATH'
    path = self.js_util._getProjectJsPath()
    if NODE_PATH not in os.environ:
      os.environ[NODE_PATH] = path
    else:
      os.environ[NODE_PATH] += ':' + path

  def __printJasmineErrors(self, file_path, ret_val, out, err):
    if ret_val:
      path = self.file_manager.formatFilePath(file_path)
      self.log.w('Error running jasmine test return value %s:\n%s' %
                 (ret_val, path))
      self.log.w('Stdout:\n%s' % out)
      self.log.w('Stderr:\%s' % err)
    return ret_val

  def runJasmineTest(self, file_path):
    argv = [self.context.jasmine_node_command, file_path, '--matchall',
            '--captureExceptions', '--noColor']
    return self.__printJasmineErrors(file_path, *self.__runProcess(argv,
                                                                   pipe=True))

  def __runProcess(self, argv, pipe):
    if pipe:
      p = subprocess.Popen(argv, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
      return p.wait(), p.stdout.read(), p.stderr.read()
    else:
      p = subprocess.Popen(argv)
      return p.wait()

  def runNodeJs(self, argv=None, pipe=False):
    self.setNodePath()
    #node_command = 'node'
    if not argv:
      argv = sys.argv[1:]
    argv = [self.context.node_command] + argv
    return self.__runProcess(argv, pipe)

def smokeTestModule():
  from simplerpc.context.SimpleRpcContext import SimpleRpcContext
  context = SimpleRpcContext('run node.js')
  NodeJsRunner(context)#.runNodeJs()

if __name__ == "__main__":
  smokeTestModule()
{'fraction_non_alphanumeric': 0.12108297819002256, 'fraction_numerical': 0.0030082727500626723, 'mean_word_length': 3.4881889763779528, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6606114', 'n_tokens_mistral': 1353, 'n_tokens_neox': 1327, 'n_words': 275}