<commit_before>require_relative "erlang_dep"

module DVM
  class ErlangProject < Project
    attr_reader :rebar_config_path, :project_dir, :relpath, :libpath, :relname, :node
    def initialize(project_name, config)
      super
      @rebar_config_path = "#{project_dir}/rebar.config"
      reldir = case service['rel-type']
               when 'relx'
                 "_rel"
               when 'reltool'
                 "rel"
               when 'rebar3'
                 "_build/dev/rel"
               end

      @relname = service['rel-name'].nil? ? name : service['rel-name']
      @relpath = "#{@project_dir}/#{reldir}/#{relname}"
      @service_dir = "/var/opt/#{omnibus_project}/embedded/service/#{service['name']}"
      @libpath =  File.join(@relpath, "lib")
      @node = service['node']
    end
    def init_reltool

    end
    def init_rebar3

    end

    def parse_deps
      return @deps if @deps
      @deps = {}
      path = File.expand_path("../../../../parse.es", __FILE__)
      result = run_command("#{path} #{@rebar_config_path}")
      target_lib_dir = service['rel-type'] == 'rebar3' ? "_build/dev/lib" : "deps"
      eval(result.stdout).each do |name, data|
        @deps[name] = ErlangDep.new(name, File.join(project_dir, target_lib_dir) , data, self)
      end
    end

    def is_running?
      `ps waux | grep "host/.*#{name}.*/run_erl"`.split("\n").length > 2 ||
      `ps waux | grep "host/.*#{name}.*/beam.smp"`.split("\n").length > 2
    end

    def start(args, background)
      raise DVMArgumentError, "#{name} appears to be already running. Try 'dvm console #{relname}', or 'dvm stop #{relname}'" if is_running?
      # Ensure that our packaged installation isn't running, thereby preventing spewage of startup errors.
      disable_service
      if background
        run_command("bin/#{relname} start", "Starting #{name}", cwd: relpath, env: { "DEVVM" => "1" } )
      else
        exec "cd #{relpath} && bin/#{relname} console"
      end
    end<commit_msg>dvm: Don't close my file handles!<commit_after>require_relative "erlang_dep"

module DVM
  class ErlangProject < Project
    attr_reader :rebar_config_path, :project_dir, :relpath, :libpath, :relname, :node
    def initialize(project_name, config)
      super
      @rebar_config_path = "#{project_dir}/rebar.config"
      reldir = case service['rel-type']
               when 'relx'
                 "_rel"
               when 'reltool'
                 "rel"
               when 'rebar3'
                 "_build/dev/rel"
               end

      @relname = service['rel-name'].nil? ? name : service['rel-name']
      @relpath = "#{@project_dir}/#{reldir}/#{relname}"
      @service_dir = "/var/opt/#{omnibus_project}/embedded/service/#{service['name']}"
      @libpath =  File.join(@relpath, "lib")
      @node = service['node']
    end
    def init_reltool

    end
    def init_rebar3

    end

    def parse_deps
      return @deps if @deps
      @deps = {}
      path = File.expand_path("../../../../parse.es", __FILE__)
      result = run_command("#{path} #{@rebar_config_path}")
      target_lib_dir = service['rel-type'] == 'rebar3' ? "_build/dev/lib" : "deps"
      eval(result.stdout).each do |name, data|
        @deps[name] = ErlangDep.new(name, File.join(project_dir, target_lib_dir) , data, self)
      end
    end

    def is_running?
      `ps waux | grep "host/.*#{name}.*/run_erl"`.split("\n").length > 2 ||
      `ps waux | grep "host/.*#{name}.*/beam.smp"`.split("\n").length > 2
    end

    def start(args, background)
      raise DVMArgumentError, "#{name} appears to be already running. Try 'dvm console #{relname}', or 'dvm stop #{relname}'" if is_running?
      # Ensure that our packaged installation isn't running, thereby preventing spewage of startup errors.
      disable_service
      if background
        run_command("bin/#{relname} start", "Starting #{name}", cwd: relpath, env: { "DEVVM" => "1" } )
      else
        exec "cd #{relpath} && bin/#{relname} console", close_others: false
      end
    end
{'fraction_non_alphanumeric': 0.15162008409596833, 'fraction_numerical': 0.002968093000247341, 'mean_word_length': 2.5104166666666665, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '4533035', 'n_tokens_mistral': 1340, 'n_tokens_neox': 1322, 'n_words': 306}