File: mail_framework_maintainers.rb

package info (click to toggle)
kde-dev-scripts 4%3A18.08.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,496 kB
  • sloc: perl: 15,466; lisp: 5,627; sh: 4,157; python: 3,892; ruby: 2,158; makefile: 16; sed: 9
file content (144 lines) | stat: -rwxr-xr-x 3,736 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#! /usr/bin/env ruby

require 'optparse'
require 'yaml'

options = {
    :includePorting => false,
    :includeDead => false,
    :includeFlags => true
}
OptionParser.new do |opts|
    opts.banner = "Usage: #{File.basename($0)} [options]"

    opts.on("-p", "--[no-]porting", "Include porting aids") do |p|
        options[:includePorting] = p
    end

    opts.on("-d", "--[no-]dead", "Include dead frameworks (no more released)") do |d|
        options[:includeDead] = d
    end

    opts.on("-f", "--[no-]flags", "Include descriptive flags in the body (active by default)") do |f|
        options[:includeFlags] = f
    end
end.parse!

kdecommon = ENV["KDE_COMMON_SRC"]

if kdecommon.nil? then
    puts "ERROR: kde-common must be available"
    puts "Set the KDE_COMMON_SRC environment variable to point to your kde-common copy"
    exit 1
end

if not File.directory?("#{ENV["PWD"]}/frameworks") then
    puts "ERROR: this script must be executed from the parent directory of your frameworks/ prefix"
    exit 1
end

def kdewho(kdecommon, user)
    if kdecommon.nil? then
        return true
    end

    if user.nil? then
        return { :name => "No maintainer", :email => "kde-frameworks-devel@kde.org" }
    end

    userFound = false

    f = File.open("#{kdecommon}/accounts", "r")
    f.each_line do |line|
        match = line.match(/^#{user}\s+(.*)\s+(\S+)\s*$/)
        if match then
            return { :name => match[1].squeeze(" ").chomp(" "), :email => match[2] }
        end
    end
    f.close

    return nil
end

frameworksMap = {}

Dir.glob("frameworks/*/metainfo.yaml").each do |file|
    framework = file.match(/frameworks\/(.*?)\/metainfo.yaml/)[1]
    yaml = YAML.load_file(file)

    if not yaml.has_key? "maintainer" then
        puts "#{file} has no maintainer property!!"
        exit 1
    end

    if yaml["portingAid"] and not options[:includePorting] then
        next
    elsif yaml["deprecated"] and not yaml["release"] and not options[:includeDead] then
        next
    end

    maintainer = yaml["maintainer"]

    description = framework
    if options[:includeFlags] then
        flags = []
        if yaml["portingAid"] then
            flags << "porting aid"
        elsif not yaml["release"] then
            if yaml["deprecated"] then
                flags << "no more released"
            else
                flags << "upcoming"
            end
        elsif yaml["deprecated"] then
            flags << "deprecated"
        end

        if not flags.empty? then
            description = description + " (" + flags.join(", ") + ")"
        end
    end

    if not frameworksMap.has_key? maintainer then
        frameworksMap[maintainer] = [description]
    else
        frameworksMap[maintainer] << description
    end
end

tempFile = "/tmp/mail_framework_frameworksMap_body.txt"
body = File.open(tempFile, "w")
args = "--msg #{tempFile}"

contacts = {}
frameworksMap.keys.each do |maintainer|
    contacts[maintainer] = kdewho(kdecommon, maintainer)
end

maintainers = frameworksMap.keys
if maintainers.include? nil then
    maintainers.delete nil
    maintainers.sort! { |a, b| contacts[a][:name] <=> contacts[b][:name] }
    maintainers << nil
else
    maintainers.sort! { |a, b| contacts[a][:name] <=> contacts[b][:name] }
end

maintainers.each do |maintainer|
    contact = contacts[maintainer]
    if maintainer.nil? then
        args = args + " \"#{contact[:email]}\""
    else
        args = args + " \"#{contact[:name]} <#{contact[:email]}>\""
    end

    body.write("#{contact[:name]}:\n")
    frameworksMap[maintainer].sort.each do |framework|
        body.write(" - #{framework}\n")
    end
    body.write("\n")
end
body.close

system "kmail #{args}"
File.delete tempFile