Added Rake task to import packages from Debian repositories
This commit is contained in:
parent
5df82dc0e5
commit
ef30db8b55
1 changed files with 93 additions and 0 deletions
93
lib/tasks/import_debian.rake
Normal file
93
lib/tasks/import_debian.rake
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
require 'open-uri' # allows to load URLs using open()
|
||||
require 'deb_importer'
|
||||
|
||||
include DebImporter
|
||||
|
||||
BLACKLIST_NAME_PATTERN=[
|
||||
'-data$',
|
||||
'-dev$',
|
||||
'-doc$',
|
||||
]
|
||||
|
||||
desc "Import package information from Debian-style Packages files"
|
||||
|
||||
task :import_debian => :environment do
|
||||
repositories = Rails.configuration.package_sources
|
||||
Rails.logger = Logger.new(STDOUT)
|
||||
Rails.logger.level = Logger::DEBUG
|
||||
|
||||
puts "Importing Debian package information"
|
||||
|
||||
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 architectures are: #{release.architectures}"
|
||||
Rails.logger.info "> Supported components are: #{release.components}"
|
||||
|
||||
# TODO: Remember what we imported to show it on the /about page
|
||||
|
||||
release.components.split.each do |component|
|
||||
Rails.logger.info "> Component: #{component}"
|
||||
release.architectures.split.each do |architecture|
|
||||
Rails.logger.info ">> Architecture: #{architecture}"
|
||||
# Check if this component and architecture is available on this mirror
|
||||
packages = release.packages(component, architecture)
|
||||
unless packages
|
||||
Rails.logger.error "No packages for component #{component} on architecture #{architecture} found on this mirror"
|
||||
next
|
||||
end
|
||||
|
||||
Rails.logger.info "Packages file for #{component} on #{architecture} found."
|
||||
Rails.logger.debug "Got: #{packages}"
|
||||
packages.each do |package|
|
||||
Rails.logger.info "> Package: #{package[:Package]}"
|
||||
#Rails.logger.debug "Fetching package informaton from our database"
|
||||
#db_package = Package[name: package[:Package]]
|
||||
db_package = Package.find_by name: package[:Package]
|
||||
unless db_package
|
||||
Rails.logger.debug "No such package in our database."
|
||||
next
|
||||
end
|
||||
|
||||
Rails.logger.debug "Found in database: #{db_package.id}"
|
||||
update_data(package, db_package)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Update the information about a package in the database
|
||||
def update_data(package, db_package)
|
||||
# Check update criteria (blacklist, whitelist)
|
||||
#for name, name in expression
|
||||
#code
|
||||
#end
|
||||
|
||||
|
||||
Rails.logger.debug "New information: #{package.to_yaml}"
|
||||
Rails.logger.debug "Database information: #{db_package.to_yaml}"
|
||||
|
||||
# Check if the version changed
|
||||
# Only the actual upstream software version (e.g. 1.2) but not the package
|
||||
# revision (e.g. 4:1.2-ubuntu0)
|
||||
package[:Version] =~ /(?:\d+\:)?(.+?)(~|\+|\-|$)/
|
||||
#new_version = package[:Version].split('-')[0]
|
||||
new_version = $1
|
||||
if not new_version
|
||||
Rails.logger.fatal "Could not parse version string: #{package[:Version]}"
|
||||
end
|
||||
|
||||
if new_version != package[:Version]
|
||||
Rails.logger.debug "- Version changed: #{db_package.version} -> #{new_version}"
|
||||
db_package.version = new_version
|
||||
end
|
||||
|
||||
db_package.save
|
||||
|
||||
# TODO: Deal with different distributions differently
|
||||
|
||||
# TODO: get the long description from http://de.archive.ubuntu.com/ubuntu/dists/precise/main/i18n/Translation-en
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue