Parsing of i18n file added.
Allows us to read long descriptions and add them to the package information
This commit is contained in:
parent
a15b2b6674
commit
c05b52895d
2 changed files with 62 additions and 2 deletions
|
|
@ -40,6 +40,32 @@ module DebImporter
|
||||||
end # open
|
end # open
|
||||||
end # def initialize
|
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")
|
# Try to load the Packages file for a certain component (e.g. "main")
|
||||||
# and architecture (e.g. "amd64")
|
# and architecture (e.g. "amd64")
|
||||||
def packages(component, architecture)
|
def packages(component, architecture)
|
||||||
|
|
@ -55,8 +81,6 @@ module DebImporter
|
||||||
Rails.logger.debug "Try opening URL: #{url}"
|
Rails.logger.debug "Try opening URL: #{url}"
|
||||||
begin
|
begin
|
||||||
file = open(url)
|
file = open(url)
|
||||||
puts "URL: #{url}"
|
|
||||||
puts "File: #{file}"
|
|
||||||
rescue OpenURI::HTTPError => e
|
rescue OpenURI::HTTPError => e
|
||||||
Rails.logger.info "URL #{url} lead to #{e}. skipping."
|
Rails.logger.info "URL #{url} lead to #{e}. skipping."
|
||||||
next
|
next
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,42 @@ namespace :debshots do
|
||||||
|
|
||||||
end # task
|
end # task
|
||||||
|
|
||||||
|
desc 'Update long description from i18n file'
|
||||||
|
|
||||||
|
task :update_longdescription_from_deb_repos => :environment do
|
||||||
|
|
||||||
|
repositories = Rails.configuration.package_sources
|
||||||
|
Rails.logger = Logger.new(STDOUT)
|
||||||
|
Rails.logger.level = Logger::INFO
|
||||||
|
# Rails.logger.level = Logger::DEBUG
|
||||||
|
|
||||||
|
Rails.logger.info "Importing long descriptoin from Debian repository (i18n)"
|
||||||
|
|
||||||
|
repositories.each do |repository|
|
||||||
|
Rails.logger.info "Fetching Release file for repository: #{repository[:url]} with components: #{repository[:components]}"
|
||||||
|
release = DebImporter::Release.new(repository[:url], repository[:components])
|
||||||
|
Rails.logger.info "> Supported components are: #{release.components}"
|
||||||
|
|
||||||
|
release.components.split.each do |component|
|
||||||
|
Rails.logger.info "> Component: #{component}"
|
||||||
|
release.i18n(component, 'en').each do |pkg|
|
||||||
|
Rails.logger.debug "i18n information: #{pkg}"
|
||||||
|
# See if we have that package in the database
|
||||||
|
if db_pkg = Package.find_by(name: pkg[:Package])
|
||||||
|
Rails.logger.info "Updating long description for package #{db_pkg.name}"
|
||||||
|
db_pkg.long_description = pkg[:'Description-en']
|
||||||
|
db_pkg.save
|
||||||
|
end
|
||||||
|
end # pkg.each
|
||||||
|
end # components.each
|
||||||
|
|
||||||
|
|
||||||
|
Rails.logger.info "Done updating long descriptions from translation file."
|
||||||
|
Rails.logger.info "--------------------------------------------"
|
||||||
|
end # repositories.each
|
||||||
|
|
||||||
|
end # task
|
||||||
|
|
||||||
# TODO: Some code duplication. Should be refactord.
|
# TODO: Some code duplication. Should be refactord.
|
||||||
desc "List configured DEB repositories"
|
desc "List configured DEB repositories"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue