Beispiel #1
0
function run_default($task, $args)
{
    pake_echo_error('Installer is a separate tool now. Please use that');
    try {
        pake_which('mvc_install');
        pake_echo_comment('It is already installed on your system. Type: mvc_install');
    } catch (pakeException $e) {
        pake_echo_comment('I will install it for you…');
        pakePearTask::install_pear_package('midgardmvc_installer', 'pear.indeyets.pp.ru');
        pake_echo_comment('Done. To use it, type: mvc_install');
    }
}
Beispiel #2
0
function run_import_users($task, $args)
{
    if (!isset($args[0])) {
        pake_echo_error('usage: pake i "users.yml"');
        return false;
    }
    pake_echo_comment("Reading file. It can take awhile…");
    $str = file_get_contents($args[0]);
    $data = pakeYaml::loadString($str);
    pake_echo_comment("Starting import…");
    $len = count($data);
    for ($i = 0; $i < $len; $i++) {
        $row = $data[$i];
        if (_create_user($row['login'], $row['password'], $row['data'])) {
            pake_echo_action('user+', "({$i} of {$len}) " . $row['login']);
        } else {
            pake_echo_comment('already exists: ' . "({$i} of {$len}) " . $row['login']);
        }
    }
}
Beispiel #3
0
 private function git_run($command)
 {
     $git = escapeshellarg(pake_which('git'));
     if (self::$needs_work_tree_workaround === true) {
         $cmd = '(cd ' . escapeshellarg($this->repository_path) . ' && ' . $git . ' ' . $command . ')';
     } else {
         $cmd = $git;
         $cmd .= ' ' . escapeshellarg('--git-dir=' . $this->repository_path . '/.git');
         $cmd .= ' ' . escapeshellarg('--work-tree=' . $this->repository_path);
         $cmd .= ' ' . $command;
     }
     try {
         pake_sh($cmd);
     } catch (pakeException $e) {
         if (strpos($e->getMessage(), 'cannot be used without a working tree') !== false) {
             pake_echo_error('Your version of git is buggy. Using workaround');
             self::$needs_work_tree_workaround = true;
             $this->git_run($command);
         }
     }
 }
 /**
  * execute HTTP Request
  *
  * @param string $method 
  * @param string $url 
  * @param mixed $query_data string or array
  * @param mixed $body string or array
  * @param array $headers 
  * @param array $options 
  * @return string
  */
 public static function request($method, $url, $query_data = null, $body = null, array $headers = array(), array $options = array())
 {
     $method = strtoupper($method);
     $_options = array('method' => $method, 'user_agent' => 'pake ' . pakeApp::VERSION, 'ignore_errors' => true);
     $parsed_url = parse_url($url);
     $proxy_var_name = null;
     if ($parsed_url['scheme'] == 'http') {
         $proxy_var_name = 'http_proxy';
     } elseif ($parsed_url['scheme'] == 'https') {
         if (isset($_SERVER['https_proxy'])) {
             $proxy_var_name = 'https_proxy';
         } elseif (isset($_SERVER['HTTPS_PROXY'])) {
             $proxy_var_name = 'HTTPS_PROXY';
         }
     }
     if (null !== $proxy_var_name) {
         if (isset($_SERVER[$proxy_var_name])) {
             $parsed_proxy_str = parse_url($_SERVER[$proxy_var_name]);
             if (is_array($parsed_proxy_str) and $parsed_proxy_str['scheme'] == 'http' and isset($parsed_proxy_str['host']) and isset($parsed_proxy_str['port'])) {
                 $_options['proxy'] = 'tcp://' . $parsed_proxy_str['host'] . ':' . $parsed_proxy_str['port'];
                 $_options['request_fulluri'] = true;
                 pake_echo_comment('(using proxy: ' . $parsed_proxy_str['host'] . ':' . $parsed_proxy_str['port'] . ')');
             } else {
                 pake_echo_error('"' . $proxy_var_name . '" environment variable is set to the wrong value. expecting http://host:port');
             }
         }
     }
     if (null !== $body) {
         if (is_array($body)) {
             $body = http_build_query($body);
         }
         $_options['content'] = $body;
     }
     if (count($headers) > 0) {
         $_options['header'] = implode("\r\n", $headers) . "\r\n";
     }
     $options = array_merge($_options, $options);
     if (null !== $query_data) {
         if (is_array($query_data)) {
             $query_data = http_build_query($query_data);
         }
         $url .= '?' . $query_data;
     }
     $context = stream_context_create(array('http' => $options));
     pake_echo_action('HTTP ' . $method, $url);
     $stream = @fopen($url, 'r', false, $context);
     if (false === $stream) {
         $err = error_get_last();
         throw new pakeException('HTTP request failed: ' . $err['message']);
     }
     $meta = stream_get_meta_data($stream);
     $response = stream_get_contents($stream);
     fclose($stream);
     $status = $meta['wrapper_data'][0];
     $code = substr($status, 9, 3);
     if ($code > 400) {
         throw new pakeException('http request returned: ' . $status);
     }
     pake_echo_action('…', 'got ' . strlen($response) . ' bytes');
     return $response;
 }
 public static function run_test($task)
 {
     $php_cgi = '';
     $_php_cgi = self::_get_php_executable() . '-cgi';
     if (file_exists($_php_cgi)) {
         $php_cgi = ' ' . escapeshellarg('TEST_PHP_CGI_EXECUTABLE=' . $_php_cgi);
     }
     pake_echo_comment('Running test-suite. This can take awhile…');
     pake_sh('make test NO_INTERACTION=1' . $php_cgi);
     pake_echo_comment('Done');
     $path = dirname(pakeApp::get_instance()->getPakefilePath()) . '/tests';
     $files = pakeFinder::type('file')->ignore_version_control()->relative()->name('*.diff')->in($path);
     if (count($files) == 0) {
         pake_echo('   All tests PASSed!');
         return;
     }
     pake_echo_error('Following tests FAILed:');
     foreach ($files as $file) {
         $phpt_file = substr($file, 0, -4) . 'phpt';
         $_lines = file($path . '/' . $phpt_file);
         $description = $_lines[1];
         unset($_lines);
         pake_echo('     ' . $phpt_file . ' (' . rtrim($description) . ')');
     }
 }
Beispiel #6
0
 /**
  * Determines an issue type by looking it up in the bug tracker
  * @param $issue
  * @param $opts
  */
 static function findIssueType($issue, $opts = false)
 {
     // dirty workaround
     if ($opts == false) {
         $opts = self::$options[self::$projname];
     }
     if ($opts['bugtracker']['url'] == '') {
         pake_echo_error("Can not determine issue type on bugtracker with empty url");
         return 'unknown';
     }
     $url = str_replace('__ISSUE__', $issue, $opts['bugtracker']['url']);
     $page = file_get_contents($url);
     switch ($opts['bugtracker']['type']) {
         case 'jira':
             $knowntypes = array('1' => 'bugfix', '4' => 'enhancement', '5' => 'enhancement', '7' => 'enhancement');
             $data = json_decode($page, true);
             if (isset($data['fields']['issuetype']['id']) && isset($knowntypes[$data['fields']['issuetype']['id']])) {
                 return $knowntypes[$data['fields']['issuetype']['id']];
             } else {
                 pake_echo_error("Can not determine issue type on Jira url '{$url}'");
             }
             break;
         default:
             pake_echo_error("Can not determine issue type on bugtracker '{$opts['bugtracker']['type']}'");
     }
     return 'unknown';
 }
 /**
  * Creates a tarball of the built extension.
  *
  * Depending on configuration options, different versions of the extenion tarball
  * are generated by this task: .tar.gz, .zip, .ezpkg
  */
 static function run_dist($task = null, $args = array(), $cliopts = array())
 {
     $opts = self::getOpts(@$args[0], @$args[1], $cliopts);
     if ($opts['create']['tarball'] || $opts['create']['zip'] || $opts['create']['ezpackage'] || $opts['create']['pearpackage']) {
         if (!SharedLock::acquire($opts['extension']['name'], LOCK_SH, $opts)) {
             throw new PakeException("Source code locked by another process");
         }
         pake_mkdirs($opts['dist']['dir']);
         $rootpath = self::getBuildDir($opts) . '/' . $opts['extension']['name'];
         if ($opts['create']['tarball']) {
             $target = $opts['dist']['dir'] . '/' . $opts['extension']['name'] . '-' . $opts['version']['alias'] . '.' . $opts['version']['release'] . '.tar.gz';
             self::archiveDir($rootpath, $target);
         }
         if ($opts['create']['zip']) {
             $target = $opts['dist']['dir'] . '/' . $opts['extension']['name'] . '-' . $opts['version']['alias'] . '.' . $opts['version']['release'] . '.zip';
             self::archiveDir($rootpath, $target);
         }
         if ($opts['create']['ezpackage'] || $opts['create']['pearpackage']) {
             $toppath = $opts['build']['dir'];
             // check if package.xml file is there
             $file = pakeFinder::type('file')->name('package.xml')->maxdepth(0)->in($toppath);
             if (!count($file)) {
                 pake_echo_error("File 'package.xml' missing in build dir {$rootpath}. Cannot create package(s)");
                 return;
             }
             // cleanup if extra files/dirs found
             $dirs = array();
             $dirs = pakeFinder::type('directory')->not_name(array('documents', 'ezextension'))->maxdepth(0)->in($toppath);
             $dirs = array_merge($dirs, pakeFinder::type('directory')->in($toppath . '/documents'));
             $dirs = array_merge($dirs, pakeFinder::type('directory')->not_name($opts['extension']['name'])->maxdepth(0)->in($toppath . '/ezextension'));
             $files = pakeFinder::type('file')->not_name('package.xml')->maxdepth(0)->in($toppath);
             $files = array_merge($files, pakeFinder::type('file')->in($toppath . '/documents'));
             $files = array_merge($files, pakeFinder::type('file')->not_name('extension-' . $opts['extension']['name'] . '.xml')->maxdepth(0)->in($toppath . '/ezextension'));
             if (count($dirs) || count($files)) {
                 pake_echo("Extra files/dirs found in build dir. Must remove them to continue:\n  " . implode("\n  ", $dirs) . "  " . implode("\n  ", $files));
                 $ok = pake_input("Do you want to delete them? [y/n]", 'n');
                 if ($ok != 'y') {
                     return;
                 }
                 foreach ($files as $file) {
                     pake_remove($file, '');
                 }
                 foreach ($dirs as $dir) {
                     pake_remove_dir($dir);
                 }
             }
             // prepare missing folders/files
             /// @todo we should not blindly copy LICENSE and README, but inspect actual package.xml file
             ///       and copy any files mentioned there
             pake_copy($rootpath . '/' . $opts['files']['gnu_dir'] . '/LICENSE', $toppath . '/documents/LICENSE');
             pake_copy($rootpath . '/' . $opts['files']['gnu_dir'] . '/README', $toppath . '/documents/README');
             $target = $opts['dist']['dir'] . '/' . $opts['extension']['name'] . '_extension.ezpkg';
             self::archiveDir($toppath, $target, true);
             if ($opts['create']['pearpackage']) {
                 /// @todo ...
                 pake_echo_error("PEAR package creation not yet implemented");
             }
         }
         SharedLock::release($opts['extension']['name'], LOCK_SH, $opts);
     }
 }
