| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
# |
| 4 |
# Example: demonstrate APT version methods |
| 5 |
# |
| 6 |
# Usage: apt-version compare VER1 VER2 |
| 7 |
# rel_compare REL1 REL2 |
| 8 |
# check_dep PKG OP DEP |
| 9 |
# upstream VER |
| 10 |
# |
| 11 |
|
| 12 |
use AptPkg::Config '$_config'; |
| 13 |
use AptPkg::System '$_system'; |
| 14 |
use AptPkg::Version; |
| 15 |
|
| 16 |
(my $self = $0) =~ s#.*/##; |
| 17 |
|
| 18 |
# initialise the global config object with the default values |
| 19 |
$_config->init; |
| 20 |
|
| 21 |
# determine the appropriate system type |
| 22 |
$_system = $_config->system; |
| 23 |
|
| 24 |
# fetch a versioning system |
| 25 |
my $vs = $_system->versioning; |
| 26 |
|
| 27 |
print '[System: ', $_system->label, '; Versioning type: ', $vs->label, "]\n"; |
| 28 |
|
| 29 |
sub describe |
| 30 |
{ |
| 31 |
return 'earlier than' if $_[0] < 0; |
| 32 |
return 'later than' if $_[0] > 0; |
| 33 |
'the same as'; |
| 34 |
} |
| 35 |
|
| 36 |
while ($_ = shift) |
| 37 |
{ |
| 38 |
# compare VER1 VER2 |
| 39 |
/^comp(?:are)?$/ and do { |
| 40 |
die "Usage: $self compare VER1 VER2\n" if @ARGV < 2; |
| 41 |
my ($ver1, $ver2) = splice @ARGV, 0, 2; |
| 42 |
print "* package version `$ver1' is ", |
| 43 |
(describe $vs->compare($ver1, $ver2)), " `$ver2'\n"; |
| 44 |
|
| 45 |
next; |
| 46 |
}; |
| 47 |
|
| 48 |
# rel_compare REL1 REL2 |
| 49 |
/^rel(?:[_-]comp(?:are)?)?$/ and do { |
| 50 |
die "Usage: $self rel_compare REL1 REL2\n" if @ARGV < 2; |
| 51 |
my ($ver1, $ver2) = splice @ARGV, 0, 2; |
| 52 |
print "* release version `$ver1' is ", |
| 53 |
(describe $vs->rel_compare($ver1, $ver2)), " `$ver2'\n"; |
| 54 |
|
| 55 |
next; |
| 56 |
}; |
| 57 |
|
| 58 |
# check_dep PKG OP DEP |
| 59 |
/^check(?:[_-]dep)?$/ and do { |
| 60 |
die "Usage: $self check_dep PKG OP DEP\n" if @ARGV < 3; |
| 61 |
my ($pkg, $op, $dep) = splice @ARGV, 0, 3; |
| 62 |
my $r = $vs->check_dep($pkg, $op, $dep) ? 'satisfies' |
| 63 |
: 'does not satisfy'; |
| 64 |
|
| 65 |
print "* package version `$pkg' $r the dependency `($op $dep)'\n"; |
| 66 |
next; |
| 67 |
}; |
| 68 |
|
| 69 |
# upstream VER |
| 70 |
/^upstream$/ and do { |
| 71 |
die "Usage: $self upstream VER\n" if @ARGV < 1; |
| 72 |
my $ver = shift; |
| 73 |
print "* upstream component of package version `$ver' is `", |
| 74 |
$vs->upstream($ver), "'\n"; |
| 75 |
|
| 76 |
next; |
| 77 |
}; |
| 78 |
|
| 79 |
die "$self: unknown action `$_'\n"; |
| 80 |
} |