<commit_before>async = require 'async'
util = require 'util'
{spawn} = require 'child_process'

exec = (cmd, silent, opt, cb) ->
  child = spawn cmd, opt
  res = null
  child.stderr.on "data", (chunk) -> (res?=[]).push {type: 'stderr', message: String(chunk).trim()}
  child.stdout.on "data", (chunk) -> (res?=[]).push {type: 'stdout', message: String(chunk).trim()}
  unless silent
    util.pump child.stdout, process.stdout
    util.pump child.stderr, process.stderr

  child.on "exit", (code) -> cb? res, code

module.exports =
  # SSH stuff
  getRemote: (host, username, cb) ->
    remote = {}
    host = "#{username}@#{host}" if username?
    remote.sexec = (cmd, cb) -> exec 'ssh', [host, cmd], false, cb
    remote.exec = (cmd, cb) -> exec 'ssh', [host, cmd], true, cb
    remote.run = (cmds..., cb) -> async.mapSeries cmds, remote.exec, cb
    return remote

  # Local stuff
  getLocal: (cwd) ->
    opt = cwd: cwd
    local = {}
    local.sexec = (cmd, cb) -> exec 'sh', ['-c', cmd], false, cb
    local.exec = (cmd, cb) -> exec 'sh', ['-c', cmd], true, cb
    local.run = (cmds..., cb) -> async.mapSeries cmds, local.exec, cb
    return local<commit_msg>sanity<commit_after>async = require 'async'
util = require 'util'
{spawn} = require 'child_process'

exec = (cmd, opt, silent, cb) ->
  child = spawn cmd, opt
  res = null
  child.stderr.on "data", (chunk) -> (res?=[]).push {type: 'stderr', message: String(chunk).trim()}
  child.stdout.on "data", (chunk) -> (res?=[]).push {type: 'stdout', message: String(chunk).trim()}
  unless silent
    util.pump child.stdout, process.stdout
    util.pump child.stderr, process.stderr

  child.on "exit", (code) -> cb? res, code

module.exports =
  # SSH stuff
  getRemote: (host, username, cb) ->
    remote = {}
    host = "#{username}@#{host}" if username?
    remote.sexec = (cmd, cb) -> exec 'ssh', [host, cmd], false, cb
    remote.exec = (cmd, cb) -> exec 'ssh', [host, cmd], true, cb
    remote.run = (cmds..., cb) -> async.mapSeries cmds, remote.exec, cb
    return remote

  # Local stuff
  getLocal: (cwd) ->
    opt = cwd: cwd
    local = {}
    local.sexec = (cmd, cb) -> exec 'sh', ['-c', cmd], false, cb
    local.exec = (cmd, cb) -> exec 'sh', ['-c', cmd], true, cb
    local.run = (cmds..., cb) -> async.mapSeries cmds, local.exec, cb
    return local
{'fraction_non_alphanumeric': 0.1964670400689358, 'fraction_numerical': 0.0, 'mean_word_length': 3.1097345132743364, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4365725', 'n_tokens_mistral': 828, 'n_tokens_neox': 819, 'n_words': 247}