Last active
May 20, 2019 14:44
-
-
Save hellcp/931a8d0f097db6c748aab22d82557f54 to your computer and use it in GitHub Desktop.
Testing script for metadata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'builder' | |
require 'optparse' | |
require 'inifile' | |
options = {} | |
OptionParser.new do |parser| | |
parser.banner = "Usage: y2metainfo [options]" | |
parser.on("-h", "--help", "Show this help message") do || | |
puts parser | |
end | |
parser.on("-f", "--file FILEPATH", "The desktop file of the module") do |v| | |
options[:file] = v | |
end | |
parser.on("-l", "--license LICENSE", "The license of the module") do |v| | |
options[:license] = v | |
end | |
parser.on("-o", "--output DIRECTORY", "The output directory") do |v| | |
options[:output] = v | |
end | |
end.parse! | |
def metainfo_gen(desktop, license) | |
output = '' | |
xml = ::Builder::XmlMarkup.new(:target => output, :indent => 2) | |
file = IniFile.load(desktop, :comment => nil) | |
data = file["Desktop Entry"] | |
xml.instruct! | |
xml.component('type' => 'addon','xmlns' => 'https://specifications.freedesktop.org/metainfo/1.0') do | |
xml.id File.basename(desktop) | |
xml.launchable(File.basename(desktop), 'type' => 'desktop-id') | |
xml._name data["Name"] | |
xml._summary data["GenericName"] | |
xml.extends 'YaST2.desktop' | |
xml.metadata_license 'CC0-1.0' | |
xml.project_license license if license | |
categories = data["Categories"].split(';') | |
xml.categories do | |
categories.each do |category| | |
xml.category category | |
end | |
end | |
xml.url('https://yast.opensuse.org', 'type' => 'homepage') | |
xml.url('https://bugzilla.opensuse.org', 'type' => 'bugtracker') | |
xml.developer_name 'YaST Team' | |
end | |
output | |
end | |
if options[:output] | |
filename = options[:output] + File.basename(options[:file], ".desktop") + ".metainfo.xml" | |
out_file = File.new(filename, "w") | |
out_file.puts(metainfo_gen(options[:file], options[:license])) | |
out_file.close | |
else | |
puts metainfo_gen(options[:file], options[:license]) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment