| [ Index ] |
PHP Cross Reference of Akelos Framework |
[Summary view] [Print] [Text view]
1 <?php 2 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 3 4 // +----------------------------------------------------------------------+ 5 // | Akelos Framework - http://www.akelos.org | 6 // +----------------------------------------------------------------------+ 7 // | Copyright (c) 2002-2006, Akelos Media, S.L. & Bermi Ferrer Martinez | 8 // | Released under the GNU Lesser General Public License, see LICENSE.txt| 9 // +----------------------------------------------------------------------+ 10 11 /** 12 * @package ActiveSupport 13 * @subpackage Scripts 14 * @author Bermi Ferrer <bermi a.t akelos c.om> 15 * @copyright Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org 16 * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html> 17 */ 18 19 error_reporting(defined('AK_ERROR_REPORTING_ON_SCRIPTS') ? AK_ERROR_REPORTING_ON_SCRIPTS : 0); 20 require_once (AK_LIB_DIR.DS.'Ak.php'); 21 require_once (AK_LIB_DIR.DS.'AkObject.php'); 22 require_once (AK_LIB_DIR.DS.'AkInflector.php'); 23 require_once (AK_LIB_DIR.DS.'AkPlugin.php'); 24 require_once (AK_LIB_DIR.DS.'AkPlugin/AkPluginManager.php'); 25 defined('AK_SKIP_DB_CONNECTION') && AK_SKIP_DB_CONNECTION ? ($dsn='') : Ak::db(&$dsn); 26 27 $ak_app_dir = AK_APP_DIR; 28 $script_name = array_shift($argv); 29 $command = strtolower(array_shift($argv)); 30 array_unshift($argv, $script_name); 31 $_SERVER['argv'] = $argv; 32 33 $available_commands = array('help','test','list', 'sources', 'source', 'unsource', 'discover', 'install', 'update', 'remove', 'info'); 34 35 if(!in_array($command, $available_commands)){ 36 echo <<<BANNER 37 Usage: {$script_name} command [OPTIONS] 38 39 Akelos plugin manager. 40 41 COMMANDS 42 43 discover Discover plugin repositories. 44 list List available plugins. 45 install Install plugin(s) from known repositories or URLs. 46 update Update installed plugins. 47 remove Uninstall plugins. 48 source Add a plugin source repository. 49 unsource Remove a plugin repository. 50 sources List currently configured plugin repositories. 51 test Run the unit tests for the plugin 52 help Shows the plugin README help file 53 54 55 EXAMPLES 56 57 Install a plugin: 58 {$script_name} install acts_as_versioned 59 60 Install a plugin from a subversion URL: 61 {$script_name} install http://svn.akelos.org/plugins/acts_as_versioned 62 63 Install a plugin and add a svn:externals entry to app/vendor/plugins 64 {$script_name} install -x acts_as_versioned 65 66 List all available plugins: 67 {$script_name} list 68 69 List plugins in the specified repository: 70 {$script_name} list --source=http://svn.akelos.org/plugins/ 71 72 Discover and prompt to add new repositories: 73 {$script_name} discover 74 75 Discover new repositories but just list them, don't add anything: 76 {$script_name} discover -l 77 78 Add a new repository to the source list: 79 {$script_name} source http://svn.akelos.org/plugins/ 80 81 Remove a repository from the source list: 82 {$script_name} unsource http://svn.akelos.org/plugins/ 83 84 Show currently configured repositories: 85 {$script_name} sources 86 87 Test a plugin 88 {$script_name} test acts_as_versioned 89 90 Help for a given plugin 91 {$script_name} help calendar_helper 92 93 BANNER; 94 exit; 95 } 96 97 98 set_time_limit(0); 99 error_reporting(E_ALL); 100 101 require_once (AK_VENDOR_DIR.DS.'pear'.DS.'Console'.DS.'Getargs.php'); 102 function get_console_options_for($description, $console_configuration) 103 { 104 global $script_name, $argv; 105 106 $args =& Console_Getargs::factory($console_configuration); 107 if (PEAR::isError($args)) { 108 109 $replacements = array( 110 '-p --parameters values(1-...)' => 'install plugin_name,URL ...', 111 'Usage: '.basename(__FILE__) =>"Usage: $script_name", 112 '[param1] ' => 'plugin_name PLUGIN_URL' 113 ); 114 echo "\n$description\n".str_repeat('-', strlen($description)+1)."\n"; 115 if ($args->getCode() === CONSOLE_GETARGS_ERROR_USER) { 116 echo str_replace(array_keys($replacements), array_values($replacements), 117 Console_Getargs::getHelp($console_configuration, null, $args->getMessage()))."\n"; 118 } else if ($args->getCode() === CONSOLE_GETARGS_HELP) { 119 echo str_replace(array_keys($replacements), array_values($replacements), 120 @Console_Getargs::getHelp($console_configuration))."\n"; 121 } 122 exit; 123 } 124 return $args->getValues(); 125 } 126 127 128 $PluginManager = new AkPluginManager(); 129 130 131 132 /** 133 * List available plugins. 134 */ 135 if($command == 'list') { 136 137 $options = get_console_options_for('List available plugins.', array( 138 'source' => array('short' => 's', 'desc' => "Use the specified plugin repositories. --source URL1 URL2", 'max'=> -1, 'min'=> 1), 139 'local' => array('short' => 'l', 'desc' => "List locally installed plugins.", 'max' => 0), 140 'remote' => array('short' => 'r', 'desc' => "List remotely available plugins. This is the default behavior", 'max' => 0) 141 )); 142 143 if(isset($options['local']) && isset($options['remote'])){ 144 die("Local and remote arguments can not be used simultaneously\n"); 145 } 146 if(!empty($options['source'])){ 147 $PluginManager->tmp_repositories = Ak::toArray($options['source']); 148 } 149 $installed_plugins = $PluginManager->getInstalledPlugins(); 150 if(isset($options['local'])){ 151 $plugins_dir = $ak_app_dir.DS.'vendor'.DS.'plugins'; 152 if(empty($installed_plugins)){ 153 die("There are not plugins intalled at $plugins_dir\n"); 154 }else{ 155 echo "Plugins installed at $plugins_dir:\n\n"; 156 foreach ($installed_plugins as $plugin){ 157 echo " * ".$plugin." (".rtrim($PluginManager->getRepositoryForPlugin($plugin),'/')."/$plugin)\n"; 158 } 159 die("\n"); 160 } 161 }else{ 162 $plugins = $PluginManager->getPlugins(true); 163 if(empty($plugins)){ 164 die("Could not find remote plugins\n"); 165 }else{ 166 $repsositories = array(); 167 foreach ($plugins as $plugin => $repository){ 168 if(empty($repsositories[$repository])){ 169 $repsositories[$repository] = array(); 170 } 171 if(in_array($plugin, $installed_plugins)){ 172 array_unshift($repsositories[$repository], '[INSTALLED] '.$plugin); 173 }else{ 174 $repsositories[$repository][] = $plugin; 175 } 176 } 177 foreach ($repsositories as $repsository=>$plugins){ 178 echo "Plugins available at $repository:\n"; 179 echo join(", ",$plugins)."\n\n"; 180 } 181 } 182 } 183 die(); 184 } 185 186 187 188 /** 189 * List configured plugin repositories. 190 */ 191 if($command == 'sources') { 192 $options = get_console_options_for('List configured plugin repositories.', array( 193 'check' => array('short' => 'c', 'desc' => "Report status of repository.", 'max' => 0) 194 )); 195 $repositories = $PluginManager->getAvailableRepositories(true); 196 197 foreach ($repositories as $repository){ 198 $checked = isset($options['check']) && !Ak::url_get_contents($repository, array('timeout'=>5)) ? ' [Connection timeout].' : ''; 199 echo " * $repository$checked\n"; 200 } 201 die(); 202 } 203 204 205 206 207 /** 208 * Adds a repository to the default search list. 209 */ 210 if($command == 'source') { 211 array_shift($argv); 212 $options = Ak::toArray($argv); 213 214 if(empty($options)){ 215 die("You need to provide at least one repository to add to the default search list.\n"); 216 } 217 218 foreach ($options as $repository){ 219 if(Ak::url_get_contents($repository, array('timeout'=>10))){ 220 $PluginManager->addRepository($repository); 221 echo "Added: $repository\n"; 222 }else{ 223 echo "Not added: Connection error for repository $repository.\n"; 224 } 225 } 226 die(); 227 } 228 229 230 231 232 /** 233 * Removes a repository to the default search list. 234 */ 235 if($command == 'unsource') { 236 array_shift($argv); 237 $options = Ak::toArray($argv); 238 239 if(empty($options)){ 240 die("You need to provide at least one repository to remove from the default search list.\n"); 241 } 242 243 foreach ($options as $repository){ 244 $PluginManager->removeRepository($repository); 245 echo "Removed: $repository\n"; 246 } 247 die(); 248 } 249 250 251 252 253 /** 254 * Discover repositories referenced on a page. 255 */ 256 if($command == 'discover') { 257 258 $options = get_console_options_for('Discover repositories referenced on a page.', array( 259 'source' => array('short' => 's', 'desc' => "Use the specified plugin repositories instead of the default.", 'max' => 1), 260 'list' => array('short' => 'l', 'desc' => "List but don't prompt or add discovered repositories.", 'max' => 0), 261 'no-prompt' => array('short' => 'n', 'desc' => "Add all new repositories without prompting.", 'max' => 0) 262 )); 263 264 if(!empty($options['source'])){ 265 $PluginManager->respository_discovery_page = $options['source']; 266 } 267 268 $repositories = $PluginManager->getDiscoveredRepositories(); 269 $default = 'Y'; 270 271 foreach ($repositories as $repository){ 272 echo "* $repository"; 273 if(!empty($options['list'])){ 274 echo "\n"; 275 }else{ 276 echo $default == 'Y' ? "[Y/n]:" : "[y/N]:"; 277 278 $key = trim(strtolower(fgetc(STDIN))); 279 280 if((empty($key) && $default == 'N') || $key == 'n'){ 281 echo "Skipped $repository.\n"; 282 $default = 'N'; 283 }elseif((empty($key) && $default == 'Y') || $key == 'y'){ 284 if(Ak::url_get_contents($repository, array('timeout'=>10))){ 285 $PluginManager->addRepository($repository); 286 echo "Added $repository.\n"; 287 }else{ 288 echo "Not added: Connection error for repository $repository.\n"; 289 } 290 $default = 'Y'; 291 } 292 293 if(!empty($key)){ 294 fgetc(STDIN); 295 } 296 } 297 298 } 299 die(); 300 } 301 302 303 304 305 /** 306 * Install plugins. 307 */ 308 if($command == 'install') { 309 310 $options = get_console_options_for('Install one or more plugins.', array( 311 CONSOLE_GETARGS_PARAMS => array('short' => 'p', 'desc' => "You can specify plugin names as given in 'plugin list' output or absolute URLs to a plugin repository.", 'max' => -1, 'min' => 1), 312 'externals' => array('short' => 'x', 'desc' => "Use svn:externals to grab the plugin. Enables plugin updates and plugin versioning.", 'max' => 0), 313 'checkout' => array('short' => 'o', 'desc' => "Use svn checkout to grab the plugin. Enables updating but does not add a svn:externals entry.", 'max' => 0), 314 'revision' => array('short' => 'r', 'desc' => "Checks out the given revision from subversion. Ignored if subversion is not used.", 'max' => 1, 'min' => 1), 315 'force' => array('short' => 'f', 'desc' => "Reinstalls a plugin if it's already installed.", 'max' => 0), 316 )); 317 318 if(empty($options['parameters'])){ 319 die("You must supply at least one plugin name or plugin URL to install.\n"); 320 } 321 322 $best = $PluginManager->guessBestInstallMethod($options); 323 if($best == 'http' && (!empty($options['externals']) || !empty($options['checkout']))){ 324 die("Cannot install using subversion because `svn' cannot be found in your PATH\n"); 325 }elseif ($best == 'export' && !empty($options['externals'])){ 326 die("Cannot install using externals because this project is not under subversion."); 327 }elseif ($best == 'export' && !empty($options['checkout'])){ 328 die("Cannot install using checkout because this project is not under subversion."); 329 } 330 331 $plugins = Ak::toArray($options['parameters']); 332 333 foreach ($plugins as $plugin){ 334 $repository = null; 335 $plugin_name = basename($plugin); 336 if($plugin_name != $plugin){ 337 $repository = preg_replace('/\/?'.$plugin_name.'$/', '', trim($plugin)); 338 } 339 if(!is_dir($plugin)){ 340 if (!@$PluginManager->getRepositoryForPlugin($plugin_name, $repository)){ 341 is_null($repository) ? $repository = AK_PLUGINS_MAIN_REPOSITORY : null; 342 echo "\nPlugin $plugin_name not found @ ".$repository.".\n"; 343 continue; 344 } 345 } 346 echo "\nInstalling $plugin\n"; 347 $PluginManager->installPlugin($plugin_name, $repository, $options); 348 } 349 350 echo "Done.\n"; 351 die(); 352 } 353 354 /** 355 * Update plugins. 356 */ 357 if($command == 'update') { 358 $options = get_console_options_for('Update installed plugins.', array( 359 'externals' => array('short' => 'x', 'desc' => "Use svn:externals to grab the plugin. Enables plugin updates and plugin versioning.", 'max' => 0), 360 'checkout' => array('short' => 'o', 'desc' => "Use svn checkout to grab the plugin. Enables updating but does not add a svn:externals entry.", 'max' => 0), 361 )); 362 363 $best = $PluginManager->guessBestInstallMethod($options); 364 if($best == 'http' && (!empty($options['externals']) || !empty($options['checkout']))){ 365 die("Cannot install using subversion because `svn' cannot be found in your PATH\n"); 366 }elseif ($best == 'export' && !empty($options['externals'])){ 367 die("Cannot install using externals because this project is not under subversion."); 368 }elseif ($best == 'export' && !empty($options['checkout'])){ 369 die("Cannot install using checkout because this project is not under subversion."); 370 } 371 $installed_plugins = $PluginManager->getInstalledPlugins(); 372 foreach ($installed_plugins as $plugin){ 373 $repository_for_plugin = $PluginManager->getRepositoryForPlugin($plugin); 374 echo "Updating $plugin from $repository_for_plugin.\n"; 375 $PluginManager->updatePlugin($plugin,$repository_for_plugin,$options); 376 } 377 echo "Done.\n"; 378 die(); 379 } 380 381 382 /** 383 * Remove plugins. 384 */ 385 if($command == 'remove') { 386 387 $options = get_console_options_for('Remove plugins.', array( 388 CONSOLE_GETARGS_PARAMS => array('short' => 'p', 'desc' => "You can specify plugin names as given in 'plugin list' output or absolute URLs to a plugin repository.", 'max' => -1, 'min' => 1))); 389 390 if(empty($options['parameters'])){ 391 echo "You must supply at least one plugin name or plugin URL to uninstall.\n"; 392 echo "\nInstalled Plugins: "; 393 echo join(', ',$PluginManager->getInstalledPlugins()).'.'; 394 die(); 395 } 396 397 $plugins = Ak::toArray($options['parameters']); 398 399 foreach ($plugins as $plugin){ 400 $plugin_name = basename($plugin); 401 echo "\nUninstalling $plugin\n"; 402 $PluginManager->uninstallPlugin($plugin_name); 403 } 404 405 echo "Done.\n"; 406 die(); 407 } 408 409 410 411 412 /** 413 * Shows plugin info at plugin_path/ABOUT. 414 */ 415 if($command == 'info') { 416 417 $options = get_console_options_for('Remove plugins.', array( 418 CONSOLE_GETARGS_PARAMS => array('short' => 'p', 'desc' => "Plugin names as given in 'plugin list' output or absolute URL to a plugin repository.", 'max' => 1, 'min' => 1))); 419 420 if(empty($options['parameters'])){ 421 die("You must supply a plugins name or plugin URL.\n"); 422 } 423 424 $plugin = $options['parameters']; 425 $plugin_name = basename($plugin); 426 if($plugin_name != $plugin){ 427 $repository = preg_replace('/\/?'.$plugin_name.'$/', '', trim($plugin)); 428 }else { 429 $repository = $PluginManager->getRepositoryForPlugin($plugin_name); 430 } 431 432 $about = Ak::url_get_contents(rtrim($repository,'/').'/'.$plugin_name.'/ABOUT', array('timeout'=>10)); 433 echo empty($about) ? "Could not get plugin information." : $about; 434 435 die("\n"); 436 } 437 438 if($command == 'test') { 439 $options = get_console_options_for('Test plugin', array(CONSOLE_GETARGS_PARAMS=>array('min'=>1,'max'=>1,'short' => 'p', 'desc' => "Specify the plugin name you wish to test"),'phpbin'=>array('short'=>'b','max'=>1,'min'=>1,'desc'=>'Path to the php binary','default'=>'/usr/bin/env php'))); 440 441 if(empty($options['parameters'])){ 442 die("You must supply a plugin name.\n"); 443 } 444 $plugin = $options['parameters']; 445 $plugin_name = basename($plugin); 446 447 $test_file = AK_PLUGINS_DIR.DS.$plugin_name.DS.'test'.DS.$plugin_name.'.php'; 448 if (file_exists($test_file)) { 449 $exec_command = $options['phpbin'].' '.$test_file; 450 passthru($exec_command); 451 } else { 452 echo "The test file $test_file does not exist."; 453 die("\n"); 454 } 455 456 } 457 458 459 if($command == 'help') { 460 $options = get_console_options_for('Plugin help', array(CONSOLE_GETARGS_PARAMS=>array('min'=>1,'max'=>1,'short' => 'p', 'desc' => "Specify a plugin name."),'phpbin'=>array('short'=>'b','max'=>1,'min'=>1,'desc'=>'Path to the php binary','default'=>'/usr/bin/env php'))); 461 462 if(empty($options['parameters'])){ 463 die("You must supply a plugin name.\n"); 464 } 465 $plugin = $options['parameters']; 466 $plugin_name = basename($plugin); 467 468 $help_file = AK_PLUGINS_DIR.DS.$plugin_name.DS.'README'; 469 470 if (file_exists($help_file)) { 471 echo file_get_contents($help_file)."\n"; 472 } else { 473 echo "Could not find a README help file for the $plugin_name plugin."; 474 die("\n"); 475 } 476 477 } 478 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Oct 27 12:43:49 2008 | Cross-referenced by PHPXref 0.6 |