Hi.
Anybody have an algorithm to identify the version of an installed package?
eg. in most cases a dash followed by a number is the start of
the version eg. "abiword-2.2.8-1"
so looking for "-[0-9]" should give the start of the version "2.2.8-1"
but then some packages are installed as eg. "cdparanoia-alpha9.8-24"
so to above rule will give "24" as the version
or "widelands-b8-1.1.fc3.rf" will give "1.1.fc3.rf" as the version
enhancing the rule to include "-alpha[0-9]" and "-b[0-9]" might (NOT) be
ambigious?
Any help or place to go light a candle?
<edit>
I know it is possible to get the relevant info with the proper switches
to the program eg. rpm -qai or pkginfo -qi etc.
But unfortunatly the input is a file I receive and I have no control
over the contents.
</edit>
Identifying revs
I think you want to use the "--queryformat" parameter. For instance, if you do a regular query:
$ rpm -q sendmail
you get this:
sendmail-8.13.4-2
If you wanted the same thing using queryformat you would:
$ rpm -q sendmail --queryformat "%{NAME}-%{VERSION}-%{RELEASE}\n"
If you wanted just the version and release you would obviously:
$ rpm -q sendmail --queryformat "%{VERSION}-%{RELEASE}\n"
If you didn't want the carriage return at the end just take out the "\n".
By the way, there are a LOT more things you can query than just those few database items. Check out the list:
http://www.rpm.org/max-rpm/ch-queryformat-tags.html
$ rpm -q sendmail
you get this:
sendmail-8.13.4-2
If you wanted the same thing using queryformat you would:
$ rpm -q sendmail --queryformat "%{NAME}-%{VERSION}-%{RELEASE}\n"
If you wanted just the version and release you would obviously:
$ rpm -q sendmail --queryformat "%{VERSION}-%{RELEASE}\n"
If you didn't want the carriage return at the end just take out the "\n".
By the way, there are a LOT more things you can query than just those few database items. Check out the list:
http://www.rpm.org/max-rpm/ch-queryformat-tags.html
-
- programmer
- Posts: 130
- Joined: Sun Feb 09, 2003 1:08 pm
- Location: Midrand Gauteng, South Africa
Tx Void
Reckon I edited the post to late
like I said i know about and have used the queryformat etc.
but my problem is that I have no control over the content of the file
and so have to make do with some rules to pull the fields apart.
I get a similiar file for all the *nix boxes on site - and they all have
about the same layout.
To get the file content changed will involve a long winded explanation,
and i really don't feel like getting into that.
it is on the cards - but not for a long time at least. (depending on
how quickly we can actually change the clients' mind-set)
Reckon I edited the post to late

like I said i know about and have used the queryformat etc.
but my problem is that I have no control over the content of the file
and so have to make do with some rules to pull the fields apart.
I get a similiar file for all the *nix boxes on site - and they all have
about the same layout.
To get the file content changed will involve a long winded explanation,
and i really don't feel like getting into that.
it is on the cards - but not for a long time at least. (depending on
how quickly we can actually change the clients' mind-set)
I guess I just don't have enough information to compute. I'm not exactly sure what you are asking. If you could give me a sample and let me know how it needs to be used I can probably come up with an answer for you. I have had to do something similar to what I *think* you are asking using regular expressions in a script.
-
- programmer
- Posts: 130
- Joined: Sun Feb 09, 2003 1:08 pm
- Location: Midrand Gauteng, South Africa
a52dec-0.7.4-7.1.fc3.rf a52dec-devel-0.7.4-7.1.fc3.rf aali
here goes
For each *nix machine I get a file with something like the following
####
a52dec-0.7.4-7.1.fc3.rf
a52dec-devel-0.7.4-7.1.fc3.rf
aalib-1.4.0-5.1.fc3.rf
abiword-2.2.8-1
abiword-plugins-impexp-2.2.8-1
.
.
####
This I have to check against a default control file for the type
of installation to see if the current version of the package is equal
or later to that in the control file.
The control file consists of 3 fields (which fortunatly I can set up) eg.
####
a52dec 0.7.4 7.1.fc3.rf
a52dec-devel 0.7.4 7.1.fc3.rf
aalib 1.4.0 5.1.fc3.rf
abiword 2.2.8 1
####
So I need to be able to split the input file into at least
the package base name and the version to be able to compare them.
Hope this makes sense
For each *nix machine I get a file with something like the following
####
a52dec-0.7.4-7.1.fc3.rf
a52dec-devel-0.7.4-7.1.fc3.rf
aalib-1.4.0-5.1.fc3.rf
abiword-2.2.8-1
abiword-plugins-impexp-2.2.8-1
.
.
####
This I have to check against a default control file for the type
of installation to see if the current version of the package is equal
or later to that in the control file.
The control file consists of 3 fields (which fortunatly I can set up) eg.
####
a52dec 0.7.4 7.1.fc3.rf
a52dec-devel 0.7.4 7.1.fc3.rf
aalib 1.4.0 5.1.fc3.rf
abiword 2.2.8 1
####
So I need to be able to split the input file into at least
the package base name and the version to be able to compare them.
Hope this makes sense

Wouldn't it be easier to just set up an apt repo and have all your Fedora machines update themselves from it?
Failing that here's something I whiped up to show you how to parse this sort of stuff in Perl. You can see I have read in the output from an "rpm -qa" and parsed things into various parts. You can add in your own logic after parsing and if you want to change it so it reads the list from a file rather than from the rpm command you would change the "open()" statement to this:
Here's the Perl code:
rpm.pl:
Too bad the version format is not standardized and enforced. This would become much easier! Of course the "rpm" command seems to know if a version is higher or lower than one being installed. I think I might look at the source for rpm and see if I can see the logic.
Failing that here's something I whiped up to show you how to parse this sort of stuff in Perl. You can see I have read in the output from an "rpm -qa" and parsed things into various parts. You can add in your own logic after parsing and if you want to change it so it reads the list from a file rather than from the rpm command you would change the "open()" statement to this:
Code: Select all
open(RPMS,"</somedir/yourinputfile.txt");
rpm.pl:
Code: Select all
#!/usr/bin/perl -w
use strict;
open(RPMS,"rpm -qa|");
while (<RPMS>) {
# d.d-d / 3.2-1
if (/(.*)-(\d+)\.(\d+)-(\d+)(.*)/) {
print "twonum: $1 $2.$3-$4 $5 orig: $_";
# d.d.d-d / 3.2.1-1
} elsif (/(.*)-(\d+)\.(\d+)\.(\d+)-(\d+)(.*)/) {
print "threenum: $1 $2.$3.$4-$5 $6 orig: $_";
# d.d.d.d-d / 4.3.2.1-1
} elsif (/(.*)-(\d+)\.(\d+)\.(\d+)\.(\d+)-(\d+)(.*)/) {
print "fournum: $1 $2.$3.$4.$5-$6 $7 orig: $_";
# d.d.d.d.d-d / 5.4.3.2.1-1
} elsif (/(.*)-(\d+)\.(\d+)\.(\d+)\.(\d+)\.(\d+)-(\d+)(.*)/) {
print "fivenum: $1 $2.$3.$4.$5.$6-$7 $8 orig: $_";
# d.d.d.d.da-d / 5.4.3.2.1a-1
} elsif (/(.*)-(\d+)\.(\d+)\.(\d+)\.(\d+)\.(.*)-(\d+)(.*)/) {
print "fivealpha: $1 $2.$3.$4.$4.$6-$7 $8 orig: $_";
# d.d.d.da-d / 4.3.2.1a-1
} elsif (/(.*)-(\d+)\.(\d+)\.(\d+)\.(.*)-(\d+)(.*)/) {
print "fouralpha: $1 $2.$3.$4.$5-$6 $7 orig: $_";
# d.d.da-d / 3.2.1a-1
} elsif (/(.*)-(\d+)\.(\d+)\.(.*)-(\d+)(.*)/) {
print "threealpha: $1 $2.$3.$4-$5 $6 orig: $_";
# d.da-d / 3.4a-1
} elsif (/(.*)-(\d+)\.(.*)-(\d+)(.*)/) {
print "twoalpha: $1 $2.$3-$4 $5 orig: $_";
# any other format
} else {
print "NOMATCH: $_";
}
}
close(RPMS);