summaryrefslogtreecommitdiffstats
path: root/checkpkgist/checkpkgist.php
diff options
context:
space:
mode:
authorRemi Collet <fedora@famillecollet.com>2014-09-14 15:38:58 +0200
committerRemi Collet <fedora@famillecollet.com>2014-09-14 15:38:58 +0200
commitb678e203f28da7fae229d65a4e0bb9c8c745a47d (patch)
tree41b02da661c69da7b19f04523f61c7fe104dcb52 /checkpkgist/checkpkgist.php
parentcca9c13bd4930bb972e18e4a2d6001004c861c2b (diff)
checkpkgist: allow package name as argument
Diffstat (limited to 'checkpkgist/checkpkgist.php')
-rwxr-xr-xcheckpkgist/checkpkgist.php139
1 files changed, 78 insertions, 61 deletions
diff --git a/checkpkgist/checkpkgist.php b/checkpkgist/checkpkgist.php
index f1257c7..b282b88 100755
--- a/checkpkgist/checkpkgist.php
+++ b/checkpkgist/checkpkgist.php
@@ -61,11 +61,76 @@ class PkgClient {
}
}
+function run($name, $rpm) {
+ global $quiet, $verb, $client;
+
+ if (!$quiet) {
+ printf(" %-40s\r", $rpm);
+ }
+
+ $rpmver = exec("rpm -q --qf '%{VERSION}' $rpm", $out, $ret);
+ if ($ret) {
+ if ($quiet) {
+ return;
+ }
+ $rpmver = "n/a";
+ }
+ $pkgs = $client->getPackage($name);
+ if ($pkgs) {
+ $maxver = "";
+ $maxdat = false;
+ $display = false;
+ foreach ($pkgs['package']['versions'] as $pkver => $pkg) {
+ if (preg_match('/^v[\.0-9]*$/', $pkver)) {
+ $pkver = substr($pkver, 1);
+ }
+ if (strpos($pkver, 'dev') !== false) {
+ continue;
+ }
+ $date = new DateTime($pkg['time']);
+ if (version_compare($pkver, $maxver, 'gt')) {
+ $maxver = $pkver;
+ $maxdat = $date;
+ }
+ if (version_compare($pkver, $rpmver, 'gt')) {
+ $diff = $date->diff(new DateTime("now"));
+ if ($diff->days <2) {
+ $note = "(Just released)";
+ } else if ($diff->days <20) {
+ $note = $diff->format("(%a days)");
+ } else {
+ $note = "";
+ }
+
+ //print_r($pkg);
+ printf(" %-40s %15s %15s %15s %s\n", $rpm, $rpmver, $pkver, $date->format("Y-m-d"), $note);
+ if ($pkg['source']['type']=='git' && $verb) {
+ printf("\tURL: %s\n\tHash: %s\n",
+ ($pkg['source']['url']?:'unkown'),
+ ($pkg['source']['reference']?:'unkown'));
+ }
+ $display = true;
+ break;
+ }
+ else if (version_compare($pkver, $rpmver, 'eq') && $verb) {
+ printf(" %-40s %15s %15s %15s\n", $rpm, $rpmver, $pkver, $date->format("Y-m-d"));
+ $display = true;
+ break;
+ }
+ }
+ if ($verb && !$display) {
+ printf(" %-40s %15s %15s %15s\n", $rpm, $rpmver, ($maxver ?: 'unkown'), ($maxdat ? $date->format("Y-m-d") : ''));
+ }
+ } else {
+ printf(" %-40s %15s %15s\n", $rpm, $rpmver, 'Not found !');
+ }
+}
+
printf("\nCheckPkgist version %s by Remi Collet.\n\n", VERSION);
if (in_array('-h', $_SERVER['argv']) || in_array('--help', $_SERVER['argv'])) {
echo <<<END
-usage checkpkg [ options ]
+usage checkpkg [ options ] [ name ... ]
-h
--help Display help (this page)
@@ -125,66 +190,18 @@ if ($sort) {
}
printf(" %-40s %15s %15s %15s\n", "Name", "Version", "Upstream", "Date");
-foreach ($pkgs as $name => $rpm) {
- if (!$quiet) {
- printf(" %-40s\r", $rpm);
- }
-
- $rpmver = exec("rpm -q --qf '%{VERSION}' $rpm", $out, $ret);
- if ($ret) {
- if ($quiet) {
- continue;
- }
- $rpmver = "n/a";
- }
- $pkgs = $client->getPackage($name);
- if ($pkgs) {
- $maxver = "";
- $maxdat = false;
- $display = false;
- foreach ($pkgs['package']['versions'] as $pkver => $pkg) {
- if (preg_match('/^v[\.0-9]*$/', $pkver)) {
- $pkver = substr($pkver, 1);
- }
- if (strpos($pkver, 'dev') !== false) {
- continue;
- }
- $date = new DateTime($pkg['time']);
- if (version_compare($pkver, $maxver, 'gt')) {
- $maxver = $pkver;
- $maxdat = $date;
- }
- if (version_compare($pkver, $rpmver, 'gt')) {
- $diff = $date->diff(new DateTime("now"));
- if ($diff->days <2) {
- $note = "(Just released)";
- } else if ($diff->days <20) {
- $note = $diff->format("(%a days)");
- } else {
- $note = "";
- }
-
- //print_r($pkg);
- printf(" %-40s %15s %15s %15s %s\n", $rpm, $rpmver, $pkver, $date->format("Y-m-d"), $note);
- if ($pkg['source']['type']=='git' && $verb) {
- printf("\tURL: %s\n\tHash: %s\n",
- ($pkg['source']['url']?:'unkown'),
- ($pkg['source']['reference']?:'unkown'));
- }
- $display = true;
- break;
- }
- else if (version_compare($pkver, $rpmver, 'eq') && $verb) {
- printf(" %-40s %15s %15s %15s\n", $rpm, $rpmver, $pkver, $date->format("Y-m-d"));
- $display = true;
- break;
- }
- }
- if ($verb && !$display) {
- printf(" %-40s %15s %15s %15s\n", $rpm, $rpmver, ($maxver ?: 'unkown'), ($maxdat ? $date->format("Y-m-d") : ''));
- }
- } else {
- printf(" %-40s %15s %15s\n", $rpm, $rpmver, 'Not found !');
+$tmp = array();
+for ($i=1 ; $i<$_SERVER['argc'] ; $i++) {
+ $k = array_search($_SERVER['argv'][$i], $pkgs);
+ if ($k) {
+ $tmp[$k] = $pkgs[$k];
}
}
+if (count($tmp)) {
+ $verb = true;
+ $pkgs = $tmp;
+}
+foreach ($pkgs as $name => $rpm) {
+ run($name, $rpm);
+}
echo str_repeat(' ', 50)."\n";