Commit Diff
Diff:
ee01fb3d58e75544660465121b6ca00b241e44ef
cd160380603f19faac8059be73490f19c3de8f4b
Commit:
cd160380603f19faac8059be73490f19c3de8f4b
Tree:
31f6167edeb740ff9aaa48a2fb4f6fc093151d2e
Author:
fredgnix <fredgnix@a8afeb8c-277c-4b4a-a4f6-ef4c85adc32b>
Committer:
fredgnix <fredgnix@a8afeb8c-277c-4b4a-a4f6-ef4c85adc32b>
Date:
Tue Jan 3 17:41:59 2012 UTC
Message:
add Slackware functions and CLI arg
blob - fd0fb8488b1ef62ab7ff658a8dc673fa6db489d5
blob + 2736b09414b20765ab19e388f45f851dbd906a44
--- Pkgtxt2db.pm
+++ Pkgtxt2db.pm
@@ -27,11 +27,11 @@ our $pkgtxt = "/tmp/salixPACKAGES.TXT";
our $url32 = "$salix_mirror/$arch32/$release/PACKAGES.TXT";
our $url64 = "$salix_mirror/$arch64/$release/PACKAGES.TXT";
# Slackware
-our $slack_mirror="ftp://ftp.osuosl.org/pub/slackware";
-our $a32 = "slackware-";
-our $a64 = "slackware64-";
-our $slack32url = "$slack_mirror/$a32$release/PACKAGES.TXT";
-our $slack64url = "$slack_mirror/$a64$release/PACKAGES.TXT";
+our $slack_mirror="http://slackware.org.uk/slackware";
+our $a32 = "slackware";
+our $a64 = "slackware64";
+our $slackurl32 = "$slack_mirror/${a32}-${release}/PACKAGES.TXT";
+our $slackurl64 = "$slack_mirror/${a64}-${release}/PACKAGES.TXT";
our $slackpkgtxt = "/tmp/slackwarePACKAGES.TXT";
sub new {
@@ -40,25 +40,55 @@ sub new {
return $self;
}
-# Pkgtxt2db->get_file($url,$pkgtxt)
-sub get_file {
- our ($a,$b) = @_;
- mirror($a, $b) or die "Error: could not fetch $a\n";
-}
-
#
-# make the file an array
+# build an array with all file lines
#
# Salix
-# Pkgtxt2db->salix_data()
+# Pkgtxt2db->getsalix_d32()
+#
+sub getsalix_d32 {
+ my $status = getstore($url32,$pkgtxt);
+ if ( is_success($status) ) {
+ print "PACKAGES.TXT downloaded correctly.\n";
+ } else {
+ print "PACKAGES.TXT not downloaded: $status\n";
+ }
+}
+sub getsalix_d64 {
+ my $status = getstore($url64,$pkgtxt);
+ if ( is_success($status) ) {
+ print "PACKAGES.TXT downloaded correctly.\n";
+ } else {
+ print "PACKAGES.TXT not dowloaded: $status\n";
+ }
+}
+
sub salix_data {
- open F, "<$pkgtxt" or die $!;
+ open F, "<$pkgtxt" or die "No Salix PACKAGES.TXT file, aborting.\n";
our @salix_d = <F>;
close (F);
return @salix_d;
}
+
# Slackware
-# Pkgtxt2db->slack_data()
+# Pkgtxt2db->getslack_d32()
+#
+sub getslack_d32 {
+ my $status = getstore($slackurl32,$slackpkgtxt);
+ if ( is_success($status) ) {
+ print "PACKAGES.TXT downloaded correctly.\n";
+ } else {
+ print "PACKAGES.TXT not downloaded: $status\n";
+ }
+}
+sub getslack_d64 {
+ my $status = getstore($slackurl64,$slackpkgtxt);
+ if ( is_success($status) ) {
+ print "PACKAGES.TXT downloaded correctly.\n";
+ } else {
+ print "PACKAGES.TXT not downloaded: $status\n";
+ }
+}
sub slack_data {
open G, "<$slackpkgtxt" or die $!;
our @slack_d = <G>;
@@ -66,15 +96,18 @@ sub slack_data {
return @slack_d;
}
-
#
# Make the hash of array database
+#
+# Salix DB
+# Pkgtxt2db->mkdasalixdb()
+#
our %pkgdb;
-sub mkdadb {
+sub mkdasalixdb {
our $self = shift;
- our @d = salix_data() unless defined(@d);
+ our @d = salix_data();
our $pname;
our $pkgname;
@@ -112,19 +145,65 @@ sub mkdadb {
else {
next;
}
- if (@d = slack_data()) {
- our %slackdb = %pkgdb;
- return \%slackdb;
- } else {
return %pkgdb;
+ }
+}
+
+#
+# Slackware DB
+# Pkgtxt2db->mkdaslackdb()
+#
+our %slackdb;
+
+sub mkdaslackdb {
+ our $self = shift;
+
+ our @da = slack_data();
+ our $name;
+ our $pkg;
+
+ foreach (@da) {
+ chomp $_;
+ if ($_ =~ /^$/){
+ next;
}
+ if ($_ =~ /(^PACKAGE NAME:\s\s)(.*)/) {
+ $name = "$2";
+ $name =~ /^(.*)-([^-]*)-([^-]*)-([^-]*).t[glx]z$/;
+ $pkg = "$1";
+ $slackdb{$pkg}[0] = "$name";
+ $slackdb{$pkg}[1] = "$2";
+ $slackdb{$pkg}[2] = "$3";
+ $slackdb{$pkg}[3] = "$4";
+ next;
+ }
+ if ($_ =~ /(^PACKAGE LOCATION:\s\s\.)(.*)/) {
+ $slackdb{$pkg}[4] = "$2";
+ next;
+ }
+ if ($_ =~ /(^PACKAGE REQUIRED:\s\s)(.*)/) {
+ $slackdb{$pkg}[5] = "$2";
+ next;
+ }
+ if ($_ =~ /(^PACKAGE\sSIZE\s\(compressed\):\s\s)(.*)/) {
+ $slackdb{$pkg}[6] = "$2";
+ next;
+ }
+ if ($_ =~ /(^PACKAGE\sSIZE\s\(uncompressed\):\s\s)(.*)/) {
+ $slackdb{$pkg}[7] = "$2";
+ next;
+ }
+ else {
+ next;
+ }
+ return %slackdb;
}
}
#
# CSV
#
-sub s2csv {
+sub salix2csv {
open(C, ">pkgtxt.csv") or die "Unable to open pkgtxt.csv for writing, aborting.";
my $c = "\t";
print C "pkgname${c}pkgver${c}arch${c}pkgrel${c}location${c}dep${c}sizeC${c}sizeU\n";
@@ -133,12 +212,26 @@ sub s2csv {
$p, $pkgdb{$p}[1], $pkgdb{$p}[2], $pkgdb{$p}[3], $pkgdb{$p}[4], $pkgdb{$p}[5], $pkgdb{$p}[6], $pkgdb{$p}[7];
}
close (C);
+ print "Salix pkgtxt.csv has been built.\n";
}
+sub slack2csv {
+ open(D, ">pkgtxt.csv") or die "Unable to open pkgtxt.csv for writing, aborting.";
+ my $c = "\t";
+ print D "pkgname${c}pkgver${c}arch${c}pkgrel${c}location${c}dep${c}sizeC${c}sizeU\n";
+ for my $q ( sort keys %slackdb ) {
+ printf D "%s$c%s$c%s$c%s$c%s$c%s$c%s$c%s\n",
+ $q, $slackdb{$q}[1], $slackdb{$q}[2], $slackdb{$q}[3], $slackdb{$q}[4], $slackdb{$q}[5], $slackdb{$q}[6], $slackdb{$q}[7];
+ }
+ close (D);
+ print "Slackware pkgtxt.csv has been built.\n";
+}
+
+
#
# JSON
#
-sub s2json {
+sub salix2json {
my $out = "pkgtxt.json";
my $n = keys %pkgdb;
open(J, ">$out") or die "Unable to open $out for writing, aborting.";
@@ -169,6 +262,42 @@ sub s2json {
}
print J "\]\n";
close (J);
+ print "Salix pkgtxt.json has been built.\n";
}
+
+sub slack2json {
+ my $out = "pkgtxt.json";
+ my $nb = keys %slackdb;
+ open(K, ">$out") or die "Unable to open $out for writing, aborting.";
+ print K "\[\n";
+ for my $q ( (keys %slackdb)[0..($nb-2)] ) {
+ print K " \{\n";
+ print K " \"pkgname\": \"$q\",\n";
+ print K " \"pkgver\": \"$slackdb{$q}[1]\",\n";
+ print K " \"arch\": \"$slackdb{$q}[2]\",\n";
+ print K " \"pkgver\": \"$slackdb{$q}[3]\",\n";
+ print K " \"location\": \"$slackdb{$q}[4]\",\n";
+ print K " \"dep\": \"$slackdb{$q}[5]\",\n";
+ print K " \"sizeC\": \"$slackdb{$q}[6]\",\n";
+ print K " \"sizeU\": \"$slackdb{$q}[7]\"\n";
+ print K " \},\n";
+ }
+ for my $q ( (keys %slackdb)[($nb-1)] ) {
+ print K " \{\n";
+ print K " \"pkgname\": \"$q\",\n";
+ print K " \"pkgver\": \"$slackdb{$q}[1]\",\n";
+ print K " \"arch\": \"$slackdb{$q}[2]\",\n";
+ print K " \"pkgver\": \"$slackdb{$q}[3]\",\n";
+ print K " \"location\": \"$slackdb{$q}[4]\",\n";
+ print K " \"dep\": \"$slackdb{$q}[5]\",\n";
+ print K " \"sizeC\": \"$slackdb{$q}[6]\",\n";
+ print K " \"sizeU\": \"$slackdb{$q}[7]\"\n";
+ print K " \}\n";
+ }
+ print K "\]\n";
+ close (K);
+ print "Slackware pkgtxt.json has been built.\n";
+}
+
1;
blob - 1bf2469b12c00d7431d5ff55f1c4b804e65b6f86
blob + 494057b75e3aca9e25b6d651c693e51c63bb8783
--- pkgtxt2db
+++ pkgtxt2db
@@ -26,8 +26,16 @@ my $Pkgtxt2db = Pkgtxt2db->new();
sub usage {
print "Usage: $0 [options]\n\n";
print "Options:\n";
- print " -c | --csv\t\tconvert to a CSV database\n";
- print " -j | --json\t\tconvert to a JSON database\n";
+ print " -a | --asc32\t\tconvert Salix PACKAGES.TXT to a CSV DB\n";
+ print " -b | --bsc64\t\tconvert Salix64 PACKAGES.TXT to a CSV DB\n";
+ print " -c | --cslc32\t\tconvert Slackware PACKAGES.TXT to a CSV DB\n";
+ print " -d | --dslc64\t\tconvert Slackware64 PACKAGES.TXT to a CSV DB\n";
+ print "\n";
+ print " -e | --esj32\t\tconvert Salix PACKAGES.TXT to a JSON DB\n";
+ print " -f | --fsj64\t\tconvert Salix64 PACKAGES.TXT to a JSON DB\n";
+ print " -g | --gslj32\t\tconvert Slackware PACKAGES.TXT to a JSON DB\n";
+ print " -i | --islj64\t\tconvert Slackware64 PACKAGES.TXT to a JSON DB\n";
+ print "\n";
print " -h | --help\t\tprint this message\n";
print " -v | --version\t\tprint pkgtxt2db version\n";
exit 0;
@@ -38,14 +46,29 @@ sub usage {
#
my $version;
my $help;
-my $scsv;
-my $sjson;
+my $salix32csv;
+my $salix64csv;
+my $slack32csv;
+my $slack64csv;
+
+my $salix32json;
+my $salix64json;
+my $slack32json;
+my $slack64json;
+
+
GetOptions(
- 'version' => \$version,
- 'help' => \&usage,
- 'csv' => \$scsv,
- 'json' => \$sjson,
+ 'version' => \$version,
+ 'help' => \&usage,
+ 'asc32' => \$salix32csv,
+ 'bsc64' => \$salix64csv,
+ 'cslc32' => \$slack32csv,
+ 'dslc64' => \$slack64csv,
+ 'esj32' => \$salix32json,
+ 'fsj64' => \$salix64json,
+ 'gslj32' => \$slack32json,
+ 'islj64' => \$slack64json,
);
if ($version) {
print "Pkgtxt2db, version $VERSION\n";
@@ -53,20 +76,54 @@ if ($version) {
print "http://www.salixos.org/wiki/index.php/Pkgtxt2db\n";
exit 0;
}
-if ($scsv) {
- Pkgtxt2db->get_file($Pkgtxt2db::url32,$Pkgtxt2db::pkgtxt);
- Pkgtxt2db->salix_data();
- Pkgtxt2db->mkdadb();
- Pkgtxt2db->s2csv();
+if ($salix32csv) {
+ Pkgtxt2db->getsalix_d32();
+ Pkgtxt2db->mkdasalixdb();
+ Pkgtxt2db->salix2csv();
exit 0;
}
-if ($sjson) {
- Pkgtxt2db->get_file($Pkgtxt2db::url32,$Pkgtxt2db::pkgtxt);
- Pkgtxt2db->salix_data();
- Pkgtxt2db->mkdadb();
- Pkgtxt2db->s2json();
+if ($salix64csv) {
+ Pkgtxt2db->getsalix_d64();
+ Pkgtxt2db->mkdasalixdb();
+ Pkgtxt2db->salix2csv();
exit 0;
}
+if ($slack32csv) {
+ Pkgtxt2db->getslack_d32();
+ Pkgtxt2db->mkdaslackdb();
+ Pkgtxt2db->slack2csv();
+ exit 0;
+ }
+if ($slack64csv) {
+ Pkgtxt2db->getslack_d64();
+ Pkgtxt2db->mkdaslackdb();
+ Pkgtxt2db->slack2csv();
+ exit 0;
+ }
+if ($salix32json) {
+ Pkgtxt2db->getsalix_d32();
+ Pkgtxt2db->mkdasalixdb();
+ Pkgtxt2db->salix2json();
+ exit 0;
+ }
+if ($salix64json) {
+ Pkgtxt2db->getsalix_d64();
+ Pkgtxt2db->mkdasalixdb();
+ Pkgtxt2db->salix2json();
+ exit 0;
+ }
+if ($slack32json) {
+ Pkgtxt2db->getslack_d32();
+ Pkgtxt2db->mkdaslackdb();
+ Pkgtxt2db->slack2json();
+ exit 0;
+ }
+if ($slack64json) {
+ Pkgtxt2db->getslack_d64();
+ Pkgtxt2db->mkdaslackdb();
+ Pkgtxt2db->slack2json();
+ exit 0;
+ }
else {
die "Wrong usage, run pkgtxt2db --help for information.\n";
}
Frédéric Galusik