File indexing completed on 2024-03-24 05:44:44

0001 #! /usr/bin/env ruby
0002 
0003 require 'yaml'
0004 
0005 if ARGV.length < 1
0006     puts "We need at least one argument"
0007     puts "Usage: ruby metainfo.yaml\n"
0008     exit
0009 end
0010 
0011 kdecommon = ENV["KDE_COMMON_SRC"]
0012 
0013 def kdewho(kdecommon, user)
0014     if kdecommon.nil? then
0015         return true
0016     end
0017 
0018     userFound = false
0019 
0020     f = File.open("#{kdecommon}/accounts", "r")
0021     f.each_line do |line|
0022       if line.match(/^#{user} /) then
0023           userFound = true
0024           break
0025       end
0026     end
0027     f.close
0028 
0029     return userFound
0030 end
0031 
0032 
0033 rules = {
0034     "description" => nil,
0035     "tier" => [1, 2, 3, 4],
0036     "type" => ["functional", "integration", "solution"],
0037     "portingAid" => [true, false],
0038     "deprecated" => [true, false],
0039     "release" => [true, false],
0040 
0041     "platforms" => lambda { |file, platforms|
0042         if not platforms.is_a? Array then
0043             return false
0044         end
0045 
0046         platforms.each do |platform|
0047             if not platform.is_a? Hash then
0048                 return false
0049             end
0050 
0051             if not ["All", "MacOSX", "Windows", "Linux"].include? platform["name"] then
0052                 return false
0053             end
0054         end
0055 
0056         return true
0057     },
0058 
0059     "maintainer" => lambda { |file, maintainer|
0060         if maintainer.nil? then
0061             return true
0062         elsif not maintainer.is_a? String then
0063             return false
0064         else
0065             return kdewho(kdecommon, maintainer)
0066         end
0067     }
0068 }
0069 
0070 errorFound = false
0071 
0072 ARGV.each do |file|
0073     yaml = YAML.load_file(file)
0074 
0075     rules.keys.each do |property|
0076         if not yaml.has_key? property then
0077             puts "#{file} is missing #{property}"
0078             errorFound = true
0079             next
0080         end
0081 
0082         rule = rules[property]
0083         if ((rule.is_a? Array and not rule.include? yaml[property]) or (rule.is_a? Proc and not rule.call file, yaml[property])) then
0084             puts "#{file} has invalid #{property}: #{yaml[property]}"
0085             errorFound = true
0086         end
0087     end
0088 end
0089 
0090 if kdecommon.nil? then
0091     if errorFound then
0092         puts
0093     end
0094     puts "WARNING: kde-common wasn't available, couldn't validate maintainer fields content"
0095     puts "Set the KDE_COMMON_SRC environment variable to point to your kde-common copy"
0096 end
0097 
0098 exit (errorFound ? 1 : 0)