summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemi Collet <fedora@famillecollet.com>2013-11-17 17:46:48 +0100
committerRemi Collet <fedora@famillecollet.com>2013-11-17 17:46:48 +0100
commitbe9f96e74ef96c85ef0b9c11c30f220c140ad48a (patch)
tree81105b8299b8f71fadb7a294d9157ee352180e7f
parent267655746e046f63a26cba2c57439fd9469db51a (diff)
WIP for pkgdb2
-rw-r--r--class/FedoraClient.php25
-rw-r--r--class/FedoraPkgdb.php147
-rwxr-xr-xfedcli.php66
3 files changed, 159 insertions, 79 deletions
diff --git a/class/FedoraClient.php b/class/FedoraClient.php
index 62f8eac..7aa2bbb 100644
--- a/class/FedoraClient.php
+++ b/class/FedoraClient.php
@@ -42,7 +42,7 @@ require_once 'Cache/Lite.php';
abstract class FedoraClient
{
- const VERSION='0.1.0-dev';
+ const VERSION='0.2.0-dev';
protected $url;
private $_agent;
private $_debug = 0;
@@ -60,18 +60,30 @@ abstract class FedoraClient
)
);
- $this->url = $url;
+ if (isset($options['debug']) && intval($options['debug'])>0) {
+ $this->_debug = intval($options['debug']);
+ }
+
+ $this->setUrl($url);
+
if (isset($options['agent']) && !empty($options['agent'])) {
$this->_agent = $options['agent'];
} else {
$this->_agent = 'Fedora PHPClient/'.self::VERSION;
}
- if (isset($options['debug']) && intval($options['debug'])>0) {
- $this->_debug = intval($options['debug']);
- }
+
+ $this->logDebug(
+ 3,
+ __CLASS__."::".__FUNCTION__.": agent='".$this->_agent."'"
+ );
+ }
+
+ function setUrl($url)
+ {
+ $this->url = $url;
$this->logDebug(
3,
- __CLASS__."::".__FUNCTION__.": url='$url', agent='".$this->_agent."'"
+ __CLASS__."::".__FUNCTION__.": url='$url'"
);
}
@@ -161,4 +173,3 @@ abstract class FedoraClient
}
}
-?> \ No newline at end of file
diff --git a/class/FedoraPkgdb.php b/class/FedoraPkgdb.php
index 15ddf50..da43986 100644
--- a/class/FedoraPkgdb.php
+++ b/class/FedoraPkgdb.php
@@ -7,7 +7,7 @@
*
* PHP version 5
*
- * Copyright (C) 2010 Remi Collet
+ * Copyright (C) 2010-2013 Remi Collet
* http://github.com/remicollet/rpmphp.
*
* Inspired from python-fedora
@@ -29,7 +29,7 @@
*
* @author Remi Collet <unknown@unknwown.com>
* @author Johan Cwiklinski <johan@x-tnd.be>
- * @copyright 2010 Remi Collet
+ * @copyright 2010-2013 Remi Collet
* @license http://www.gnu.org/licenses/lgpl-2.1.txt LGPL License 2.1 or (at your option) any later version
* @link http://github.com/remicollet/rpmphp/
* @since The begining of times.
@@ -37,41 +37,65 @@
class FedoraPkgdb extends FedoraClient
{
- private $_suburl;
+ private $_version = 0;
function __construct (array $options=array())
{
- parent::__construct('https://admin.fedoraproject.org/pkgdb/', $options);
- $this->_suburl = 'acls/name/';
+ if (isset($options['server']) && ($options['server'])) {
+ $server = $options['server'];
+ } else {
+ $server = 'admin.fedoraproject.org';
+ }
+ parent::__construct("http://$server/api/", $options);
+
+ $rep = $this->cache->get(__METHOD__, $this->url);
+ if ($rep!==false) {
+ $this->logDebug(2, __METHOD__."() get from cache");
+ } else {
+ $rep =$this->sendRequest('version');
+ $this->cache->save($rep, __METHOD__, $this->url);
+ $this->logDebug(2, __METHOD__."() save to cache"
+ );
+ }
+
+ if (isset($rep['version'])) {
+ /* Pkgdb2 */
+ $this->_version = $rep['version'];
+ } else {
+ /* Pkgdb */
+ $this->setUrl("https://$server/pkgdb/");
+ }
+ }
- $this->logDebug(
- 3,
- __CLASS__."::".__FUNCTION__
- );
+ function getVersion()
+ {
+ return $this->_version;
}
function getBranches($refresh=false)
{
- $rep = ($refresh ? false : $this->cache->get(__FUNCTION__, __CLASS__));
+ $rep = ($refresh ? false : $this->cache->get(__METHOD__, $this->url));
if ($rep) {
- $this->logDebug(
- 2,
- __CLASS__."::".__FUNCTION__."() get from cache"
- );
+ $this->logDebug(2, __METHOD__."() get from cache");
} else {
$rep =$this->sendRequest('collections');
- $this->cache->save($rep, __FUNCTION__, __CLASS__);
- $this->logDebug(
- 2,
- __CLASS__."::".__FUNCTION__."() save to cache"
- );
+ $this->cache->save($rep, __METHOD__, $this->url);
+ $this->logDebug(2, __METHOD__."() save to cache");
}
$branches = array();
if (isset($rep['collections'])) {
- foreach ($rep['collections'] as $coll) {
- if (isset($coll[0]['branchname'])) {
- $branches[$coll[0]['branchname']] = $coll[0];
+ if ($this->_version > 0) {
+ foreach ($rep['collections'] as $coll) {
+ if (isset($coll['branchname'])) { /* pkgdb version 2 */
+ $branches[$coll['branchname']] = $coll;
+ }
+ }
+ } else {
+ foreach ($rep['collections'] as $coll) {
+ if (isset($coll[0]['branchname'])) { /* pkgdb version 1 */
+ $branches[$coll[0]['branchname']] = $coll[0];
+ }
}
}
}
@@ -80,32 +104,37 @@ class FedoraPkgdb extends FedoraClient
function getPackageURL($name)
{
- return $this->url.$this->_suburl.$name;
+ return $this->url.'acls/name/'.$name;
}
function getPackageInfo($name, $refresh=false)
{
- $url=$this->_suburl.urlencode($name);
- $rep = ($refresh ? false : $this->cache->get($url, __CLASS__));
+ if ($this->_version > 0) {
+ $url='package/acl/get/'.urlencode($name);
+ $rep = ($refresh ? false : $this->cache->get(__METHOD__, $this->url.$url));
+ if ($rep) {
+ $this->logDebug(2, __METHOD__."($name) get from cache");
+ } else {
+ $rep =$this->sendRequest($url);
+ $this->cache->save($rep, __METHOD__, $this->url.$url);
+ $this->logDebug(2, __METHOD__."($name) save to cache");
+ }
+ $this->logDebug(8, print_r($rep, true));
+ return false;
+ }
+
+ $url='acls/name/'.urlencode($name);
+ $rep = ($refresh ? false : $this->cache->get(__METHOD__, $this->url.$url));
if ($rep) {
- $this->logDebug(
- 2,
- __CLASS__."::".__FUNCTION__."($name) get from cache"
- );
+ $this->logDebug(2, __METHOD__."($name) get from cache");
} else {
$rep =$this->sendRequest($url);
- $this->cache->save($rep, $url, __CLASS__);
- $this->logDebug(
- 2,
- __CLASS__."::".__FUNCTION__."($name) save to cache"
- );
+ $this->cache->save($rep, __METHOD__, $this->url.$url);
+ $this->logDebug(2, __METHOD__."($name) save to cache");
}
if (isset($rep['status']) && !$rep['status']) {
- $this->logDebug(
- 1,
- __CLASS__."::".__FUNCTION__."($name) ".$rep['message']
- );
+ $this->logDebug(1, __METHOD__."($name) ".$rep['message']);
return false;
}
$this->logDebug(8, print_r($rep, true));
@@ -119,6 +148,18 @@ class FedoraPkgdb extends FedoraClient
function getBranch($name, $refresh=false)
{
+ if ($this->_version > 0) {
+ $url='collections/'.urlencode($name).'/';
+ $rep = ($refresh ? false : $this->cache->get(__METHOD__, $this->url.$url));
+ if ($rep) {
+ $this->logDebug(2, __METHOD__."($name) get from cache");
+ } else {
+ $rep =$this->sendRequest($url);
+ $this->cache->save($rep, __METHOD__, $this->url.$url);
+ $this->logDebug(2, __METHOD__."($name) save to cache");
+ }
+ return (isset($rep['collections'][0]) ? $rep['collections'][0] : array());
+ }
$branches = $this->getBranches($refresh);
if (isset($branches[$name])) {
@@ -129,22 +170,30 @@ class FedoraPkgdb extends FedoraClient
function getCritPath($refresh=false)
{
+ if ($this->_version > 0) {
+ $url="critpath";
+ $rep = ($refresh ? false : $this->cache->get(__METHOD__, $this->url));
+ if ($rep) {
+ $this->logDebug(2, __METHOD__."() get from cache");
+ } else {
+ $rep =$this->sendRequest($url);
+ $this->cache->save($rep, __METHOD__, $this->url);
+ $this->logDebug(2, __METHOD__."() save to cache");
+ }
+ return (isset($rep['pkgs']) ? $rep['pkgs'] : NULL);
+ }
+
$url="lists/critpath";
- $rep = ($refresh ? false : $this->cache->get($url, __CLASS__));
+ $rep = ($refresh ? false : $this->cache->get(__METHOD__, $this->url));
if ($rep) {
- $this->logDebug(
- 2,
- __CLASS__."::".__FUNCTION__." get from cache"
- );
+ $this->logDebug(2, __METHOD__."() get from cache");
} else {
$rep =$this->sendRequest($url);
- $this->cache->save($rep, $url, __CLASS__);
- $this->logDebug(
- 2,
- __CLASS__."::".__FUNCTION__." save to cache"
+ $this->cache->save($rep, __METHOD__, $this->url);
+ $this->logDebug(2, __METHOD__."() save to cache"
);
}
- return $rep['pkgs'];
+ return (isset($rep['pkgs']) ? $rep['pkgs'] : NULL);
}
}
-?> \ No newline at end of file
+
diff --git a/fedcli.php b/fedcli.php
index a604ae8..0588caf 100755
--- a/fedcli.php
+++ b/fedcli.php
@@ -5,7 +5,7 @@
*
* fedcli.php is a command line tools to test FedoraClient clmsses
*
- * Copyright (C) 2010 Remi Collet
+ * Copyright (C) 2010-2013 Remi Collet
* http://github.com/remicollet/rpmphp.
*
* Inspired from python-fedora
@@ -42,7 +42,9 @@ function Help() {
function Branches() {
$config = array(
- "debug" => array('short' => 'd', 'max' => 1, 'min' => 1, 'desc' => "debug level", 'default' => "0")
+ "server" => array('short' => 's', 'max' => 1, 'min' => 1, 'desc' => "server URL", 'default' => ""),
+ "debug" => array('short' => 'd', 'max' => 1, 'min' => 1, 'desc' => "debug level", 'default' => "0"),
+ "refresh" => array('short' => 'r', 'max' => 1, 'min' => 1, 'desc' => "refresh cache", 'default' => "0"),
);
$args =& Console_Getargs::factory($config);
@@ -50,8 +52,9 @@ function Branches() {
die (Console_Getargs::getHelp($config));
}
- $client = new FedoraPkgdb(array('debug' => intval($args->getValue('debug'))));
- $branches = $client->getBranches();
+ $client = new FedoraPkgdb(array('debug' => intval($args->getValue('debug')),
+ 'server' => $args->getValue('server')));
+ $branches = $client->getBranches(intval($args->getValue('refresh')));
foreach ($branches as $name => $branch) {
echo $name." ";
}
@@ -60,8 +63,10 @@ function Branches() {
function Branch() {
$config = array(
- "branch" => array('short' => 'b', 'max' => 1, 'min' => 1, 'desc' => "branch name", 'default' => "devel"),
- "debug" => array('short' => 'd', 'max' => 1, 'min' => 1, 'desc' => "debug level", 'default' => "0")
+ "server" => array('short' => 's', 'max' => 1, 'min' => 1, 'desc' => "server URL", 'default' => ""),
+ "branch" => array('short' => 'b', 'max' => 1, 'min' => 1, 'desc' => "branch name", 'default' => "devel"),
+ "debug" => array('short' => 'd', 'max' => 1, 'min' => 1, 'desc' => "debug level", 'default' => "0"),
+ "refresh" => array('short' => 'r', 'max' => 1, 'min' => 1, 'desc' => "refresh cache", 'default' => "0"),
);
$args =& Console_Getargs::factory($config);
@@ -69,15 +74,18 @@ function Branch() {
die (Console_Getargs::getHelp($config));
}
- $client = new FedoraPkgdb(array('debug' => intval($args->getValue('debug'))));
- $branch = $client->getBranch($args->getValue('branch'));
+ $client = new FedoraPkgdb(array('debug' => intval($args->getValue('debug')),
+ 'server' => $args->getValue('server')));
+ $branch = $client->getBranch($args->getValue('branch'), intval($args->getValue('refresh')));
print_r($branch);
}
function CritPath() {
$config = array(
//"branch" => array('short' => 'b', 'max' => 1, 'min' => 1, 'desc' => "branch name", 'default' => "devel"),
- "debug" => array('short' => 'd', 'max' => 1, 'min' => 1, 'desc' => "debug level", 'default' => "0")
+ "server" => array('short' => 's', 'max' => 1, 'min' => 1, 'desc' => "server URL", 'default' => ""),
+ "debug" => array('short' => 'd', 'max' => 1, 'min' => 1, 'desc' => "debug level", 'default' => "0"),
+ "refresh" => array('short' => 'r', 'max' => 1, 'min' => 1, 'desc' => "refresh cache", 'default' => "0"),
);
$args =& Console_Getargs::factory($config);
@@ -85,23 +93,29 @@ function CritPath() {
die (Console_Getargs::getHelp($config));
}
- $client = new FedoraPkgdb(array('debug' => intval($args->getValue('debug'))));
- $branch = $client->getCritPath();
- print_r($branch);
+ $client = new FedoraPkgdb(array('debug' => intval($args->getValue('debug')),
+ 'server' => $args->getValue('server')));
+ $crit = $client->getCritPath(intval($args->getValue('refresh')));
+ foreach ($crit as $name => $pkgs) {
+ echo "\n$name: ".implode(', ', $pkgs)."\n";
+ }
}
function Package() {
$config = array(
+ "server" => array('short' => 's', 'max' => 1, 'min' => 1, 'desc' => "server URL", 'default' => ""),
"package" => array('short' => 'p', 'max' => 1, 'min' => 1, 'desc' => "package name"),
- "debug" => array('short' => 'd', 'max' => 1, 'min' => 1, 'desc' => "debug level", 'default' => "0")
+ "debug" => array('short' => 'd', 'max' => 1, 'min' => 1, 'desc' => "debug level", 'default' => "0"),
+ "refresh" => array('short' => 'r', 'max' => 1, 'min' => 1, 'desc' => "refresh cache", 'default' => "0"),
);
$args =& Console_Getargs::factory($config);
if (PEAR::isError($args)) {
die (Console_Getargs::getHelp($config));
}
- $client = new FedoraPkgdb(array('debug' => intval($args->getValue('debug'))));
- $rep = $client->getPackageInfo($args->getValue('package'));
+ $client = new FedoraPkgdb(array('debug' => intval($args->getValue('debug')),
+ 'server' => $args->getValue('server')));
+ $rep = $client->getPackageInfo($args->getValue('package'), intval($args->getValue('refresh')));
if (!$rep) {
die("Package not found\n");
@@ -136,7 +150,8 @@ function Package() {
function Version() {
$config = array(
- "debug" => array('short' => 'd', 'max' => 1, 'min' => 1, 'desc' => "debug level", 'default' => "0")
+ "server" => array('short' => 's', 'max' => 1, 'min' => 1, 'desc' => "server URL", 'default' => ""),
+ "debug" => array('short' => 'd', 'max' => 1, 'min' => 1, 'desc' => "debug level", 'default' => "0")
);
$args =& Console_Getargs::factory($config);
@@ -145,17 +160,22 @@ function Version() {
}
echo "PHP Fedora Client class version ".FedoraClient::VERSION."\n";
+ $client = new FedoraPkgdb(array('debug' => intval($args->getValue('debug')),
+ 'server' => $args->getValue('server')));
+ echo "pkgdb version ".$client->getVersion()."\n";
}
+error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT);
+
$cmd = array_shift($_SERVER['argv']);
$cmd = array_shift($_SERVER['argv']);
switch ($cmd) {
- case 'branches': Branches(); break;
- case 'branch': Branch(); break;
- case 'critpath': CritPath(); break;
- case 'package': Package(); break;
- case 'version': Version(); break;
- default: Help();
+ case 'branches' : Branches(); break;
+ case 'branch' : Branch(); break;
+ case 'critpath' : CritPath(); break;
+ case 'package' : Package(); break;
+ case 'version' : Version(); break;
+ default : Help();
}
-?>
+