Beispiel #8
0
function pake_select_input($question, array $options, $default = null)
{
    if (null !== $default) {
        if (!is_numeric($default)) {
            throw new UnexpectedValueException("Default is specified, but is not numeric");
        }
        if (!isset($options[$default])) {
            throw new UnexpectedValueException("Default is specified, but it is not one of options");
        }
    }
    pake_echo($question);
    $i = 1;
    $options_strs = array();
    foreach ($options as $option) {
        $options_strs[] = '(' . $i++ . ') ' . $option;
    }
    pake_echo('  ' . implode("\n  ", $options_strs));
    while (true) {
        if (null === $default) {
            $prompt = '[>] ';
        } else {
            $prompt = '[> default="' . ($default + 1) . '"] ';
        }
        $retval = pakeInput::getString($prompt);
        if ('' === $retval) {
            if (null === $default) {
                continue;
            }
            $retval = $options[$default];
        } else {
            if (!is_numeric($retval)) {
                pake_echo_error("Just enter number");
                continue;
            }
            if (!isset($options[$retval - 1])) {
                pake_echo_error("There is no option " . $retval);
                continue;
            }
            $retval = $options[$retval - 1];
        }
        break;
    }
    return $retval;
}
 /**
  * Removes orphaned lock files - by checking their PIDs against running processes
  * @param array $opts
  */
 public static function cleanup($opts = array())
 {
     if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
         exec('tasklist /FO CSV', $runningProcesses, $return_var);
         $runningProcesses = array_map(function ($line) {
             $cols = explode(',', $line);
             return trim($cols[1], '"');
         }, $runningProcesses);
         unset($runningProcesses[0]);
         // 'PID'
         sort($runningProcesses);
         unset($runningProcesses[0]);
         // 0
     } else {
         exec('ps -e -o pid', $runningProcesses, $return_var);
     }
     if ($return_var != 0) {
         pake_echo_error("Could not get list of processes to remove stale lock files");
         return;
     }
     $lockDir = self::lockDir($opts);
     foreach (glob($lockDir . "/*_W.lock") as $writeLock) {
         $pid = file_get_contents($writeLock);
         //strstr( file_get_contents( $writeLock ), ' ', true );
         if (!in_array($pid, $runningProcesses)) {
             pake_unlink($writeLock);
         }
     }
     foreach (glob($lockDir . "/*_R/*.lock") as $readLock) {
         $pid = file_get_contents($readLock);
         // strstr( file_get_contents( $readLock ), ' ', true );
         if (!in_array($pid, $runningProcesses)) {
             pake_unlink($readLock);
         }
     }
 }