示例#1
0
 /**
  * constructor
  */
 function __construct()
 {
     //	$include_path = "packages/" . get_include_path( );
     //	set_include_path( $include_path );
     require_once 'Console/Getopt.php';
     $shortOptions = "s:u:p:k:";
     $longOptions = array('site=', 'user', 'pass');
     $getopt = new Console_Getopt();
     $args = $getopt->readPHPArgv();
     array_shift($args);
     list($valid, $this->args) = $getopt->getopt2($args, $shortOptions, $longOptions);
     $vars = array('user' => 'u', 'pass' => 'p', 'key' => 'k', 'site' => 's');
     foreach ($vars as $var => $short) {
         ${$var} = NULL;
         foreach ($valid as $v) {
             if ($v[0] == $short || $v[0] == "--{$var}") {
                 ${$var} = $v[1];
                 break;
             }
         }
         if (!${$var}) {
             die("\nUsage: \$ php5 " . $_SERVER['PHP_SELF'] . " -k key -u user -p password -s yoursite.org\n");
         }
     }
     $this->site = $site;
     $this->key = $key;
     $this->setEnv();
     $this->authenticate($user, $pass);
 }
function run()
{
    session_start();
    require_once '../civicrm.config.php';
    require_once 'CRM/Core/Config.php';
    $config = CRM_Core_Config::singleton();
    require_once 'Console/Getopt.php';
    $shortOptions = "n:p:k:pre";
    $longOptions = array('name=', 'pass='******'key=', 'prefix=');
    $getopt = new Console_Getopt();
    $args = $getopt->readPHPArgv();
    array_shift($args);
    list($valid, $dontCare) = $getopt->getopt2($args, $shortOptions, $longOptions);
    $vars = array('name' => 'n', 'pass' => 'p', 'key' => 'k', 'prefix' => 'pre');
    foreach ($vars as $var => $short) {
        ${$var} = NULL;
        foreach ($valid as $v) {
            if ($v[0] == $short || $v[0] == "--{$var}") {
                ${$var} = $v[1];
                break;
            }
        }
        if (!${$var}) {
            ${$var} = CRM_Utils_Array::value($var, $_REQUEST);
        }
        $_REQUEST[$var] = ${$var};
    }
    // this does not return on failure
    // require_once 'CRM/Utils/System.php';
    CRM_Utils_System::authenticateScript(TRUE, $name, $pass);
    //log the execution of script
    CRM_Core_Error::debug_log_message('NormalizePhone.php');
    // process all phones
    processPhones($config, $prefix);
}
示例#3
0
 /**
  * constructor
  */
 function __construct($authenticate = true)
 {
     //	$include_path = "packages/" . get_include_path( );
     //	set_include_path( $include_path );
     if (!$authenticate) {
         $this->setEnv();
         return;
     }
     require_once 'Console/Getopt.php';
     $shortOptions = "s:u:p:";
     $longOptions = array('site=', 'user', 'pass');
     $getopt = new Console_Getopt();
     $args = $getopt->readPHPArgv();
     array_shift($args);
     list($valid, $this->args) = $getopt->getopt2($args, $shortOptions, $longOptions);
     $vars = array('user' => 'u', 'pass' => 'p', 'site' => 's');
     foreach ($vars as $var => $short) {
         ${$var} = null;
         foreach ($valid as $v) {
             if ($v[0] == $short || $v[0] == "--{$var}") {
                 ${$var} = $v[1];
                 break;
             }
         }
         if (!${$var}) {
             $a = explode('/', $_SERVER["SCRIPT_NAME"]);
             $file = $a[count($a) - 1];
             die("\nUsage: \$cd /your/civicrm/root; \$php5 bin/" . $file . " -u user -p password -s yoursite.org (or default)\n");
         }
     }
     $this->site = $site;
     $this->setEnv();
     $this->authenticate($user, $pass);
 }
 /**
  * returns the commandline arguments of a function
  *
  * @param    string  $argv           the commandline
  * @param    string  $short_options  the allowed option short-tags
  * @param    string  $long_options   the allowed option long-tags
  * @return   array   the given options and there values
  * @static
  * @access private
  */
 function _parseArgs($argv, $short_options, $long_options = null)
 {
     if (!is_array($argv) && $argv !== null) {
         $argv = preg_split('/\\s+/', $argv, -1, PREG_SPLIT_NO_EMPTY);
     }
     return Console_Getopt::getopt2($argv, $short_options);
 }
示例#5
0
 function raiseError($error)
 {
     $this->graph = new Image_GraphViz(true, array('fontname' => 'Verdana', 'fontsize' => 12.0, 'rankdir' => 'LR'));
     if (PEAR::isError($error)) {
         $error = $error->getMessage();
     }
     trigger_error($error, E_USER_WARNING);
     return Console_Getopt::getopt2($argv, $short_options);
 }
