<commit_before>require 'treetop'
require 'policy'

module Dgh  
  extend self

  # Parse input with the policy grammar
  #
  # @param input [String] apt-cache policy input
  # @return a list of hashes with info on packages
  def parse(input)
    @parser ||= PolicyParser.new
    @parser.parse input
  end

  # Find downgradable packages
  #
  # @param paca
  def find_downgradable(packages)
    packages.select do |pkg|
      pkg[:versions].any? do |ver|
        ver[:current] && ver[:sources].length == 1 && ver[:sources][0][:source] == '/var/lib/dpkg/status'
      end
    end
  end

  class << self
    def run
      ARGV.each do |f|
        puts "Parsing #{f}:"
        find_downgradable(parse(File.open(f).read).content).each do |pkg|
          puts "  " + pkg[:name]
        end
      end
    end
  end
end<commit_msg>Output usage instructions if no input given<commit_after>require 'treetop'
require 'policy'

module Dgh  
  extend self

  # Parse input with the policy grammar
  #
  # @param input [String] apt-cache policy input
  # @return a list of hashes with info on packages
  def parse(input)
    @parser ||= PolicyParser.new
    @parser.parse input
  end

  # Find downgradable packages
  #
  # @param paca
  def find_downgradable(packages)
    packages.select do |pkg|
      pkg[:versions].any? do |ver|
        ver[:current] && ver[:sources].length == 1 && ver[:sources][0][:source] == '/var/lib/dpkg/status'
      end
    end
  end

  class << self
    def run
      if ARGV.empty? || ARGV.any? {|a| !File.exist? a}
        puts "dgh, the Debian/Ubuntu Downgrade Helper"
        puts "Usage: dgh <apt-cache policy listing>"
        puts "You can generate a policy listing by running e.g."
        puts "`dpkg --get-selections|egrep '\binstall'|awk '{print $1}'|\\"
        puts "  xargs env LANG=C apt-cache policy`"
      else
        ARGV.each do |f|
          puts "Parsing #{f}:"
          find_downgradable(parse(File.open(f).read).content).each do |pkg|
            puts "  " + pkg[:name]
          end
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.1204644412191582, 'fraction_numerical': 0.0024189646831156266, 'mean_word_length': 2.4466666666666668, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 4, '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': '1483425', 'n_tokens_mistral': 692, 'n_tokens_neox': 678, 'n_words': 201}