class OhlohScm::PyClient

Public Instance Methods

shutdown() click to toggle source
# File lib/ohloh_scm/py_bridge/py_client.rb, line 11
def shutdown
  send_command('QUIT')
  [@stdin, @stdout, @stderr].reject(&:closed?).each(&:close)
  Process.waitpid(@pid, Process::WNOHANG)
end
start() click to toggle source
# File lib/ohloh_scm/py_bridge/py_client.rb, line 5
def start
  @stdin, @stdout, @stderr, wait_thr = Open3.popen3 "python #{@py_script}"
  @pid = wait_thr[:pid]
  open_repository
end

Private Instance Methods

raise_subprocess_error(flag) click to toggle source
# File lib/ohloh_scm/py_bridge/py_client.rb, line 38
def raise_subprocess_error(flag)
  return unless flag == 'E'

  error = @stdout.read(size)
  raise "Exception in server process\n#{error}"
end
send_command(cmd) click to toggle source
# File lib/ohloh_scm/py_bridge/py_client.rb, line 19
def send_command(cmd)
  # send the command
  @stdin.puts cmd
  @stdin.flush
  return if cmd == 'QUIT'

  # get status on stderr, first letter indicates state,
  # remaing value indicates length of the file content
  status = @stderr.read(10)
  flag = status[0, 1]
  size = status[1, 9].to_i
  return if flag == 'F'

  raise_subprocess_error(flag)

  # read content from stdout
  @stdout.read(size)
end