示例#6
0
 function get($path)
 {
     ini_set('memory_limit', '256M');
     // we need alot of memory
     set_time_limit(0);
     $argv = $_SERVER['argv'];
     array_shift($argv);
     array_shift($argv);
     $opts = explode(',', 'table==,where==,dump-dir==,debug=');
     require_once 'Console/Getopt.php';
     $go = Console_Getopt::getopt2($argv, '', $opts);
     if (is_object($go)) {
         die($go->toString());
     }
     foreach ($go[0] as $ar) {
         $args[substr($ar[0], 2)] = $ar[1];
     }
     $errs = array();
     foreach ($opts as $req) {
         if (substr($req, -2, 2) != '==') {
             // skip optional arguments
             continue;
         }
         if (empty($args[substr($req, 0, -2)])) {
             $errs[] = "--" . substr($req, 0, -2) . ' is required';
         }
     }
     if (!empty($errs)) {
         die(print_R($errs, true));
     }
     if (!empty($args['debug'])) {
         DB_DataObject::debugLevel($args['debug']);
     }
     $this->args = $args;
     $this->out = array();
     $this->discoverChildren($this->args['table'], $this->args['where'], true);
     //print_R($this->deletes);
     //print_r($this->dumps);
     //exit;
     $this->discover($this->args['table'], $this->args['where'], true);
     if (!file_exists($args['dump-dir'])) {
         mkdir($args['dump-dir'], 0777, true);
     }
     // create uid's
     // dump items..
     echo "GENERATED FILES:\n";
     // summary
     echo "    " . implode("\n    ", $this->out) . "\n";
     exit;
 }
示例#7
0
文件: System.php 项目: roojs/pear
 /**
  * returns the commandline arguments of a function
  *
  * @param    string  $argv           the commandline
  * @param    string  $short_options  the allowed option short-tags
  * @param    string  $long_options   the allowed option long-tags
  * @return   array   the given options and there values
  * @static
  * @access private
  */
 static function _parseArgs($argv, $short_options, $long_options = null)
 {
     if (!is_array($argv) && $argv !== null) {
         // Find all items, quoted or otherwise
         preg_match_all("/(?:[\"'])(.*?)(?:['\"])|([^\\s]+)/", $argv, $av);
         $argv = $av[1];
         foreach ($av[2] as $k => $a) {
             if (empty($a)) {
                 continue;
             }
             $argv[$k] = trim($a);
         }
     }
     return Console_Getopt::getopt2($argv, $short_options, $long_options);
 }
