<commit_before>include RVC::Util

# TODO windows tmp folder
def _local_vmrc_dir ver
  File.join("/tmp", "vmrc-#{Process::UID.eid}-#{ver}")
end

def _find_local_vmrc
  ver = $vim.serviceInstance.content.about.version
  path = File.join(_local_vmrc_dir(ver), 'plugins', 'vmware-vmrc')
  File.exists?(path) && path
end

VMRC = ENV['VMRC'] || _find_local_vmrc || search_path('vmrc')

def view *paths
  err "VMRC not found" unless VMRC
  paths.each do |path|
    obj = lookup path
    expect obj, VIM::VirtualMachine
    moref = obj._ref
    fork do
      ENV['https_proxy'] = ENV['HTTPS_PROXY'] = ''
      $stderr.reopen("#{ENV['HOME']||'.'}/.rvc-vmrc.log", "w")
      Process.setpgrp
      exec VMRC, '-M', moref, '-h', $opts[:host], '-u', $opts[:user], '-p', $opts[:password]
    end
  end
end<commit_msg>cache vmrc lookup<commit_after>include RVC::Util

# TODO windows tmp folder
def _local_vmrc_dir ver
  File.join("/tmp", "vmrc-#{Process::UID.eid}-#{ver}")
end

def _find_local_vmrc
  ver = $vim.serviceInstance.content.about.version
  path = File.join(_local_vmrc_dir(ver), 'plugins', 'vmware-vmrc')
  File.exists?(path) && path
end

def _find_vmrc
  @cached_vmrc ||= ENV['VMRC'] || _find_local_vmrc || search_path('vmrc')
end

def _clear_cached_vmrc
  @cached_vmrc = nil
end

def view *paths
  err "VMRC not found" unless _find_vmrc
  paths.each do |path|
    obj = lookup path
    expect obj, VIM::VirtualMachine
    moref = obj._ref
    fork do
      ENV['https_proxy'] = ENV['HTTPS_PROXY'] = ''
      $stderr.reopen("#{ENV['HOME']||'.'}/.rvc-vmrc.log", "w")
      Process.setpgrp
      exec _find_vmrc, '-M', moref, '-h', $opts[:host], '-u', $opts[:user], '-p', $opts[:password]
    end
  end
end
{'fraction_non_alphanumeric': 0.1745005875440658, 'fraction_numerical': 0.0, 'mean_word_length': 3.9077809798270895, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1967416', 'n_tokens_mistral': 651, 'n_tokens_neox': 665, 'n_words': 143}