Refactored check if a package name or section is blacklisted

This commit is contained in:
Christoph Haas 2015-04-24 17:00:15 +02:00
parent 7c6b5c7205
commit da6309400c

View file

@ -88,7 +88,7 @@ namespace :debshots do
Rails.logger.info "> Package: #{package[:Package]}" Rails.logger.info "> Package: #{package[:Package]}"
#Rails.logger.debug "Fetching package informaton from the database" #Rails.logger.debug "Fetching package informaton from the database"
if package_blacklisted? package if package_name_blacklisted? package[:Package] or package_section_blacklisted? package[:Section]
# Should the package get removed from the database? # Should the package get removed from the database?
if REMOVE_BLACKLISTED_PACKAGE if REMOVE_BLACKLISTED_PACKAGE
db_package = Package.find_by name: package[:Package] db_package = Package.find_by name: package[:Package]
@ -133,19 +133,10 @@ namespace :debshots do
repositories = Rails.configuration.package_sources repositories = Rails.configuration.package_sources
Rails.logger = Logger.new(STDOUT) Rails.logger = Logger.new(STDOUT)
Rails.logger.level = Logger::INFO Rails.logger.level = Logger::INFO
Rails.logger.level = Logger::DEBUG # Rails.logger.level = Logger::DEBUG
Rails.logger.info "Importing long descriptoin from Debian repository (i18n)" Rails.logger.info "Importing long descriptoin from Debian repository (i18n)"
# BUG
# Description-en: autoconf like tool
# ACR is an autoconf like tool that allows you to create configure scripts for
# your programs. The main aim of this tool is to teach developers how to create
# portable builds of their tools, just using generic functions wrapped by acr to
# generate portable shellscript.
# Parses as "your programs. The ..."
repositories.each do |repository| repositories.each do |repository|
Rails.logger.info "Fetching Release file for repository: #{repository[:url]} with components: #{repository[:components]}" Rails.logger.info "Fetching Release file for repository: #{repository[:url]} with components: #{repository[:components]}"
release = DebImporter::Release.new(repository[:url]) release = DebImporter::Release.new(repository[:url])
@ -155,7 +146,13 @@ namespace :debshots do
Rails.logger.info "> Component: #{component}" Rails.logger.info "> Component: #{component}"
release.i18n(component, 'en').each do |pkg| release.i18n(component, 'en').each do |pkg|
Rails.logger.debug "i18n information: #{pkg}" Rails.logger.debug "i18n information: #{pkg}"
next unless pkg[:'Description-en'] unless pkg[:'Description-en']
Rails.logger.debug "No Description-en found in section."
next
end
if package_name_blacklisted? pkg[:Package]
next
end
# See if we have that package in the database # See if we have that package in the database
if db_pkg = Package.find_by(name: pkg[:Package]) if db_pkg = Package.find_by(name: pkg[:Package])
Rails.logger.info "Updating long description for package #{db_pkg.name}" Rails.logger.info "Updating long description for package #{db_pkg.name}"
@ -163,6 +160,8 @@ namespace :debshots do
short_description, long_description = text.split("\n", 2) short_description, long_description = text.split("\n", 2)
db_pkg.long_description = long_description db_pkg.long_description = long_description
db_pkg.save db_pkg.save
else
Rails.logger.debug "Package not in database. Nothing to update."
end end
end # pkg.each end # pkg.each
end # components.each end # components.each
@ -180,8 +179,8 @@ namespace :debshots do
task :list_deb_repos => :environment do task :list_deb_repos => :environment do
repositories = Rails.configuration.package_sources repositories = Rails.configuration.package_sources
Rails.logger = Logger.new(STDOUT) Rails.logger = Logger.new(STDOUT)
# Rails.logger.level = Logger::INFO Rails.logger.level = Logger::INFO
Rails.logger.level = Logger::DEBUG # Rails.logger.level = Logger::DEBUG
Rails.logger.info "Listing configured DEB repositories" Rails.logger.info "Listing configured DEB repositories"
@ -240,33 +239,26 @@ def update_data(package, db_package)
end end
db_package.save db_package.save
# TODO: get the long description from http://de.archive.ubuntu.com/ubuntu/dists/precise/main/i18n/Translation-en
end end
# Check if a package is blacklisted and should not be imported. # Check if a package name is blacklisted and should not be imported.
# This prevents importing boring software that likely does not get a useful screenshot. # This prevents importing boring software that likely does not get a useful screenshot.
# Argument: Hash containing package information from a Packages file def package_name_blacklisted?(name)
def package_blacklisted?(package) if match=BLACKLIST_NAME_PATTERN.find { |pattern| name=~pattern}
Rails.logger.debug "Blacklist check of package #{package[:Package]}" Rails.logger.debug " > Blacklisted by name ('#{name}')"
return true
# TODO: add a flag that allows to manually blacklist a package else
return false
BLACKLIST_SECTION_PATTERN.each do |pattern| end
Rails.logger.debug "Checking package section #{package[:Package]} against pattern #{pattern.inspect}" end
if package[:Section] =~ pattern
Rails.logger.info " > Blacklisted by section (matched pattern '#{pattern.inspect}')" # Check if a package's section is blacklisted and should not be imported.
return true # This prevents importing boring software that likely does not get a useful screenshot.
end def package_section_blacklisted?(section)
if match=BLACKLIST_SECTION_PATTERN.find { |pattern| section=~pattern}
Rails.logger.debug " > Blacklisted by section ('#{section}')"
return true
else
return false
end end
BLACKLIST_NAME_PATTERN.each do |pattern|
Rails.logger.debug "Checking package name #{package[:Package]} against pattern #{pattern.inspect}"
if package[:Package] =~ pattern
Rails.logger.info " > Blacklisted by name (matched pattern '#{pattern.inspect}')"
return true
end
end
false
end end