示例#8
0
function &get_commandline()
{
    $cg = new Console_Getopt();
    $args = $cg->readPHPArgv();
    array_shift($args);
    $shortOpts = 'h::v::';
    $longOpts = array('ini=', 'force==');
    $params = $cg->getopt2($args, $shortOpts, $longOpts);
    $new_params = array();
    foreach ($params[0] as $param) {
        $param[0] = str_replace('--', '', $param[0]);
        $new_params[$param[0]] = $param[1];
    }
    unset($params);
    return $new_params;
}
function &get_commandline()
{
    $cg = new Console_Getopt();
    $args = $cg->readPHPArgv();
    array_shift($args);
    $shortOpts = 'h::v::';
    $longOpts = array('ini=', 'help==', 'pid=', 'daemon==');
    $params = $cg->getopt2($args, $shortOpts, $longOpts);
    if (PEAR::isError($params)) {
        echo 'Error: ' . $params->getMessage() . "\n";
        exit(1);
    }
    $new_params = array();
    foreach ($params[0] as $param) {
        $param[0] = str_replace('--', '', $param[0]);
        $new_params[$param[0]] = $param[1];
    }
    unset($params);
    return $new_params;
}
示例#10
0
function run()
{
    session_start();
    require_once '../civicrm.config.php';
    require_once 'CRM/Core/Config.php';
    $config =& CRM_Core_Config::singleton();
    require_once 'Console/Getopt.php';
    $shortOptions = "n:p:s:e:k:";
    $longOptions = array('name=', 'pass='******'key=', 'start=', 'end=');
    $getopt = new Console_Getopt();
    $args = $getopt->readPHPArgv();
    array_shift($args);
    list($valid, $dontCare) = $getopt->getopt2($args, $shortOptions, $longOptions);
    $vars = array('start' => 's', 'end' => 'e', 'name' => 'n', 'pass' => 'p', 'key' => 'k');
    foreach ($vars as $var => $short) {
        ${$var} = null;
        foreach ($valid as $v) {
            if ($v[0] == $short || $v[0] == "--{$var}") {
                ${$var} = $v[1];
                break;
            }
        }
        if (!${$var}) {
            ${$var} = CRM_Utils_Array::value($var, $_REQUEST);
        }
        $_REQUEST[$var] = ${$var};
    }
    // this does not return on failure
    // require_once 'CRM/Utils/System.php';
    CRM_Utils_System::authenticateScript(true, $name, $pass);
    // check that we have a geocodeMethod
    if (empty($config->geocodeMethod)) {
        echo ts('Error: You need to set a mapping provider under Global Settings');
        exit;
    }
    $config->userFramework = 'Soap';
    $config->userFrameworkClass = 'CRM_Utils_System_Soap';
    $config->userHookClass = 'CRM_Utils_Hook_Soap';
    // we have an exclusive lock - run the mail queue
    processContacts($config, $start, $end);
}
示例#11
0
function &get_commandline($more_longopts = array())
{
    $cg = new Console_Getopt();
    $args = $cg->readPHPArgv();
    array_shift($args);
    $shortOpts = 'h::v::';
    $longOpts = array('user='******'ini=', 'password='******'host=', 'db=', 'port=', 'help==', 'verbose==', 'method=', 'gearman=', 'inlist=', 'between=', 'directory=', 'push_where', 'inlist_merge_threshold==', 'inlist_merge_size==', 'coord_engine==', 'schema=', 'batch');
    $longOpts = array_merge($longOpts, $more_longopts);
    @($params = $cg->getopt2($args, $shortOpts, $longOpts));
    if (@PEAR::isError($params)) {
        echo 'Error: ' . $params->getMessage() . "\n";
        exit(1);
    }
    $new_params = array();
    foreach ($params[0] as $param) {
        $param[0] = str_replace('--', '', $param[0]);
        $new_params[$param[0]] = $param[1];
    }
    unset($params);
    return $new_params;
}
示例#12
0
/** include_pathの設定(このtest runnerがあるディレクトリを追加) */
ini_set('include_path', dirname(BASE) . PATH_SEPARATOR . ini_get('include_path'));
/** Ethna関連クラスのインクルード */
require_once 'Ethna/Ethna.php';
/** SimpleTestのインクルード */
require_once 'simpletest/unit_tester.php';
require_once 'simpletest/reporter.php';
require_once 'Ethna/test/TextDetailReporter.php';
require_once 'Ethna/test/Ethna_UnitTestBase.php';
/** テストケースがあるディレクトリ */
$test_dir = ETHNA_BASE . '/test';
$test =& new GroupTest('Ethna All tests');
// テストケースのファイルリストを取得
require_once 'Console/Getopt.php';
$args = Console_Getopt::readPHPArgv();
list($args, $opts) = Console_Getopt::getopt2($args, '', array());
array_shift($opts);
if (count($opts) > 0) {
    $file_list = $opts;
} else {
    $file_list = getFileList($test_dir);
}
// テストケースを登録
foreach ($file_list as $file) {
    $test->addTestFile($file);
}
// 結果をコマンドラインに出力
//$test->run(new TextReporter());
$test->run(new TextDetailReporter());
//{{{ getFileList
/**
 /**
  * easy getopt :)
  *
  * @param   array   $lopts  long options
  * @return  array   list($opts, $args)
  * @access  protected
  */
 function &_getopt($lopts = array())
 {
     // create opts
     // ex: $lopts = array('foo', 'bar=');
     $lopts = to_array($lopts);
     $sopts = '';
     $opt_def = array();
     foreach ($lopts as $lopt) {
         if ($lopt[strlen($lopt) - 2] === '=') {
             $opt_def[$lopt[0]] = substr($lopt, 0, strlen($lopt) - 2);
             $sopts .= $lopt[0] . '::';
         } else {
             if ($lopt[strlen($lopt) - 1] === '=') {
                 $opt_def[$lopt[0]] = substr($lopt, 0, strlen($lopt) - 1);
                 $sopts .= $lopt[0] . ':';
             } else {
                 $opt_def[$lopt[0]] = $lopt;
                 $sopts .= $lopt[0];
             }
         }
     }
     // do getopt
     // ex: $sopts = 'fb:';
     $opts_args = Console_Getopt::getopt2($this->arg_list, $sopts, $lopts);
     if (Ethna::isError($opts_args)) {
         return $opts_args;
     }
     // parse opts
     // ex: "-ff --bar=baz" gets
     //      $opts = array('foo' => array(true, true),
     //                    'bar' => array('baz'));
     $opts = array();
     foreach ($opts_args[0] as $opt) {
         $opt[0] = $opt[0][0] === '-' ? $opt_def[$opt[0][2]] : $opt_def[$opt[0][0]];
         $opt[1] = $opt[1] === null ? true : $opt[1];
         if (isset($opts[$opt[0]]) === false) {
             $opts[$opt[0]] = array($opt[1]);
         } else {
             $opts[$opt[0]][] = $opt[1];
         }
     }
     $opts_args[0] = $opts;
     return $opts_args;
 }
