[Slim-Checkins] r10792 - in /trunk: platforms/debian/control
server/CPAN/Data/VString.pm
server/Plugins/MusicMagic/Importer.pm server/Slim/Utils/Versions.pm
dsully at svn.slimdevices.com
dsully at svn.slimdevices.com
Tue Nov 28 16:04:05 PST 2006
Author: dsully
Date: Tue Nov 28 16:04:05 2006
New Revision: 10792
URL: http://svn.slimdevices.com?rev=10792&view=rev
Log:
Bug: N/A
Description:
Replace Data::VString with an implementation of Mozilla's Toolkit Version
Format, which is much more flexible and will be used for checking min/max
ranges for plugin version compatibility.
Added:
trunk/server/Slim/Utils/Versions.pm (with props)
Removed:
trunk/server/CPAN/Data/VString.pm
Modified:
trunk/platforms/debian/control
trunk/server/Plugins/MusicMagic/Importer.pm
Modified: trunk/platforms/debian/control
URL: http://svn.slimdevices.com/trunk/platforms/debian/control?rev=10792&r1=10791&r2=10792&view=diff
==============================================================================
--- trunk/platforms/debian/control (original)
+++ trunk/platforms/debian/control Tue Nov 28 16:04:05 2006
@@ -21,7 +21,7 @@
libtie-cache-perl, libtie-cache-lru-perl, libtie-llhash-perl, libcarp-clan-perl,
libpath-class-perl, liburi-perl, liburi-find-perl, liberror-perl, libclass-singleton-perl,
libtie-cache-lru-expires-perl (>= 0.54-1), libxml-parser-perl, libfile-find-rule-perl,
- libdata-vstring-perl, libalgorithm-c3-perl, libclass-c3-perl, libproc-background-perl,
+ libalgorithm-c3-perl, libclass-c3-perl, libproc-background-perl,
libdbix-class-perl, libclass-inspector-perl, libxml-writer-perl, libxml-xspf-perl,
liblog-log4perl-perl, libexporter-lite-perl, libmodule-pluggable-perl,
libdata-dump-perl, libmpeg-audio-frame-perl, libnet-upnp-perl, libxml-simple-perl (>= 2.15-1),
Modified: trunk/server/Plugins/MusicMagic/Importer.pm
URL: http://svn.slimdevices.com/trunk/server/Plugins/MusicMagic/Importer.pm?rev=10792&r1=10791&r2=10792&view=diff
==============================================================================
--- trunk/server/Plugins/MusicMagic/Importer.pm (original)
+++ trunk/server/Plugins/MusicMagic/Importer.pm Tue Nov 28 16:04:05 2006
@@ -5,7 +5,6 @@
use strict;
use File::Spec::Functions qw(:ALL);
-use Data::VString qw(vstring_cmp);
use LWP::Simple;
use Scalar::Util qw(blessed);
use Socket qw($LF);
@@ -18,6 +17,7 @@
use Slim::Utils::Misc;
use Slim::Utils::OSDetect;
use Slim::Utils::Strings qw(string);
+use Slim::Utils::Versions;
my $initialized = 0;
my $MMMVersion = 0;
@@ -199,7 +199,7 @@
# MMM Version 1.5+ adds support for /api/songs?extended, which pulls
# down the entire library, separated by $LF$LF - this allows us to make
# 1 HTTP request, and the process the file.
- if (vstring_cmp($MMMVersion, '>=', '1.5')) {
+ if (Slim::Utils::Versions->compareVersions($MMMVersion, '1.5')) {
$log->info("Fetching ALL song data via songs/extended..");
@@ -378,7 +378,7 @@
my $class = shift;
# check for dupes, but not with 1.1.3
- if (vstring_cmp($MMMVersion, '<=', '1.1.3')) {
+ if (Slim::Utils::Versions->compareVersions('1.1.3', $MMMVersion)) {
return;
}
Added: trunk/server/Slim/Utils/Versions.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Utils/Versions.pm?rev=10792&view=auto
==============================================================================
--- trunk/server/Slim/Utils/Versions.pm (added)
+++ trunk/server/Slim/Utils/Versions.pm Tue Nov 28 16:04:05 2006
@@ -1,0 +1,218 @@
+package Slim::Utils::Versions;
+
+# $Id$
+
+# SlimServer Copyright (c) 2001-2006 Slim Devices Inc.
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License, version 2.
+
+=head1 NAME
+
+Slim::Utils::Versions
+
+=head1 SYNOPSIS
+
+if (Slim::Utils::Versions->checkVersion($toCheck, $min, $max)) {
+
+ print "ok!";
+}
+
+=head1 DESCRIPTION
+
+This module implements the Mozilla Toolkit Version Format, as found in Firefox 1.5 and later.
+
+See L<http://developer.mozilla.org/en/docs/Toolkit_version_format> for more information.
+
+=head1 METHODS
+
+=cut
+
+use strict;
+use POSIX qw(INT_MAX);
+
+sub _parseVersionPart {
+ my ($part, $result) = @_;
+
+ if (!$part) {
+ return $part;
+ }
+
+ my $rest = undef;
+
+ if ($part =~ /^(.+?)\.(.*)$/) {
+ $part = $1;
+ $rest = $2;
+ }
+
+ if ($part eq '*') {
+
+ $result->[0] = POSIX::INT_MAX();
+ $result->[1] = '';
+
+ } elsif ($part =~ s/^(-?\d+)//) {
+
+ $result->[0] = $1;
+ }
+
+ if ($part && $part eq '+') {
+
+ $result->[0]++;
+ $result->[1] = 'pre';
+
+ } elsif ($part && $part =~ /^([A-Za-z]+)?([+-]?\d+)?([A-Za-z]+)?/) {
+
+ $result->[1] = $1 || undef;
+ $result->[2] = $2 || 0;
+ $result->[3] = $3 || undef;
+ }
+
+ return $rest;
+}
+
+sub _string_cmp {
+ my ($n1, $n2) = @_;
+
+ if (!$n1) {
+ return defined $n2;
+ }
+
+ if (!$n2) {
+ return -1;
+ }
+
+ return $n1 cmp $n2;
+}
+
+sub _compareVersionPart {
+ my ($left, $right) = @_;
+
+ my $ret = $left->[0] <=> $right->[0];
+
+ if ($ret) {
+ return $ret;
+ }
+
+ $ret = _string_cmp($left->[1], $right->[1]);
+
+ if ($ret) {
+ return $ret;
+ }
+
+ $ret = $left->[2] <=> $right->[2];
+
+ if ($ret) {
+ return $ret;
+ }
+
+ return _string_cmp($left->[3], $right->[3]);
+}
+
+=head2 compareVersions( $left, $right )
+
+Returns true if the version string in $left is greater than the string in $right.
+
+Returns false otherwise.
+
+=cut
+
+sub compareVersions {
+ my ($class, $left, $right) = @_;
+
+ my $result;
+
+ if (!$left || !$right) {
+ return 1;
+ }
+
+ my ($a, $b) = ($left, $right);
+
+ while ($a || $b) {
+
+ my $va = [ 0, undef, 0, undef ];
+ my $vb = [ 0, undef, 0, undef ];
+
+ $a = _parseVersionPart($a, $va);
+ $b = _parseVersionPart($b, $vb);
+
+ $result = _compareVersionPart($va, $vb);
+
+ if ($result) {
+ last;
+ }
+ }
+
+ return $result || 0;
+}
+
+=head2 checkVersion( $toCheck, $min, $max )
+
+Returns true if the version string in $toCheck falls within the $min & $max range.
+
+Returns false otherwise.
+
+=cut
+
+sub checkVersion {
+ my ($class, $toCheck, $min, $max) = @_;
+
+ if ($class->compareVersions($toCheck, $min) < 0) {
+
+ return 0;
+ }
+
+ if ($class->compareVersions($toCheck, $max) > 0) {
+
+ return 0;
+ }
+
+ return 1;
+}
+
+1;
+
+__END__
+# Tests follow
+
+use Test::More qw(no_plan);
+
+is(compareVersions('1.1b', '1.1ab'), 1, '1.1b > 1.1ab');
+
+is(compareVersions('2.0', '1.*.1'), 1, '2.0 > 1.*.1');
+is(compareVersions('1.*.1', '1.*'), 1, '1.*.1 > 1.*');
+is(compareVersions('1.*', '1.10'), 1, '1.* > 1.10');
+is(compareVersions('1.10', '1.1.00'), 1, '1.10 > 1.1.00');
+
+is(compareVersions('1.1.00', '1.1.0'), 0, '1.1.00 == 1.1.0');
+is(compareVersions('1.1.0', '1.1'), 0, '1.1.0 == 1.1');
+is(compareVersions('1.1.00', '1.1'), 0, '1.1.00 == 1.1');
+
+is(compareVersions('1.1', '1.1.-1'), 1, '1.1 > 1.1-1');
+
+is(compareVersions('1.1.-1', '1.1pre10'), 1, '1.1-1 > 1.1pre10');
+is(compareVersions('1.1pre10', '1.1pre2'), 1, '1.1pre10 > 1.1pre2');
+is(compareVersions('1.1pre2', '1.1pre1'), 1, '1.1pre2 > 1.1pre1');
+is(compareVersions('1.1pre1', '1.1pre1b'), 1, '1.1pre1 > 1.1pre1b');
+is(compareVersions('1.1pre1b', '1.1pre1aa'), 1, '1.1pre1b > 1.1pre1aa');
+is(compareVersions('1.1pre1aa', '1.1pre1a'), 1, '1.1pre1aa > 1.1pre1a');
+is(compareVersions('1.1pre1a', '1.0+'), 1, '1.1pre1a > 1.0+');
+
+is(compareVersions('1.0+', '1.1pre0'), 0, '1.0+ == 1.1pre0');
+is(compareVersions('1.0+', '1.1pre'), 0, '1.0+ == 1.1pre');
+is(compareVersions('1.1pre0', '1.1pre'), 0, '1.1pre0 == 1.1pre');
+
+is(compareVersions('1.1pre', '1.1whatever'), -1, '1.1pre < 1.1whatever');
+is(compareVersions('1.1whatever', '1.1c'), 1, '1.1whatever > 1.1c');
+
+is(compareVersions('1.1c', '1.1b'), 1, '1.1c > 1.1b');
+is(compareVersions('1.1b', '1.1ab'), 1, '1.1b > 1.1ab');
+is(compareVersions('1.1ab', '1.1aa'), 1, '1.1ab > 1.1aa');
+is(compareVersions('1.1aa', '1.1a'), 1, '1.1aa > 1.1a');
+is(compareVersions('1.1a', '1.0.0'), 1, '1.1a > 1.0.0');
+
+is(compareVersions('1.0.0', '1.0'), 0, '1.0.0 == 1.0');
+is(compareVersions('1.0', '1.'), 0, '1.0 == 1.');
+is(compareVersions('1.', '1'), 0, '1. == 1');
+is(compareVersions('1.0.0', '1.'), 0, '1.0.0 == 1.');
+is(compareVersions('1.0.0', '1'), 0, '1.0.0 == 1');
+
+is(compareVersions('1', '1.-1'), 1, '1 > 1.-1');
Propchange: trunk/server/Slim/Utils/Versions.pm
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: trunk/server/Slim/Utils/Versions.pm
------------------------------------------------------------------------------
svn:keywords = Id Author LastChangedDate LastChangedBy
Propchange: trunk/server/Slim/Utils/Versions.pm
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the checkins
mailing list