appstream_mkindex.rb 2.15 KB
Newer Older
Harald Sitter's avatar
Harald Sitter committed
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
#!/usr/bin/env ruby
#
# Copyright 2018 Harld Sitter <sitter@kde.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License or (at your option) version 3 or any later version
# accepted by the membership of KDE e.V. (or its successor approved
# by the membership of KDE e.V.), which shall act as a proxy
# defined in Section 14 of version 3 of the license.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

require 'json'

Dir.chdir(__dir__) if Dir.pwd != __dir__

appdata_dir = '../appdata'

27 28 29 30 31 32 33
unmaintained = JSON.load(File.open("unmaintained.json"))
unmaintained_ids = []
unmaintained.each do |app|
    unmaintained_ids << "org.kde.#{app}"
    unmaintained_ids << "org.kde.#{app}.desktop"
end

Harald Sitter's avatar
Harald Sitter committed
34
index ||= {}
35
puts 'ignored metainfo files without Categories:'
Harald Sitter's avatar
Harald Sitter committed
36
Dir.glob("#{appdata_dir}/*.json") do |file|
37
  next if File.symlink?(file) # Don't include compat symlinks in index.
Harald Sitter's avatar
Harald Sitter committed
38 39
  data = JSON.parse(File.read(file))
  next unless data['Categories'] # not appdata
40
  raise "no x-kde-id: #{file}" unless data['X-KDE-ID']
41
  id = data.fetch('X-KDE-ID')
42 43 44 45
  if unmaintained_ids.include?(id)
    index['unmaintained'] ||= []
    index['unmaintained'] << id
  else
46 47
    if not data.fetch('Categories').any?
      print data['Name']['C'] + "\n"
48
      print data['ID'] + "\n"
49
    end
50 51 52 53 54 55
    data.fetch('Categories').uniq.each do |category|
      # NB: category is the Name value. Should l10n for categoresi get implemented
      #   this maybe need rethinking as mapping by name is somewhat fragile.
      index[category] ||= []
      index[category] << id
    end
Harald Sitter's avatar
Harald Sitter committed
56 57 58 59 60 61 62
  end
end

index.values.each(&:sort!)

# Old-ish structure
# Hash of categories and their apps as array inside
63
File.write("../index.json", JSON.pretty_generate(index))