Project

General

Profile

Download (3.81 KB) Statistics
| Branch: | Revision:
ff29708e Marc Dequènes (Duck)
#!/usr/bin/ruby

bc82ca34 Marc Dequènes (Duck)
#--
# Ruby-Debian, a Ruby interface for Debian packaging aspects
# Copyright (c) 2009 Marc Dequènes (Duck) <Duck@DuckCorp.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#++

ff29708e Marc Dequènes (Duck)
require 'debian_apt'

module Debian_apt
def self.included(base)
@@op_to_opcode = {}
i = 1
while true
op = Debian_apt::PkgCache.comp_type_deb(i)
break if op == ""
@@op_to_opcode[op] = i
i += 1
end
end

def compare_versions(lver, rver)
829c40b8 Marc Dequènes (Duck)
Debian_apt.debVS.cmp_version(lver.to_s, rver.to_s)
ff29708e Marc Dequènes (Duck)
end

def check_version_constraint(lver, op, rver)
829c40b8 Marc Dequènes (Duck)
Debian_apt.debVS.check_dep(lver.to_s, @@op_to_opcode[op], rver.to_s)
ff29708e Marc Dequènes (Duck)
end
end

module Debian
class DebianVersion
include Comparable
include Debian_apt

attr_accessor :epoch, :upstream, :revision

DEB_TILDE = /~(.*)$/

def initialize(version = nil)
if version.nil? or version == ""
@epoch = 0
@upstream = nil
@revision = nil
else
@upstream = Debian_apt.debVS.upstream_version(version)
ce4364e3 Marc Dequènes (Duck)
@epoch, @revision = version.split(@upstream, 2)
@epoch = @epoch ? @epoch[0..-2].to_i : 0
@revision = @revision[1..-1] if @revision

# magic fence
raise "DebianVersion bug in parsing. Stopping before breaking the world !" if self.version != version
ff29708e Marc Dequènes (Duck)
end
end

def version
if @upstream.nil?
ver = nil
else
ver = "#{@upstream}"
# @revision can be nil for native packages
ver += "-#{@revision}" unless @revision.nil?
ver = "#{@epoch}:#{ver}" unless @epoch == 0
end
ver
end

def to_s
ver = self.version
(ver.nil?) ? "none" : ver
end

def <=>(rver)
compare_versions(self.version, rver.version)
end

def is_native?
@revision.nil?
end

def compare(op, rver)
check_version_constraint(self.version, op, rver.version)
end

def compare_epochless(op, rver)
v1 = self.dup
v2 = rver.dup
v1.epoch = 0
v2.epoch = 0
check_version_constraint(v1.version, op, v2.version)
end

def compare_upstream(op, rver, remove_tilde_part = false)
v1 = self.dup
v2 = rver.dup
if remove_tilde_part
v1.remove_upstream_tilde_part
v2.remove_upstream_tilde_part
end
check_version_constraint(v1.upstream, op, v2.upstream)
end

def compare_revision(op, rver)
check_version_constraint(self.revision, op, rver.revision)
end

def compare_epoch(op, rver)
check_version_constraint(self.epoch, op, rver.epoch)
end

def upstream_tilde_part
@upstream =~ DEB_TILDE
$1
end

def remove_upstream_tilde_part
# trigger a bug with dupped objects
#@upstream.gsub!(DEB_TILDE, "")
@upstream = @upstream.gsub(DEB_TILDE, "")
end

def set_upstream_tilde_part(str)
remove_upstream_tilde_part
@upstream += "~#{str}"
end

def revision_tilde_part
@revision =~ DEB_TILDE
$1
end

def remove_revision_tilde_part
# trigger a bug with dupped objects
#@revision.gsub!(DEB_TILDE, "")
@revision = @revision.gsub(DEB_TILDE, "")
end

def set_revision_tilde_part(str)
remove_revision_tilde_part
@revision += "~#{str}"
end
end
end