summaryrefslogtreecommitdiffstats
path: root/fedcli.php
blob: 0588cafe285919c1ba7e937edee865e812237043 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/usr/bin/php
<?php
/*
 * FedoraClient is a PHP classe to interact with web services
 *
 * fedcli.php is a command line tools to test FedoraClient clmsses
 *
 * Copyright (C) 2010-2013  Remi Collet
 * http://github.com/remicollet/rpmphp.
 *
 * Inspired from python-fedora
 *
 * FedoraClient is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * python-fedora is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * See <http://www.gnu.org/licenses/>
 */

define ('CLIONLY', true);

require 'include/main.php';
require 'Console/Getargs.php';

function Help() {
   echo "\nFedora Client Command Line usage\n\n";

   echo "fdcli   command   options\n";
   echo "\tbranch:   branch info\n";
   echo "\tbranches: list branches\n";
   echo "\tcritpath: list critical path\n";
   echo "\tpackage:  package info\n";
   echo "\tversion:  class version\n";
   echo "Also try fdcli command --help\n";
}

function Branches() {
   $config = array(
     "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);

   if (PEAR::isError($args)) {
      die (Console_Getargs::getHelp($config));
   }

   $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." ";
   }
   echo "\n";
}

function Branch() {
   $config = array(
     "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);

   if (PEAR::isError($args)) {
      die (Console_Getargs::getHelp($config));
   }

   $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"),
     "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);

   if (PEAR::isError($args)) {
      die (Console_Getargs::getHelp($config));
   }

   $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"),
     "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')),
                                   'server' => $args->getValue('server')));
   $rep = $client->getPackageInfo($args->getValue('package'), intval($args->getValue('refresh')));

   if (!$rep) {
      die("Package not found\n");
   }

   $first = true;
   foreach ($rep as $branch => $pack) {
      if ($first) {
         $first = false;
         echo 'Name:       '.$pack['package']['name']."\n";
         echo 'Summary:    '.$pack['package']['summary']."\n";
         echo "Description:\n".$pack['package']['description']."\n";
      }
      echo $branch.":\t".$pack['owner'];

      $i=0;
      $tmp = array();
      foreach ($pack['people'] as $user) {
         if (isset($user['aclOrder']['commit']['statuscode']) && $user['aclOrder']['commit']['statuscode']==3) {
            $tmp[] = $user['username'];
         }
      }
      if (count($tmp)) {
        sort($tmp);
        echo " (".implode($tmp, ', ').")\n";
      } else {
        echo "\n";
      }
   }

}

function Version() {
   $config = array(
   "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);

   if (PEAR::isError($args)) {
      die (Console_Getargs::getHelp($config)."\n");
   }

   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();
}