summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemi Collet <fedora@famillecollet.com>2010-05-23 17:12:20 +0200
committerRemi Collet <fedora@famillecollet.com>2010-05-23 17:12:20 +0200
commitbc796fd68e1faae3260c186ac446c3a75ac1ecf5 (patch)
tree778ca8c2177b81c229f9c9520704cd4b43d01a0d
parent9cc3e2d35597302a3c831c5787cd18b90218b434 (diff)
Add FedoraPkgdb->getBranch(), improves fedcli.php
-rw-r--r--FedoraClient.php23
-rwxr-xr-xfedcli.php72
2 files changed, 81 insertions, 14 deletions
diff --git a/FedoraClient.php b/FedoraClient.php
index 891b7f3..1a33ac9 100644
--- a/FedoraClient.php
+++ b/FedoraClient.php
@@ -41,7 +41,7 @@ abstract class FedoraClient {
if (isset($options['agent']) && !empty($options['agent'])) {
$this->agent = $options['agent'];
} else {
- $this->agent = 'PHP FedoraClient/'.FEDORACLIENT_VERSION;
+ $this->agent = 'Fedora PHPClient/'.FEDORACLIENT_VERSION;
}
if (isset($options['debug']) && intval($options['debug'])>0) {
$this->debug = intval($options['debug']);
@@ -74,7 +74,7 @@ abstract class FedoraClient {
curl_setopt($curl, CURLOPT_HTTPHEADER, array('User-agent: '.$this->agent, 'Accept: application/json'));
# run the request
- $this->logDebug(1,__CLASS__."::".__FUNCTION__.": call '$url'");
+ $this->logDebug(2,__CLASS__."::".__FUNCTION__.": call '$url'");
curl_exec($curl);
@@ -93,7 +93,7 @@ abstract class FedoraClient {
$this->logDebug(2,__CLASS__."::".__FUNCTION__.": http_status '$http_status'");
}
- $this->logDebug(1,__CLASS__."::".__FUNCTION__.": close connexion");
+ $this->logDebug(2,__CLASS__."::".__FUNCTION__.": close connexion");
curl_close($curl);
return json_decode($this->data, true);
@@ -116,7 +116,7 @@ class FedoraPkgdb extends FedoraClient {
}
function getBranches($refresh=false) {
- $rep = $this->cache->get(__FUNCTION__,__CLASS__);
+ $rep = ($refresh ? false : $this->cache->get(__FUNCTION__,__CLASS__));
if ($rep) {
$this->logDebug(2,__CLASS__."::".__FUNCTION__." get from cache");
} else {
@@ -125,13 +125,22 @@ class FedoraPkgdb extends FedoraClient {
$this->logDebug(2,__CLASS__."::".__FUNCTION__." save to cache");
}
- $this->branches = array();
+ $branches = array();
if (isset($rep['collections'])) {
foreach ($rep['collections'] as $coll) if (isset($coll[0]['branchname'])) {
- $this->branches[$coll[0]['branchname']] = $coll[0];
+ $branches[$coll[0]['branchname']] = $coll[0];
}
}
- return $this->branches;
+ return $branches;
+ }
+
+ function getBranch($name, $refresh=false) {
+ $branches = $this->getBranches($refresh);
+
+ if (isset($branches[$name])) {
+ return $branches[$name];
+ }
+ return false;
}
}
?>
diff --git a/fedcli.php b/fedcli.php
index 1bc48f3..d8439ff 100755
--- a/fedcli.php
+++ b/fedcli.php
@@ -23,14 +23,72 @@
* See <http://www.gnu.org/licenses/>
*/
-require('FedoraClient.php');
+require 'Console/Getargs.php';
+require 'FedoraClient.php';
-$client = new FedoraPkgdb(array('debug'=>2));
+function Help() {
+ echo "\nFedora Client Command Line usage\n\n";
+
+ echo "fdcli command options\n";
+ echo "\tbranches: list branches\n";
+ echo "\tversion: class version\n";
+ echo "Also try fdcli command --help\n";
+}
+
+function Branches() {
+ $config = array(
+ "debug" => array('short' => 'd', 'max' => 1, 'min' => 1, 'desc' => "debug level", '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'))));
+ $branches = $client->getBranches();
+ foreach ($branches as $name => $branch) {
+ echo $name." ";
+ }
+ echo "\n";
+}
+
+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")
+ );
+ $args =& Console_Getargs::factory($config);
+
+ if (PEAR::isError($args)) {
+ die (Console_Getargs::getHelp($config));
+ }
+
+ $client = new FedoraPkgdb(array('debug' => intval($args->getValue('debug'))));
+ $branch = $client->getBranch($args->getValue('branch'));
+ print_r($branch);
+}
+
+function Version() {
+ $config = array(
+ "debug" => array('short' => 'd', 'max' => 1, 'min' => 1, 'desc' => "debug level", 'default' => "0")
+ );
+ $args =& Console_Getargs::factory($config);
+
+ if (PEAR::isError($args)) {
+ die (Console_Getargs::getHelp($config)."\n");
+ }
+
+ echo "PHP Fedora Client class version ".FEDORACLIENT_VERSION."\n";
+}
+
+$cmd = array_shift($_SERVER['argv']);
+$cmd = array_shift($_SERVER['argv']);
-echo "FedoraPkgdb::getBranches():\n";
-$branches = $client->getBranches();
-foreach ($branches as $name => $branch) {
- echo $name." ";
+switch ($cmd) {
+ case 'branches': Branches(); break;
+ case 'branch': Branch(); break;
+ case 'version': Version(); break;
+ default: Help();
}
-echo "\ndone.\n";
?>