PageRenderTime 60ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/bin/hudson-cli.php

https://bitbucket.org/abtris/php4hudson
PHP | 106 lines | 71 code | 1 blank | 34 comment | 16 complexity | 4eac26acf4cc51af16a18e216b184044 MD5 | raw file
  1. #!/usr/bin/env php
  2. <?php
  3. /**
  4. * Php4Hudson
  5. *
  6. * @version $Id$
  7. * @author Ladislav Prskavec <ladislav.prskavec@gmail.com>
  8. * @package php4hudson
  9. * @category php4hudson
  10. * @copyright Copyright (c) 2009, Ladislav Prskavec (http://ladislav.prskavec.net)
  11. * @license MIT http://www.opensource.org/licenses/mit-license.php
  12. * @link http://code.google.com/p/php4hudson/
  13. * @filesource
  14. */
  15. error_reporting(E_ALL|E_STRICT);
  16. ini_set('display_errors',true);
  17. date_default_timezone_set('Europe/Prague');
  18. /**
  19. * Zend GetOpt
  20. */
  21. require_once('Zend/Console/Getopt.php');
  22. require_once('Zend/Console/Getopt/Exception.php');
  23. /**
  24. * Command line client for php4hudson
  25. */
  26. require_once ("../Php4Hudson/phphudson.php");
  27. require_once ("../Php4Hudson/phphudsonui.php");
  28. /**
  29. * Try processing Zend_Console_Getopt
  30. */
  31. try {
  32. $opts = new Zend_Console_Getopt(
  33. array(
  34. 'help' => 'Displays usage information.',
  35. 'version|v' => 'Version',
  36. 'username|u=s'=> 'Username',
  37. 'password|p=s'=> 'password',
  38. 'host|h=s' => 'Hudson URL',
  39. 'restart|r' => 'restart Hudson',
  40. 'output|o=s'=> 'output path',
  41. 'configs|c' => 'get Hudson Configs',
  42. 'jobs|j' => 'print jobs list',
  43. 'debug|d' => 'debug'
  44. )
  45. );
  46. $opts->parse();
  47. } catch (Zend_Console_Getopt_Exception $e) {
  48. exit($e->getMessage() ."\n\n". $e->getUsageMessage());
  49. }
  50. // start processing ops
  51. // help + without arguments
  52. if (count($opts->toArray())==0 || isset($opts->help)) {
  53. php4hudsonUI::printVersion();
  54. echo $opts->getUsageMessage();
  55. exit;
  56. }
  57. // version
  58. if (isset($opts->v)) {
  59. php4hudsonUI::printVersion();
  60. echo $opts->getUsageMessage();
  61. }
  62. // username
  63. if (isset($opts->u)) {
  64. $username = $opts->u;
  65. } else {
  66. $username = null;
  67. }
  68. // passwod
  69. if (isset($opts->p)) {
  70. $password = $opts->p;
  71. } else {
  72. $password = null;
  73. }
  74. // host
  75. if (isset($opts->h)) {
  76. $host = $opts->h;
  77. } else {
  78. print "Error url to Hudson must be set!\n";
  79. exit;
  80. }
  81. // debug
  82. if (isset($opts->d)) {
  83. $debug = true;
  84. } else {
  85. $debug = false;
  86. }
  87. // output
  88. if (isset($opts->o)) {
  89. $output = $opts->o;
  90. } else {
  91. $output = null;
  92. }
  93. // jobs
  94. if (isset($opts->j)) {
  95. php4hudsonUI::printListJobs($host, $username, $password, $debug);
  96. }
  97. // config
  98. if (isset($opts->c)) {
  99. php4hudsonUI::getConfigs($host, $username, $password, $debug, $output);
  100. }
  101. // restart
  102. if (isset ($opts->r)) {
  103. php4hudsonUI::system($host, $username, $password, $debug, "restart");
  104. }
  105. // end processing ops