示例#14
0
define('P2_FETCH_SUBJECT_TXT_DEBUG_OUTPUT_FILE', '/tmp/p2_fetch_subject_txt.log');
require dirname(__FILE__) . '/../conf/conf.inc.php';
require_once 'Console/Getopt.php';
P2HttpExt::activate();
// }}}
// {{{ コマンドライン引数を取得
$getopt = new Console_Getopt();
$args = $getopt->readPHPArgv();
if (PEAR::isError($args)) {
    fwrite(STDERR, $args->getMessage() . PHP_EOL);
    exit(1);
}
array_shift($args);
$short_options = 'm:s:';
$long_options = array('mode=', 'set=');
$options = $getopt->getopt2($args, $short_options, $long_options);
if (PEAR::isError($options)) {
    fwrite(STDERR, $options->getMessage() . PHP_EOL);
    exit(1);
}
$mode = null;
$set = null;
foreach ($options[0] as $option) {
    switch ($option[0]) {
        case 'm':
        case '--mode':
            $mode = p2_fst_checkopt_mode($option[1]);
            break;
        case 's':
        case '--set':
            $set = p2_fst_checkopt_set($option[1]);
示例#15
0
function run()
{
    session_start();
    require_once '../civicrm.config.php';
    require_once 'CRM/Core/Config.php';
    $config =& CRM_Core_Config::singleton();
    require_once 'Console/Getopt.php';
    $shortOptions = "n:p:s:e:k:g:parse";
    $longOptions = array('name=', 'pass='******'key=', 'start=', 'end=', 'geocoding=', 'parse=');
    $getopt = new Console_Getopt();
    $args = $getopt->readPHPArgv();
    array_shift($args);
    list($valid, $dontCare) = $getopt->getopt2($args, $shortOptions, $longOptions);
    $vars = array('start' => 's', 'end' => 'e', 'name' => 'n', 'pass' => 'p', 'key' => 'k', 'geocoding' => 'g', 'parse' => 'ap');
    foreach ($vars as $var => $short) {
        ${$var} = null;
        foreach ($valid as $v) {
            if ($v[0] == $short || $v[0] == "--{$var}") {
                ${$var} = $v[1];
                break;
            }
        }
        if (!${$var}) {
            ${$var} = CRM_Utils_Array::value($var, $_REQUEST);
        }
        $_REQUEST[$var] = ${$var};
    }
    // this does not return on failure
    // require_once 'CRM/Utils/System.php';
    CRM_Utils_System::authenticateScript(true, $name, $pass);
    // do check for geocoding.
    $processGeocode = false;
    if (empty($config->geocodeMethod)) {
        if ($geocoding == 'true') {
            echo ts('Error: You need to set a mapping provider under Global Settings');
            exit;
        }
    } else {
        $processGeocode = true;
        // user might want to over-ride.
        if ($geocoding == 'false') {
            $processGeocode = false;
        }
    }
    // do check for parse street address.
    require_once 'CRM/Core/BAO/Preferences.php';
    $parseAddress = CRM_Utils_Array::value('street_address_parsing', CRM_Core_BAO_Preferences::valueOptions('address_options'), false);
    $parseStreetAddress = false;
    if (!$parseAddress) {
        if ($parse == 'true') {
            echo ts('Error: You need to enable Street Address Parsing under Global Settings >> Address Settings.');
            exit;
        }
    } else {
        $parseStreetAddress = true;
        // user might want to over-ride.
        if ($parse == 'false') {
            $parseStreetAddress = false;
        }
    }
    // don't process.
    if (!$parseStreetAddress && !$processGeocode) {
        echo ts('Error: Both Geocode mapping as well as Street Address Parsing are disabled. You must configure one or both options to use this script.');
        exit;
    }
    $config->userFramework = 'Soap';
    $config->userFrameworkClass = 'CRM_Utils_System_Soap';
    $config->userHookClass = 'CRM_Utils_Hook_Soap';
    // we have an exclusive lock - run the mail queue
    processContacts($config, $processGeocode, $parseStreetAddress, $start, $end);
}
示例#16
0
     usage(null, @$options[1][1]);
 }
 if (!$config->validConfiguration()) {
     PEAR::raiseError('CRITICAL ERROR: no existing valid configuration files found in files ' . "'{$pear_user_config}' or '{$pear_system_config}', please copy an existing configuration" . 'file to one of these locations, or use the -c and -s options to create one');
 }
 PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
 $cmd = PEAR_Command::factory($command, $config);
 PEAR::popErrorHandling();
 if (PEAR::isError($cmd)) {
     usage(null, @$options[1][0]);
 }
 $short_args = $long_args = null;
 PEAR_Command::getGetoptArgs($command, $short_args, $long_args);
 array_shift($options[1]);
 $skip_unknown = $progname === 'pecl' ? true : false;
 $tmp = Console_Getopt::getopt2($options[1], $short_args, $long_args, $skip_unknown);
 if (PEAR::isError($tmp)) {
     break;
 }
 $opts = array();
 // Gather any extra params which may be passed on to compile
 if ($skip_unknown === true) {
     $o = $options[1];
     foreach (str_split($short_args) as $sa) {
         $pos = array_search('-' . $sa, $o);
         if ($pos !== false) {
             unset($o[$pos]);
         }
     }
     foreach ($long_args as $la) {
         $pos = array_search('--' . $la, $o);
示例#17
0
 /**
  * Parses command line into command line arguments array.
  *          
  * @return array
  */
 protected static function handleArguments()
 {
     $arguments = array();
     $shortopts = 'v::h::';
     $longopts = array('certreq', 'delete', 'export', 'genkey', 'help', 'import', 'keyclone', 'list', 'alias==', 'file==', 'keypass==', 'Crypt_KeyStore==', 'storepass==', 'dest==', 'new==');
     try {
         $con = new Console_Getopt();
         $args = $con->readPHPArgv();
         array_shift($args);
         $options = $con->getopt2($args, $shortopts, $longopts);
         if (!is_array($options)) {
             echo "Failed to parse command line arguments:\n";
             echo $options;
             exit(1);
         }
         if (count($options[0]) == 0 || self::hasOption('--help', $options) || self::hasOption('h', $options)) {
             self::showHelp();
             exit(1);
         }
     } catch (RuntimeException $e) {
         echo "Failed to parse command line arguments:\n";
         echo $e->getMessage() . "\n";
         exit(1);
     }
     foreach (self::$_cmds as $cmd => $cmdFunc) {
         if (self::hasOption("--" . $cmd, $options)) {
             $arguments['command'] = $cmd;
             break;
         }
     }
     foreach (self::$_cmdopts as $cmdopt) {
         if (self::hasOption("--" . $cmdopt, $options)) {
             $arguments[$cmdopt] = self::getOptionValue("--" . $cmdopt, $options);
         }
     }
     return $arguments;
 }
示例#18
0
 /**
  * Populate default testing focus based on parameters.
  *
  * This implementation reads parameters from the command-line.
  *
  * @return void This method does not return a value.
  *
  * @todo Consider renaming this method to better express its intent.
  * @todo Deprecate the $_GET compatibility, moving $_GET parameter handling
  * to a subclass.
  */
 function findDefaults()
 {
     $con = new Console_Getopt();
     $args = $con->readPHPArgv();
     array_shift($args);
     $options = $con->getopt2($args, array(), array('format=', 'type=', 'level=', 'layer=', 'folder=', 'file=', 'dir=', 'host='));
     if (PEAR::isError($options)) {
         PEAR::raiseError($args);
         die(254);
     }
     foreach ($options[0] as $option) {
         $name_with_dashes = $option[0];
         $name = str_replace('--', '', $name_with_dashes);
         $value = $option[1];
         switch ($name) {
             case 'format':
                 $this->output_format_name = $value;
                 break;
             case 'type':
                 $this->test_type_name = $value;
                 $GLOBALS['_MAX']['TEST']['test_type'] = $value;
                 break;
             case 'level':
                 $this->test_level_name = $value;
                 break;
             case 'folder':
                 $this->test_folder_name = $value;
                 break;
             case 'file':
                 $this->test_file_name = $value;
                 break;
             case 'host':
                 $this->host = $value;
                 break;
         }
         // For compatibility with legacy Web runner, pretend that commandline arguments came in through GET
         if (!isset($_GET[$name])) {
             $_GET[$name] = $value;
         }
     }
 }
 /**
  * Parses the command line options.
  *
  * @return array
  */
 protected function parseOptions()
 {
     Stagehand_LegacyError_PEARError::enableConversion();
     $oldErrorReportingLevel = error_reporting(error_reporting() & ~E_STRICT & ~E_NOTICE);
     Stagehand_LegacyError_PHPError::enableConversion(error_reporting());
     try {
         $argv = Console_Getopt::readPHPArgv();
         array_shift($argv);
         $parsedOptions = Console_Getopt::getopt2($argv, $this->shortOptions, $this->longOptions);
     } catch (Stagehand_LegacyError_PEARError_Exception $e) {
         Stagehand_LegacyError_PHPError::disableConversion();
         error_reporting($oldErrorReportingLevel);
         Stagehand_LegacyError_PEARError::disableConversion();
         throw new $this->exceptionClass(preg_replace('/^Console_Getopt: /', '', $e->getMessage()));
     } catch (Exception $e) {
         Stagehand_LegacyError_PHPError::disableConversion();
         error_reporting($oldErrorReportingLevel);
         Stagehand_LegacyError_PEARError::disableConversion();
         throw $e;
     }
     Stagehand_LegacyError_PHPError::disableConversion();
     error_reporting($oldErrorReportingLevel);
     Stagehand_LegacyError_PEARError::disableConversion();
     return $parsedOptions;
 }
示例#20
0
function main()
{
    global $just_show;
    $shortopts = "hn";
    $cg = new Console_Getopt();
    $dirs = $cg->readPHPArgv();
    array_shift($dirs);
    /* Trash $0, the name of the script */
    $ret = $cg->getopt2($dirs, $shortopts, $longopts);
    if (PEAR::isError($ret)) {
        echo $ret->getMessage(), "\n\n";
        usage();
    }
    list($opts, $dirs) = $ret;
    foreach ($opts as $opt) {
        list($o, $val) = $opt;
        switch ($o) {
            case 'h':
                usage(true);
                break;
            case 'n':
                $just_show = true;
                break;
            default:
                echo "Unknown option: {$o}\n\n";
                usage(true);
        }
    }
    if (count($dirs) == 0) {
        usage();
    }
    foreach ($dirs as $dir) {
        run_files($dir);
    }
}
示例#21
0
        }
        foreach ($this->errors() as $failure) {
            echo $failure->toString();
        }
    }
}
function microtime_float()
{
    list($usec, $sec) = explode(" ", microtime());
    return (double) $usec + (double) $sec;
}
$longopts = array('no-math', 'buggy-gmp', 'no-curl', 'math-lib=', 'insecure-rand', 'thorough', 'extra-tests=');
$con = new Console_Getopt();
$args = $con->readPHPArgv();
array_shift($args);
$options = $con->getopt2($args, "", $longopts);
if (PEAR::isError($options)) {
    print $options->message . "\n";
    exit(1);
}
list($flags, $tests_to_run) = $options;
$math_type = array();
$extra_test_modules = array();
$thorough = false;
foreach ($flags as $flag) {
    list($option, $value) = $flag;
    switch ($option) {
        case '--insecure-rand':
            define('Auth_OpenID_RAND_SOURCE', null);
            break;
        case '--no-math':
示例#22
0
    Gtk::main();
} else {
    do {
        if ($command == 'help') {
            usage(null, @$options[1][1]);
        }
        PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
        $cmd = PEAR_Command::factory($command, $config);
        PEAR::popErrorHandling();
        if (PEAR::isError($cmd)) {
            usage(null, @$options[1][1]);
        }
        $short_args = $long_args = null;
        PEAR_Command::getGetoptArgs($command, $short_args, $long_args);
        array_shift($options[1]);
        if (PEAR::isError($tmp = Console_Getopt::getopt2($options[1], $short_args, $long_args))) {
            break;
        }
        list($tmpopt, $params) = $tmp;
        $opts = array();
        foreach ($tmpopt as $foo => $tmp2) {
            list($opt, $value) = $tmp2;
            if ($value === null) {
                $value = true;
                // options without args
            }
            if (strlen($opt) == 1) {
                $cmdoptions = $cmd->getOptions($command);
                foreach ($cmdoptions as $o => $d) {
                    if (@$d['shortopt'] == $opt) {
                        $opts[$o] = $value;
示例#23
0
文件: PearRunner.php 项目: pago/pantr
 public function run($argv)
 {
     //        $old = error_reporting(0);
     if (!defined('PEAR_RUNTYPE')) {
         define('PEAR_RUNTYPE', 'pear');
     }
     if (!defined('PEAR_IGNORE_BACKTRACE')) {
         define('PEAR_IGNORE_BACKTRACE', 1);
     }
     @ini_set('allow_url_fopen', true);
     if (!ini_get('safe_mode')) {
         @set_time_limit(0);
     }
     ob_implicit_flush(true);
     @ini_set('track_errors', true);
     @ini_set('html_errors', false);
     @ini_set('magic_quotes_runtime', false);
     $pear_package_version = "1.9.0";
     PEAR_Command::setFrontendType('CLI');
     $this->_allCommands = PEAR_Command::getCommands();
     $progname = PEAR_RUNTYPE;
     array_shift($argv);
     $options = Console_Getopt::getopt2($argv, "c:C:d:D:Gh?sSqu:vV");
     if (PEAR::isError($options)) {
         $this->usage($options);
     }
     $opts = $options[0];
     $store_user_config = false;
     $verbose = 1;
     $config = PEAR_Config::singleton($this->_pearConfigFile, "#no#system#config#");
     if ($config instanceof PEAR_Error) {
         echo $config, "\n";
         exit(1);
     }
     $config->set('verbose', 1);
     //        $config->set('verbose', -1); // supress all kind of annoying stuff.
     $ui = PEAR_Command::getFrontendObject();
     $ui->setConfig($config);
     PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, "throwException"));
     if (ini_get('safe_mode')) {
         $ui->outputData('WARNING: running in safe mode requires that all files created ' . 'be the same uid as the current script. PHP reports this script is uid: ' . @getmyuid() . ', and current user is: ' . @get_current_user());
     }
     $verbose = $config->get("verbose");
     $cmdopts = array();
     foreach ($opts as $opt) {
         $param = !empty($opt[1]) ? $opt[1] : true;
         switch ($opt[0]) {
             case 'd':
                 if ($param === true) {
                     die('Invalid usage of "-d" option, expected -d config_value=value, ' . 'received "-d"' . "\n");
                 }
                 $possible = explode('=', $param);
                 if (count($possible) != 2) {
                     die('Invalid usage of "-d" option, expected -d config_value=value, received "' . $param . '"' . "\n");
                 }
                 list($key, $value) = explode('=', $param);
                 $config->set($key, $value, 'user');
                 break;
             case 'D':
                 if ($param === true) {
                     die('Invalid usage of "-d" option, expected -d config_value=value, ' . 'received "-d"' . "\n");
                 }
                 $possible = explode('=', $param);
                 if (count($possible) != 2) {
                     die('Invalid usage of "-d" option, expected -d config_value=value, received "' . $param . '"' . "\n");
                 }
                 list($key, $value) = explode('=', $param);
                 $config->set($key, $value, 'system');
                 break;
             case 's':
                 $store_user_config = true;
                 break;
             case 'u':
                 $config->remove($param, 'user');
                 break;
             case 'v':
                 $config->set('verbose', $config->get('verbose') + 1);
                 break;
             case 'q':
                 $config->set('verbose', $config->get('verbose') - 1);
                 break;
             case 'V':
                 $this->usage(null, 'version');
             case 'c':
             case 'C':
                 break;
             default:
                 // all non pear params goes to the command
                 $cmdopts[$opt[0]] = $param;
                 break;
         }
     }
     if ($store_user_config) {
         $config->store('user');
     }
     $command = isset($options[1][0]) ? $options[1][0] : null;
     if (empty($command) && $store_user_config) {
         exit;
     }
     if ($command == 'help') {
         $this->usage(null, @$options[1][1]);
     }
     if (!$config->validConfiguration()) {
         PEAR::raiseError('CRITICAL ERROR: no existing valid configuration files found in files found');
     }
     PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
     $cmd = PEAR_Command::factory($command, $config);
     PEAR::popErrorHandling();
     if (PEAR::isError($cmd)) {
         $this->usage(null, @$options[1][0]);
     }
     $short_args = $long_args = null;
     PEAR_Command::getGetoptArgs($command, $short_args, $long_args);
     array_shift($options[1]);
     $tmp = Console_Getopt::getopt2($options[1], $short_args, $long_args);
     if (PEAR::isError($tmp)) {
         break;
     }
     list($tmpopt, $params) = $tmp;
     $opts = array();
     foreach ($tmpopt as $foo => $tmp2) {
         list($opt, $value) = $tmp2;
         if ($value === null) {
             $value = true;
             // options without args
         }
         if (strlen($opt) == 1) {
             $cmdoptions = $cmd->getOptions($command);
             foreach ($cmdoptions as $o => $d) {
                 if (isset($d['shortopt']) && $d['shortopt'] == $opt) {
                     $opts[$o] = $value;
                 }
             }
         } else {
             if (substr($opt, 0, 2) == '--') {
                 $opts[substr($opt, 2)] = $value;
             }
         }
     }
     $ok = $cmd->run($command, $opts, $params);
     if ($ok === false) {
         PEAR::raiseError("unknown command `{$command}'");
     }
     //        error_reporting($old);
 }
示例#24
0
文件: Dump.php 项目: roojs/Pman.Admin
 function get($path)
 {
     ini_set('memory_limit', '256M');
     // we need alot of memory
     set_time_limit(0);
     $argv = $_SERVER['argv'];
     array_shift($argv);
     array_shift($argv);
     $opts = explode(',', 'table==,where==,dump-dir==,debug=');
     require_once 'Console/Getopt.php';
     $go = Console_Getopt::getopt2($argv, '', $opts);
     if (is_object($go)) {
         die($go->toString());
     }
     foreach ($go[0] as $ar) {
         $args[substr($ar[0], 2)] = $ar[1];
     }
     $errs = array();
     foreach ($opts as $req) {
         if (substr($req, -2, 2) != '==') {
             // skip optional arguments
             continue;
         }
         if (empty($args[substr($req, 0, -2)])) {
             $errs[] = "--" . substr($req, 0, -2) . ' is required';
         }
     }
     if (!empty($errs)) {
         die(print_R($errs, true));
     }
     if (!empty($args['debug'])) {
         DB_DataObject::debugLevel($args['debug']);
     }
     $this->args = $args;
     $this->out = array();
     $this->discoverChildren($this->args['table'], $this->args['where'], true);
     //print_R($this->deletes);
     //print_r($this->dumps);
     //exit;
     $this->discover($this->args['table'], $this->args['where'], true);
     if (!file_exists($args['dump-dir'])) {
         mkdir($args['dump-dir'], 0777, true);
     }
     $this->generateInsert();
     $this->generateDelete();
     $this->generateShell();
     echo "DELETING:\n";
     foreach ($this->deletes as $tbl => $ar) {
         if (empty($ar)) {
             continue;
         }
         echo "   " . $tbl . ' -> ' . count(array_keys($ar)) . " Records\n";
     }
     echo "DUMPING:\n";
     foreach ($this->dumps as $tbl => $ar) {
         if (empty($ar)) {
             continue;
         }
         echo "   " . $tbl . ' -> ' . count(array_keys($ar)) . " Records\n";
     }
     echo "FILES:\n";
     echo "   Total : " . $this->filetotal . " files using " . floor($this->filesize / 1000000) . "Mb\n";
     echo "GENERATED FILES:\n";
     // summary
     echo "    " . implode("\n    ", $this->out) . "\n";
     exit;
 }
function parse_arg_list($arg_list)
{
    list($opt_list, $additional) = Console_Getopt::getopt2($arg_list, "skri:c:m:dh", array("start", "kill", "restart", "ident=", "concurrency=", "max-request=", "daemon", "help"));
    $mode = null;
    $ident = null;
    $concurrency = GREE_FASTPROCESSOR_DEFAULT_CONCURRENCY;
    $max_request = GREE_FASTPROCESSOR_DEFAULT_MAX_REQUEST;
    if (is_null($opt_list)) {
        $opt_list = array();
    }
    foreach ($opt_list as $opt) {
        if (is_array($opt) && isset($opt[0])) {
            switch ($opt[0]) {
                case 's':
                case '--start':
                    if (is_null($mode) == false) {
                        printf("-s, -k, -r and -d are exclusive\n\n");
                        usage();
                    }
                    $mode = 'start';
                    break;
                case 'k':
                case '--kill':
                    if (is_null($mode) == false) {
                        printf("-s, -k, -r and -d are exclusive\n\n");
                        usage();
                    }
                    $mode = 'kill';
                    break;
                case 'r':
                case '--restart':
                    if (is_null($mode) == false) {
                        printf("-s, -k, -r and -d are exclusive\n\n");
                        usage();
                    }
                    $mode = 'restart';
                    break;
                case 'i':
                case '--ident':
                    $ident = $opt[1];
                    break;
                case 'c':
                case '--concurrency':
                    $concurrency = intval($opt[1]);
                    if ($concurrency <= 0) {
                        printf("invalid concurrency: {$concurrency}\n\n");
                        usage();
                    }
                    break;
                case 'm':
                case '--max-request':
                    $max_request = intval($opt[1]);
                    if ($max_request <= 0) {
                        printf("invalid max request parameter: {$max_request}\n\n");
                        usage();
                    }
                    break;
                case 'd':
                case '--daemon':
                    if (is_null($mode) == false) {
                        printf("-s, -k, -r, -d, -w and -g are exclusive\n\n");
                        usage();
                    }
                    $mode = 'daemon';
                    break;
                case 'h':
                case '--help':
                    usage();
                    break;
                default:
                    printf("unkown option [%s]\n\n", $opt[0]);
                    usage();
                    break;
            }
        }
    }
    if (is_null($ident)) {
        printf("option [--ident] is required\n\n");
        usage();
    }
    return array($mode, $ident, $concurrency, $max_request);
}
示例#26
0
define('SF_DEBUG', 1);
require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
require_once 'Console/Getopt.php';
// initialize database manager
$databaseManager = new sfDatabaseManager();
$databaseManager->initialize();
// batch process here
//     insert jon's user id
$userId = 36;
xdebug_break();
$cg = new Console_Getopt();
$args = $cg->readPHPArgv();
array_shift($args);
$shortOpts = 's::v::f:d';
$longOpts = array('schema_id==', 'vocab_id==', 'file=', 'delete_missing');
$params = $cg->getopt2($args, $shortOpts, $longOpts);
if (PEAR::isError($params)) {
    echo 'Error: ' . $params->getMessage() . "\n";
    exit(1);
}
var_dump(condense_arguments($params));
//     concept scheme or element set selected (get from command line)
//        schema_id= vocab_id= file=     -delete_missing
//       -snnnnn    -vnnnnnn  -fnnnnnnnn -d
//     Select a file (get from the command line)
//     determine/ask the file type (rdf, xml, json, csv) (get from file extension)
//     determine/ask the object type (get from command line)
/* From here on the process is the same regardless of UI */
//execute
//     parse file to get the fields/columns and data
//     check to see if file has been uploaded before
示例#27
0
 /**
  * getArgs -- used in the constructor to gather the commandline flags and options.
  * Uses Console_Getopt.
  *
  * @param  string $shortOpts single-letter flags (e.g. '-r')
  * @param  mixed $longOpts  multi-letter flags (e.g. '--makeitwork')
  * @return void
  */
 private function getArgs($shortOpts = '', $longOpts = array())
 {
     $cg = new Console_Getopt();
     $args = $cg->readPHPArgv();
     array_shift($args);
     $params = $cg->getopt2($args, $shortOpts, $longOpts);
     if (PEAR::isError($params)) {
         echo 'Error: ' . $params->getMessage() . "\n";
         exit(1);
     }
     $cline_args = $this->condenseArguments($params);
     return $cline_args;
 }
示例#28
0
function main()
{
    $shortopts = "lhmn";
    $longopts = array("mode=", "maxlen=");
    $maxlen = 80;
    $mode_line = 'c-default-style: "bsd"; indent-tabs-mode: nil; ' . 'c-basic-offset: 4;';
    $cg = new Console_Getopt();
    $dirs = $cg->readPHPArgv();
    array_shift($dirs);
    /* Trash $0, the name of the script */
    $ret = $cg->getopt2($dirs, $shortopts, $longopts);
    $license = false;
    $just_show = false;
    if (PEAR::isError($ret)) {
        echo $ret->getMessage(), "\n\n";
        usage();
    }
    list($opts, $dirs) = $ret;
    foreach ($opts as $opt) {
        list($o, $val) = $opt;
        switch ($o) {
            case 'h':
                usage(true);
                break;
            case 'm':
                echo "Mode Line: {$mode_line}\n";
                die;
                break;
            case '--mode':
                $mode_line = $val;
                break;
            case '--maxlen':
                $maxlen = $val;
                break;
            case 'l':
                $license = true;
                break;
            case 'n':
                $just_show = true;
                break;
            default:
                echo "Unknown option: {$o}\n\n";
                usage(true);
        }
    }
    if (count($dirs) == 0) {
        usage();
    }
    foreach ($dirs as $dir) {
        run_files($dir, $license, $mode_line, $maxlen, $just_show);
    }
}
     usage(null, @$options[1][1]);
 }
 if (!$config->validConfiguration()) {
     PEAR::raiseError('CRITICAL ERROR: no existing valid configuration files found in files ' . "'{$pear_user_config}' or '{$pear_system_config}', please copy an existing configuration" . 'file to one of these locations, or use the -c and -s options to create one');
 }
 PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
 $cmd = PEAR_Command::factory($command, $config);
 PEAR::popErrorHandling();
 if (PEAR::isError($cmd)) {
     usage(null, @$options[1][0]);
 }
 $short_args = $long_args = null;
 PEAR_Command::getGetoptArgs($command, $short_args, $long_args);
 if (in_array('getopt2', get_class_methods('Console_Getopt'))) {
     array_shift($options[1]);
     $tmp = Console_Getopt::getopt2($options[1], $short_args, $long_args);
 } else {
     $tmp = Console_Getopt::getopt($options[1], $short_args, $long_args);
 }
 if (PEAR::isError($tmp)) {
     break;
 }
 list($tmpopt, $params) = $tmp;
 $opts = array();
 foreach ($tmpopt as $foo => $tmp2) {
     list($opt, $value) = $tmp2;
     if ($value === null) {
         $value = true;
         // options without args
     }
     if (strlen($opt) == 1) {
示例#30
0
 /**
  * returns the commandline arguments of a function
  *
  * @param    string  $argv           the commandline
  * @param    string  $short_options  the allowed option short-tags
  * @param    string  $long_options   the allowed option long-tags
  * @return   array   the given options and there values
  * @static
  * @access private
  */
 function _parseArgs($argv, $short_options, $long_options = null)
 {
     if (!is_array($argv) && $argv !== null) {
         /*
         // Quote all items that are a short option
         $av = preg_split('/(\A| )--?[a-z0-9]+[ =]?((?<!\\\\)((,\s*)|((?<!,)\s+))?)/i', $argv, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_OFFSET_CAPTURE);
         $offset = 0;
         foreach ($av as $a) {
             $b = trim($a[0]);
             if ($b{0} == '"' || $b{0} == "'") {
                 continue;
             }
         
             $escape = escapeshellarg($b);
             $pos = $a[1] + $offset;
             $argv = substr_replace($argv, $escape, $pos, strlen($b));
             $offset += 2;
         }
         */
         // Find all items, quoted or otherwise
         preg_match_all("/(?:[\"'])(.*?)(?:['\"])|([^\\s]+)/", $argv, $av);
         $argv = $av[1];
         foreach ($av[2] as $k => $a) {
             if (empty($a)) {
                 continue;
             }
             $argv[$k] = trim($a);
         }
     }
     return Console_Getopt::getopt2($argv, $short_options, $long_options);
 }