Package importer fixed
This commit is contained in:
parent
a7c8f08972
commit
c67f3062dc
2 changed files with 35 additions and 30 deletions
|
|
@ -150,7 +150,7 @@ module DebImporter
|
||||||
end # def
|
end # def
|
||||||
|
|
||||||
class Version
|
class Version
|
||||||
attr_reader :epoch, :version, :revision
|
attr_reader :epoch, :version, :revision, :version_string
|
||||||
|
|
||||||
def initialize(version_string)
|
def initialize(version_string)
|
||||||
@version_string = version_string
|
@version_string = version_string
|
||||||
|
|
@ -164,14 +164,15 @@ module DebImporter
|
||||||
end # /def
|
end # /def
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
@version
|
@version_string
|
||||||
end
|
end
|
||||||
|
|
||||||
def >(other)
|
def >(other)
|
||||||
dpkg_compare_version(@version_string, other)
|
dpkg_compare_version(@version_string, other, 'gt')
|
||||||
# return true if a.epoch > b.epoch
|
end
|
||||||
# return true if version_compare(a.version, b.version)
|
|
||||||
# return true if version_compare(a.revision, b.revision)
|
def <(other)
|
||||||
|
dpkg_compare_version(@version_string, other, 'lt')
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
@ -184,7 +185,7 @@ module DebImporter
|
||||||
# The algorithm is described in the Debian Policy at
|
# The algorithm is described in the Debian Policy at
|
||||||
# https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version
|
# https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version
|
||||||
# The reference implementation is "dpkg --compare-versions …"
|
# The reference implementation is "dpkg --compare-versions …"
|
||||||
def dpkg_compare_version(v1, v2, op: 'gt')
|
def dpkg_compare_version(v1, v2, op)
|
||||||
system("dpkg --compare-versions #{v1} #{op} #{v2}")
|
system("dpkg --compare-versions #{v1} #{op} #{v2}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,8 +50,8 @@ 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 Debian package information"
|
Rails.logger.info "Importing Debian package information"
|
||||||
|
|
||||||
|
|
@ -103,15 +103,34 @@ namespace :debshots do
|
||||||
end # if blacklisted
|
end # if blacklisted
|
||||||
|
|
||||||
db_package = Package.find_by name: package[:Package]
|
db_package = Package.find_by name: package[:Package]
|
||||||
unless db_package
|
if db_package # package exists in the database
|
||||||
|
# check if the parsed package data has a newer version
|
||||||
|
current_version = DebImporter::Version.new(db_package.version)
|
||||||
|
new_version = DebImporter::Version.new(package[:Version])
|
||||||
|
|
||||||
|
Rails.logger.debug "Comparing package version: old=#{db_package.version} new=#{new_version}"
|
||||||
|
if new_version > current_version
|
||||||
|
# update the package information from new data
|
||||||
|
update_data(package, db_package)
|
||||||
|
Rails.logger.info "Updating package information"
|
||||||
|
stats_updated += 1
|
||||||
|
end
|
||||||
|
else # new package - create it in the database
|
||||||
Rails.logger.debug "No such package in our database. Creating one."
|
Rails.logger.debug "No such package in our database. Creating one."
|
||||||
db_package = Package.new
|
db_package = Package.new
|
||||||
|
data_has_changed = update_data(package, db_package)
|
||||||
stats_added += 1
|
stats_added += 1
|
||||||
end
|
end
|
||||||
|
|
||||||
# Rails.logger.debug "Found in database: #{db_package}"
|
# unless db_package
|
||||||
data_has_changed = update_data(package, db_package)
|
# Rails.logger.debug "No such package in our database. Creating one."
|
||||||
stats_updated += 1 if data_has_changed
|
# db_package = Package.new
|
||||||
|
# stats_added += 1
|
||||||
|
# end
|
||||||
|
|
||||||
|
# # Rails.logger.debug "Found in database: #{db_package}"
|
||||||
|
# data_has_changed = update_data(package, db_package)
|
||||||
|
# stats_updated += 1 if data_has_changed
|
||||||
end # package.each
|
end # package.each
|
||||||
|
|
||||||
end # architectures.each
|
end # architectures.each
|
||||||
|
|
@ -225,22 +244,8 @@ end # namespace
|
||||||
def update_data(package, db_package)
|
def update_data(package, db_package)
|
||||||
Rails.logger.debug "New information: #{package.inspect}"
|
Rails.logger.debug "New information: #{package.inspect}"
|
||||||
|
|
||||||
# Check if the version changed
|
# Rails.logger.info "New package version found. Updating details in database."
|
||||||
# Only the actual upstream software version (e.g. 1.2) but not the package
|
db_package.version = package[:Version]
|
||||||
# revision (e.g. 4:1.2-ubuntu0)
|
|
||||||
package[:Version] =~ /(?:\d+\:)?(.+?)(~|\+|\-|$)/
|
|
||||||
new_version = $1
|
|
||||||
if not new_version
|
|
||||||
Rails.logger.fatal "Could not parse version string: #{package[:Version]}"
|
|
||||||
end
|
|
||||||
|
|
||||||
Rails.logger.debug "Comparing package version: old=#{db_package.version} new=#{new_version}"
|
|
||||||
if new_version == db_package.version
|
|
||||||
return false # data has not changed
|
|
||||||
end
|
|
||||||
|
|
||||||
Rails.logger.info "New package version found. Updating details in database."
|
|
||||||
db_package.version = new_version
|
|
||||||
db_package.name = package[:Package] unless db_package.name # set the name for new packages
|
db_package.name = package[:Package] unless db_package.name # set the name for new packages
|
||||||
db_package.description = package[:Description][0..79]
|
db_package.description = package[:Description][0..79]
|
||||||
db_package.homepage = package[:Homepage]
|
db_package.homepage = package[:Homepage]
|
||||||
|
|
@ -251,7 +256,6 @@ def update_data(package, db_package)
|
||||||
db_package.maintainer_email = $2
|
db_package.maintainer_email = $2
|
||||||
db_package.save
|
db_package.save
|
||||||
Rails.logger.debug "Saved package data: #{db_package.inspect}"
|
Rails.logger.debug "Saved package data: #{db_package.inspect}"
|
||||||
return true # data has changed
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Check if a package name is blacklisted and should not be imported.
|
# Check if a package name is blacklisted and should not be imported.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue