Parsing of i18n file added.

Allows us to read long descriptions and add them to the package information
This commit is contained in:
Christoph Haas 2015-04-23 00:29:30 +02:00
parent a15b2b6674
commit c05b52895d
2 changed files with 62 additions and 2 deletions

View file

@ -40,6 +40,32 @@ module DebImporter
end # open
end # def initialize
# TODO: Avoid code duplication (bz2, gz, ...)
def i18n(component, language)
for suffix in ['.bz2', '.gz', '']
url = "#{@dist_url}/#{component}/i18n/Translation-en#{suffix}"
Rails.logger.debug "Looking for translations file: #{url}"
begin
Rails.logger.debug "Try opening URL: #{url}"
begin
file = open(url)
rescue OpenURI::HTTPError => e
Rails.logger.info "URL #{url} lead to #{e}. skipping."
next
end
if suffix == '.gz'
file = Zlib::GzipReader.new(file)
elsif suffix == '.bz2'
file = Bzip2::Reader.new(file)
end
Rails.logger.debug "File containing translations is: #{file}"
return get_paragraphs(file)
rescue Errno::ENOENT
Rails.logger.debug "URL could not be opened. Skipping."
end
end
end
# Try to load the Packages file for a certain component (e.g. "main")
# and architecture (e.g. "amd64")
def packages(component, architecture)
@ -55,8 +81,6 @@ module DebImporter
Rails.logger.debug "Try opening URL: #{url}"
begin
file = open(url)
puts "URL: #{url}"
puts "File: #{file}"
rescue OpenURI::HTTPError => e
Rails.logger.info "URL #{url} lead to #{e}. skipping."
next