Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix appdata parsing #181

Merged
merged 2 commits into from
Jul 28, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions app/models/appdata.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
require 'open-uri'
require 'zlib'

class Appdata

def self.logger
Rails.logger
end

def self.get dist = "factory"
data = Hash.new
xml = Appdata.get_distribution dist, "oss"
data = add_appdata data, xml
# xml = Appdata.get_distribution dist, "non-oss"
# data = add_appdata data, xml
xml = Appdata.get_distribution dist, "non-oss"
data = add_appdata data, xml
logger.debug("found #{data[:apps].size} apps")
data
end

Expand All @@ -16,7 +22,7 @@ def self.get dist = "factory"
def self.add_appdata data, xml
data[:apps] = Array.new unless data[:apps]
data[:categories] = Array.new unless data[:categories]
xml.xpath("/components/component").each do |app|
xml.xpath("/components/component").each do |app|
appdata = Hash.new
# Filter translated versions of name and summary out
appdata[:name] = app.xpath('name[not(@xml:lang)]').text
Expand All @@ -39,10 +45,12 @@ def self.get_distribution dist = "factory", flavour = "oss"
else
"http://download.opensuse.org/distribution/#{dist}/repo/#{flavour}/suse/setup/descr/appdata.xml.gz"
end
filename = File.join(Rails.root.join('tmp'), "appdata-" + dist + ".xml")
logger.debug("fetching appdata for #{dist}/#{flavour}")
filename = File.join(Rails.root.join('tmp'), "appdata-#{dist}-#{flavour}.xml")
open(filename, 'wb') do |file|
# Gzip data will be automatically decompressed with open-uri
file << open(appdata_url).read
# Gzip data will NOT be automatically decompressed with open-uri
# must have changed at some point in time, so decompress explicitly
file << Zlib::GzipReader.new(open(appdata_url)).read
end
xmlfile = File.open(filename)
doc = Nokogiri::XML(xmlfile)
Expand Down