Commit 96228190 authored by Jonathan Riddell's avatar Jonathan Riddell 🏄

option of date off

parent 44833e29
...@@ -25,6 +25,7 @@ require_relative 'lib/appstream-metainfo-release-update' ...@@ -25,6 +25,7 @@ require_relative 'lib/appstream-metainfo-release-update'
@date = "today" @date = "today"
@releases_to_show = 0 @releases_to_show = 0
@dateoff = false # double negative but I can't work out a nicer way
parser = OptionParser.new do |opts| parser = OptionParser.new do |opts|
opts.banner = <<-EOS opts.banner = <<-EOS
...@@ -38,6 +39,10 @@ Usage: appstream-metainfo-release-update 'org.foo.metainfo.xml' ...@@ -38,6 +39,10 @@ Usage: appstream-metainfo-release-update 'org.foo.metainfo.xml'
"date to use 'today' 'next Thursday' '2018-01-01' etc") do |date_string| "date to use 'today' 'next Thursday' '2018-01-01' etc") do |date_string|
@date = date_string || "today" @date = date_string || "today"
end end
opts.on("-o", "--dateoff DATE_OFF",
"do not include a date") do |date_off|
@dateoff = date_off
end
opts.on("-r", "--releases_to_show RELEASES_TO_SHOW", opts.on("-r", "--releases_to_show RELEASES_TO_SHOW",
"how many releases to include in file (default infinite)") do |releases_to_show| "how many releases to include in file (default infinite)") do |releases_to_show|
@releases_to_show = releases_to_show.to_i || 0 @releases_to_show = releases_to_show.to_i || 0
...@@ -48,6 +53,6 @@ parser.parse! ...@@ -48,6 +53,6 @@ parser.parse!
abort parser.help if ARGV.empty? abort parser.help if ARGV.empty?
file_name = ARGV[0] file_name = ARGV[0]
updater = MetaInfoUpdater.new(file_name, @version, @date, @releases_to_show) updater = MetaInfoUpdater.new(file_name, @version, @date, @dateoff, @releases_to_show)
updater.open_file updater.open_file
updater.save_file updater.save_file
...@@ -30,11 +30,13 @@ class MetaInfoUpdater ...@@ -30,11 +30,13 @@ class MetaInfoUpdater
attr_accessor :version attr_accessor :version
attr_accessor :date_string attr_accessor :date_string
attr_accessor :releases_to_show attr_accessor :releases_to_show
attr_accessor :date_off
def initialize(filename, version, date_string="today", releases_to_show=0) def initialize(filename, version, date_string="today", date_off=false, releases_to_show=0)
@filename = filename @filename = filename
@version = version @version = version
@date_string = date_string @date_string = date_string
@date_off = date_off
@releases_to_show = releases_to_show @releases_to_show = releases_to_show
end end
...@@ -47,7 +49,11 @@ class MetaInfoUpdater ...@@ -47,7 +49,11 @@ class MetaInfoUpdater
@doc = File.open(@filename) { |f| Nokogiri::XML(f, &:noblanks) } @doc = File.open(@filename) { |f| Nokogiri::XML(f, &:noblanks) }
component = @doc.at_css("component") component = @doc.at_css("component")
releases = @doc.at_css("releases") releases = @doc.at_css("releases")
if releases if releases and @date_off
releases.add_child("<release version='#{@version}'/>")
elsif not releases and @date_off
component.add_child("<releases><release version='#{@version}'/></releases>")
elsif releases and not @date_off
releases.add_child("<release version='#{@version}' date='#{date}'/>") releases.add_child("<release version='#{@version}' date='#{date}'/>")
else else
component.add_child("<releases><release version='#{@version}' date='#{date}'/></releases>") component.add_child("<releases><release version='#{@version}' date='#{date}'/></releases>")
......
<?xml version="1.0" encoding="utf-8"?>
<component type="desktop">
<id>org.kde.cuttlefish.desktop</id>
<metadata_license>CC0-1.0</metadata_license>
<project_license>GPL-2.0+</project_license>
<name>Cuttlefish</name>
<summary>Icon Previewer for Artists and Developers</summary>
<description>
<p>Cuttlefish allows artists and developers to preview and pick icons. Cuttlefish attempts to render the icons exactly as they would look drawn in the application. It allows to filter based on category and name. Cuttlefish is not a general-purpose tool, but geared towards artists' and developers' use-cases.
Cuttlefish also provides a plugin for Kate and KDevelop to be used as icon picker.
</p>
</description>
<url type="bugtracker">https://bugs.kde.org/enter_bug.cgi?format=guided&amp;product=Plasma%20SDK&amp;component=cuttlefish</url>
<screenshots>
<screenshot type="default">
<image>https://www.kde.org/images/screenshots/cuttlefish.png</image>
</screenshot>
</screenshots>
<project_group>KDE</project_group>
<provides>
<binary>cuttlefish</binary>
</provides>
</component>
<?xml version="1.0" encoding="utf-8"?>
<component type="desktop">
<id>org.kde.cuttlefish.desktop</id>
<metadata_license>CC0-1.0</metadata_license>
<project_license>GPL-2.0+</project_license>
<name>Cuttlefish</name>
<summary>Icon Previewer for Artists and Developers</summary>
<description>
<p>Cuttlefish allows artists and developers to preview and pick icons. Cuttlefish attempts to render the icons exactly as they would look drawn in the application. It allows to filter based on category and name. Cuttlefish is not a general-purpose tool, but geared towards artists' and developers' use-cases.
Cuttlefish also provides a plugin for Kate and KDevelop to be used as icon picker.
</p>
</description>
<url type="bugtracker">https://bugs.kde.org/enter_bug.cgi?format=guided&amp;product=Plasma%20SDK&amp;component=cuttlefish</url>
<screenshots>
<screenshot type="default">
<image>https://www.kde.org/images/screenshots/cuttlefish.png</image>
</screenshot>
</screenshots>
<project_group>KDE</project_group>
<provides>
<binary>cuttlefish</binary>
</provides>
<releases>
<release version="1.0"/>
</releases>
</component>
...@@ -5,7 +5,17 @@ class MetaInfoUpdaterTest < MiniTest::Test ...@@ -5,7 +5,17 @@ class MetaInfoUpdaterTest < MiniTest::Test
# adding a release to a file with no releases # adding a release to a file with no releases
def test_no_releases def test_no_releases
file = "no-releases" file = "no-releases"
updater = MetaInfoUpdater.new("data/#{file}.appdata.xml", "1.0", "2018-01-01") updater = MetaInfoUpdater.new("data/#{file}.appdata.xml", "1.0", "2018-01-01", false)
updater.testing = true
updater.open_file
updater.save_file
assert_equal(File.read("data/#{file}.appdata.xml.expected"), File.read("data/#{file}.appdata.xml.testout"))
end
# date off
def test_no_releases_date_off
file = "no-releases-date-off"
updater = MetaInfoUpdater.new("data/#{file}.appdata.xml", "1.0", "today", true)
updater.testing = true updater.testing = true
updater.open_file updater.open_file
updater.save_file updater.save_file
...@@ -15,7 +25,7 @@ class MetaInfoUpdaterTest < MiniTest::Test ...@@ -15,7 +25,7 @@ class MetaInfoUpdaterTest < MiniTest::Test
# adding a release to a file with 1 release # adding a release to a file with 1 release
def test_one_release def test_one_release
file = "one-release" file = "one-release"
updater = MetaInfoUpdater.new("data/#{file}.appdata.xml", "2.0", "2018-01-01") updater = MetaInfoUpdater.new("data/#{file}.appdata.xml", "2.0", "2018-01-01", false)
updater.testing = true updater.testing = true
updater.open_file updater.open_file
updater.save_file updater.save_file
...@@ -25,7 +35,7 @@ class MetaInfoUpdaterTest < MiniTest::Test ...@@ -25,7 +35,7 @@ class MetaInfoUpdaterTest < MiniTest::Test
# adding a release to a file with 5 releases and limit set to 4 # adding a release to a file with 5 releases and limit set to 4
def test_five_releases def test_five_releases
file = "five-releases" file = "five-releases"
updater = MetaInfoUpdater.new("data/#{file}.appdata.xml", "6.0", "2018-01-01", 4) updater = MetaInfoUpdater.new("data/#{file}.appdata.xml", "6.0", "2018-01-01", false, 4)
updater.testing = true updater.testing = true
updater.open_file updater.open_file
updater.save_file updater.save_file
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment