File indexing completed on 2024-04-14 05:35:05

0001 #! /usr/bin/env ruby
0002 
0003 require 'optparse'
0004 require 'yaml'
0005 
0006 options = {
0007     :includePorting => false,
0008     :includeDead => false,
0009     :includeFlags => true
0010 }
0011 OptionParser.new do |opts|
0012     opts.banner = "Usage: #{File.basename($0)} [options]"
0013 
0014     opts.on("-p", "--[no-]porting", "Include porting aids") do |p|
0015         options[:includePorting] = p
0016     end
0017 
0018     opts.on("-d", "--[no-]dead", "Include dead frameworks (no more released)") do |d|
0019         options[:includeDead] = d
0020     end
0021 
0022     opts.on("-f", "--[no-]flags", "Include descriptive flags in the body (active by default)") do |f|
0023         options[:includeFlags] = f
0024     end
0025 end.parse!
0026 
0027 kdecommon = ENV["KDE_COMMON_SRC"]
0028 
0029 if kdecommon.nil? then
0030     puts "ERROR: kde-common must be available"
0031     puts "Set the KDE_COMMON_SRC environment variable to point to your kde-common copy"
0032     exit 1
0033 end
0034 
0035 if not File.directory?("#{ENV["PWD"]}/frameworks") then
0036     puts "ERROR: this script must be executed from the parent directory of your frameworks/ prefix"
0037     exit 1
0038 end
0039 
0040 def kdewho(kdecommon, user)
0041     if kdecommon.nil? then
0042         return true
0043     end
0044 
0045     if user.nil? then
0046         return { :name => "No maintainer", :email => "kde-frameworks-devel@kde.org" }
0047     end
0048 
0049     userFound = false
0050 
0051     f = File.open("#{kdecommon}/accounts", "r")
0052     f.each_line do |line|
0053         match = line.match(/^#{user}\s+(.*)\s+(\S+)\s*$/)
0054         if match then
0055             return { :name => match[1].squeeze(" ").chomp(" "), :email => match[2] }
0056         end
0057     end
0058     f.close
0059 
0060     return nil
0061 end
0062 
0063 frameworksMap = {}
0064 
0065 Dir.glob("frameworks/*/metainfo.yaml").each do |file|
0066     framework = file.match(/frameworks\/(.*?)\/metainfo.yaml/)[1]
0067     yaml = YAML.load_file(file)
0068 
0069     if not yaml.has_key? "maintainer" then
0070         puts "#{file} has no maintainer property!!"
0071         exit 1
0072     end
0073 
0074     if yaml["portingAid"] and not options[:includePorting] then
0075         next
0076     elsif yaml["deprecated"] and not yaml["release"] and not options[:includeDead] then
0077         next
0078     end
0079 
0080     maintainer = yaml["maintainer"]
0081 
0082     description = framework
0083     if options[:includeFlags] then
0084         flags = []
0085         if yaml["portingAid"] then
0086             flags << "porting aid"
0087         elsif not yaml["release"] then
0088             if yaml["deprecated"] then
0089                 flags << "no more released"
0090             else
0091                 flags << "upcoming"
0092             end
0093         elsif yaml["deprecated"] then
0094             flags << "deprecated"
0095         end
0096 
0097         if not flags.empty? then
0098             description = description + " (" + flags.join(", ") + ")"
0099         end
0100     end
0101 
0102     if not frameworksMap.has_key? maintainer then
0103         frameworksMap[maintainer] = [description]
0104     else
0105         frameworksMap[maintainer] << description
0106     end
0107 end
0108 
0109 tempFile = "/tmp/mail_framework_frameworksMap_body.txt"
0110 body = File.open(tempFile, "w")
0111 args = "--msg #{tempFile}"
0112 
0113 contacts = {}
0114 frameworksMap.keys.each do |maintainer|
0115     contacts[maintainer] = kdewho(kdecommon, maintainer)
0116 end
0117 
0118 maintainers = frameworksMap.keys
0119 if maintainers.include? nil then
0120     maintainers.delete nil
0121     maintainers.sort! { |a, b| contacts[a][:name] <=> contacts[b][:name] }
0122     maintainers << nil
0123 else
0124     maintainers.sort! { |a, b| contacts[a][:name] <=> contacts[b][:name] }
0125 end
0126 
0127 maintainers.each do |maintainer|
0128     contact = contacts[maintainer]
0129     if maintainer.nil? then
0130         args = args + " \"#{contact[:email]}\""
0131     else
0132         args = args + " \"#{contact[:name]} <#{contact[:email]}>\""
0133     end
0134 
0135     body.write("#{contact[:name]}:\n")
0136     frameworksMap[maintainer].sort.each do |framework|
0137         body.write(" - #{framework}\n")
0138     end
0139     body.write("\n")
0140 end
0141 body.close
0142 
0143 system "kmail #{args}"
0144 File.delete tempFile