summaryrefslogtreecommitdiffstats
path: root/checkpkgist/checkpkgist.php
diff options
context:
space:
mode:
authorRemi Collet <fedora@famillecollet.com>2014-05-16 10:24:22 +0200
committerRemi Collet <fedora@famillecollet.com>2014-05-16 10:24:22 +0200
commit01cc66a23361366660fd1de194b4ec0777baa4f3 (patch)
treefaad7f79672e7be5039266bee48668e96c69af03 /checkpkgist/checkpkgist.php
parent9004d8e5985def5c4e85c603816b68180ad04d0d (diff)
checkpkgist: new tool, to check upstream new version, using packagist
Diffstat (limited to 'checkpkgist/checkpkgist.php')
-rwxr-xr-xcheckpkgist/checkpkgist.php98
1 files changed, 98 insertions, 0 deletions
diff --git a/checkpkgist/checkpkgist.php b/checkpkgist/checkpkgist.php
new file mode 100755
index 0000000..0a0c961
--- /dev/null
+++ b/checkpkgist/checkpkgist.php
@@ -0,0 +1,98 @@
+#!/usr/bin/php
+<?php
+require_once 'Cache/Lite.php';
+
+class PkgClient {
+ const URL = 'https://packagist.org/';
+ protected $cache;
+
+ function __construct () {
+ $dir = "/tmp/pkgist-".posix_getlogin()."/";
+ @mkdir($dir);
+ $this->cache = new Cache_Lite(
+ array(
+ 'memoryCaching' => true,
+ 'cacheDir' => $dir,
+ 'automaticSerialization' => true
+ )
+ );
+ }
+
+ function getPackage($name) {
+ $url = self::URL.'packages/'.$name.'.json';
+ $rep = $this->cache->get(__METHOD__, $url);
+ if (!$rep) {
+ $rep = @file_get_contents($url);
+ $this->cache->save($rep, __METHOD__, $url);
+ }
+ return ($rep ? json_decode($rep, true) : false);
+ }
+}
+
+if (in_array('-h', $_SERVER['argv']) || in_array('--help', $_SERVER['argv'])) {
+ echo <<<END
+
+usage checkpkg [ options ]
+
+ -h
+ --help Display help (this page)
+
+ -v
+ --verbose Display all packages, with upsteam information
+
+ -q
+ --quiet Don't display not installed packages
+ or packages with latest version installed
+END;
+ die("\n\n");
+}
+
+$verb = (in_array('-v', $_SERVER['argv']) || in_array('--verbose', $_SERVER['argv']));
+$quiet = (in_array('-q', $_SERVER['argv']) || in_array('--quiet', $_SERVER['argv']));
+$client = new PkgClient();
+
+$pkgs = file_get_contents(__DIR__."/checkpkgist.json");
+if (!$pkgs) {
+ die("Missing configuration file\n");
+}
+$pkgs = json_decode($pkgs, true, 5, JSON_PARSER_NOTSTRICT);
+if (!$pkgs) {
+ die("Bad configuration file\n");
+}
+
+printf(" %-40s %15s %15s\n", "Name", "Version", "Upstream");
+
+foreach ($pkgs as $name => $rpm) {
+ $rpmver = exec("rpm -q --qf '%{VERSION}' $rpm", $out, $ret);
+ if ($ret) {
+ if ($quiet) {
+ continue;
+ }
+ $rpmver = "n/a";
+ }
+ $pkgs = $client->getPackage($name);
+ if ($pkgs) {
+ foreach ($pkgs['package']['versions'] as $pkver => $pkg) {
+ if (strpos($pkver, 'dev') !== false) {
+ continue;
+ }
+ if (version_compare($pkver, $rpmver, 'gt')) {
+ if ($pkg['source']['type']=='git') {
+ printf(" %-40s %15s %15s\n", $rpm, $rpmver, $pkver);
+ if ($verb) {
+ printf("\tURL: %s\n\tHash: %s\n",
+ ($pkg['source']['url']?:'unkown'),
+ ($pkg['source']['reference']?:'unkown'));
+ }
+ }
+ break;
+ }
+ else if (version_compare($pkver, $rpmver, 'eq') && $verb) {
+ printf(" %-40s %15s %15s\n", $rpm, $rpmver, $pkver);
+ break;
+ }
+ }
+ } else {
+ printf(" %-40s %15s %15s\n", $rpm, $rpmver, 'Not found !');
+ }
+} \ No newline at end of file