<commit_before>#--
# Webyast Webservice framework
#
# Copyright (C) 2009, 2010 Novell, Inc. 
#   This library is free software; you can redistribute it and/or modify
# it only under the terms of version 2.1 of the GNU Lesser General Public
# License as published by the Free Software Foundation. 
#
#   This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 
# details. 
#
#   You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#++

require "rake"
require "English"

def make_rdoc_header(input_fname, output_fname)
  File.open(input_fname, "r") do |inf|
    File.open(output_fname, "w") do |out|
      out.puts "#--"
      inf.each_line { |l| out.printf "# %s", l }
      out.puts "#++"
    end
  end
end

def verbose(msg)
  # FIXME verbose seems to be on by default, but can use rake -q
  puts msg if RakeFileUtils.verbose
end

LIMIT = (ENV["LIMIT"] || 10).to_i
def license_report
  # FIXME: operate on distributed files, i.e. tarballs
  report = {:missing => [], :seen => [], :unneeded => [], :skipped => []}
  filenames = `git ls-files`.split "\n"
  filenames.each do |fn|
    # file name checks
    if fn =~ /\.yml\z/ || fn =~ /\.conf\z/ || fn =~ /\.xml\z/
      report[:skipped] << "#{fn}: skipped by name match (configuration file)"
      next
    elsif fn =~ /README/ 
      report[:skipped] << "#{fn}: skipped by name match (README file)"
      next
    elsif fn =~ /^db\//
      report[:skipped] << "#{fn}: skipped by name match (generated DB migration or schema)"
      next
    elsif fn =~ /licenses\//
      report[:skipped] << "#{fn}: skipped by name match (already contain license)"
      next
    elsif fn =~ /COPYING/
      report[:skipped] << "#{fn}: skipped by name match (already contain license)"
      next
    elsif fn =~ /\/rrdtool.*\.txt/
      report[:skipped] << "#{fn}: skipped by name match (rrdtool output is not licensed)"
      next
    elsif fn =~ /\.changes\z/
      report[:skipped] << "#{fn}: skipped by name match (changes file)"
      next<commit_msg>skip in license check all non-regular files<commit_after>#--
# Webyast Webservice framework
#
# Copyright (C) 2009, 2010 Novell, Inc. 
#   This library is free software; you can redistribute it and/or modify
# it only under the terms of version 2.1 of the GNU Lesser General Public
# License as published by the Free Software Foundation. 
#
#   This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 
# details. 
#
#   You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#++

require "rake"
require "English"

def make_rdoc_header(input_fname, output_fname)
  File.open(input_fname, "r") do |inf|
    File.open(output_fname, "w") do |out|
      out.puts "#--"
      inf.each_line { |l| out.printf "# %s", l }
      out.puts "#++"
    end
  end
end

def verbose(msg)
  # FIXME verbose seems to be on by default, but can use rake -q
  puts msg if RakeFileUtils.verbose
end

LIMIT = (ENV["LIMIT"] || 10).to_i
def license_report
  # FIXME: operate on distributed files, i.e. tarballs
  report = {:missing => [], :seen => [], :unneeded => [], :skipped => []}
  filenames = `git ls-files`.split "\n"
  filenames.each do |fn|
    next unless File.file? fn #skip all non-regular files e.g. symlinks
    # file name checks
    if fn =~ /\.yml\z/ || fn =~ /\.conf\z/ || fn =~ /\.xml\z/
      report[:skipped] << "#{fn}: skipped by name match (configuration file)"
      next
    elsif fn =~ /README/ 
      report[:skipped] << "#{fn}: skipped by name match (README file)"
      next
    elsif fn =~ /^db\//
      report[:skipped] << "#{fn}: skipped by name match (generated DB migration or schema)"
      next
    elsif fn =~ /licenses\//
      report[:skipped] << "#{fn}: skipped by name match (already contain license)"
      next
    elsif fn =~ /COPYING/
      report[:skipped] << "#{fn}: skipped by name match (already contain license)"
      next
    elsif fn =~ /\/rrdtool.*\.txt/
      report[:skipped] << "#{fn}: skipped by name match (rrdtool output is not licensed)"
      next
    elsif fn =~ /\.changes\z/
      report[:skipped] << "#{fn}: skipped by name match (changes file)"
      next
{'fraction_non_alphanumeric': 0.12945866554762903, 'fraction_numerical': 0.009651699538396978, 'mean_word_length': 3.032994923857868, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '6575296', 'n_tokens_mistral': 1553, 'n_tokens_neox': 1475, 'n_words': 585}