Esempio n. 1
0
 /**
  * Prints the message of an occured error and exits the program.
  * This method is used to print an error message, as soon as an error
  * occurs end quit the program with return code -1. Optionally, the
  * method will trigger the help text to be printed after the error message.
  * 
  * @param string $message The error message to print
  * @param bool $printHelp Whether to print the help after the error msg.
  */
 private function raiseError($message, $printHelp = false)
 {
     $this->output->outputLine($message, 'error');
     $this->output->outputLine();
     if ($printHelp === true) {
         $this->output->outputText($this->input->getHelpText(ezcPersistentObjectSchemaGenerator::PROGRAM_DESCRIPTION), "help");
     }
     exit(-1);
 }
Esempio n. 2
0
 /**
  * Displays messages
  *
  * @var string $message Message to display
  * @var string $type    Type of the message
  * @return void
  */
 public static function displayMessage($message, $type = 'info')
 {
     if ('info' == $type && !self::$consoleInput->getOption('verbose')->value) {
         return;
     } elseif ('debug' == $type && !self::$consoleInput->getOption('debug')->value) {
         return;
     }
     self::$consoleOutput->outputText("{$message}\n", $type);
 }
Esempio n. 3
0
 /**
  * Prints the message of an occured error and exits the program.
  * This method is used to print an error message, as soon as an error
  * occurs end quit the program with return code -1. Optionally, the
  * method will trigger the help text to be printed after the error message.
  *
  * @param string $message The error message to print
  * @param bool $printHelp Whether to print the help after the error msg.
  */
 private function raiseError($message, $printHelp = false)
 {
     $this->output->outputLine($message, 'error');
     $this->output->outputLine();
     if ($printHelp === true) {
         $this->output->outputText($this->input->getHelpText(self::PROGRAM_DESCRIPTION), "help");
     }
     exit(-1);
 }
Esempio n. 4
0
 /**
  * Add a status to the status bar.
  * Adds a new status to the bar which is printed immediately. If the
  * cursor is currently not at the beginning of a line, it will move to
  * the next line.
  *
  * @param bool $status Print successChar on true, failureChar on false.
  * @return void
  */
 public function add($status)
 {
     if (is_bool($status) === false) {
         trigger_error('Unknown status ' . var_export($status, true) . '.', E_USER_WARNING);
         $status = (bool) $status;
     }
     switch ($status) {
         case true:
             $this->outputHandler->outputText($this->properties['options']['successChar'], 'success');
             break;
         case false:
             $this->outputHandler->outputText($this->properties['options']['failureChar'], 'failure');
             break;
     }
     $this->counter[$status]++;
 }
// ---------------------------------------------------------------------------
if ( $helpOption->value === true )
{
    echo $input->getSynopsis() . "\n";
    foreach ( $input->getOptions() as $option )
    {
        echo " -{$option->short}, --{$option->long}\t {$option->shorthelp}\n";
    }
    die();
}


// Generate test file
// ---------------------------------------------------------------------------
$generator = new ezpGenerateTestCaseFromClass( $sourceFileOption->value, $destinationFileOption->value );
$generator->generate();

$testCount = count( $generator->methods );
$out->outputText( "Generated " );
$out->outputText( $testCount, 'count' );
$out->outputText( " tests from " );
$out->outputText( $sourceFileOption->value, 'source' );
$out->outputText( "\n" );

$out->outputText( "Tests written to " );
$out->outputText( $destinationFileOption->value, 'dest' );
$out->outputText( "\n" );


?>
Esempio n. 6
0
 public function testToPos()
 {
     $output = new ezcConsoleOutput();
     ob_start();
     $output->outputText("Test 123");
     $output->toPos(6);
     $output->outputText("456");
     $res = ob_get_clean();
     $exp = 'Test 123456';
     $this->assertEquals($exp, $res, "Position code not generated correctly.");
 }
Esempio n. 7
0
$input->argumentDefinition = new ezcConsoleArguments();
$input->argumentDefinition[0] = new ezcConsoleArgument("artist");
$input->argumentDefinition[0]->mandatory = true;
$input->argumentDefinition[0]->shorthelp = "The artist to search for";
$output = new ezcConsoleOutput();
$output->formats->info->color = 'blue';
$output->formats->error->color = 'red';
$output->formats->error->style = array('bold');
$output->formats->fatal->color = 'red';
$output->formats->fatal->style = array('bold', 'underlined');
$output->formats->fatal->bgcolor = 'black';
try {
    $input->process();
} catch (ezcConsoleArgumentMandatoryViolationException $e) {
    if ($helpOption->value === true) {
        $output->outputText($input->getHelpText("Auto-link by artist name"));
        exit;
    } else {
        $output->outputLine("No arguments given", "fatal");
        $output->outputText($input->getHelpText("Auto-link by artist name"));
        exit(1);
    }
} catch (ezcConsoleException $e) {
    die($e->getMessage());
}
if ($input->argumentDefinition["artist"]->value === null) {
    $output->outputLine("The <artist> argument is mandatory", 'fatal');
    $output->outputText($input->getHelpText("Auto-link by artist name"), 'fatal');
    exit;
}
var_dump($verboseOption->value);
Esempio n. 8
0
 public function testToPos()
 {
     if (ezcBaseFeatures::os() === 'Windows') {
         $this->markTestSkipped("Does not work on Windows");
     }
     $output = new ezcConsoleOutput();
     ob_start();
     $output->outputText("Test 123");
     $output->toPos(6);
     $output->outputText("456");
     $res = ob_get_clean();
     $exp = 'Test 123456';
     $this->assertEquals($exp, $res, "Position code not generated correctly.");
 }
Esempio n. 9
0
// Set the verbosity to level 10
$out->options->verbosityLevel = 10;
// Enable auto wrapping of lines after 40 characters
$out->options->autobreak = 40;
// Set the color of the default output format to green
$out->formats->default->color = 'green';
// Set the color of the output format named 'success' to white
$out->formats->success->color = 'white';
// Set the style of the output format named 'success' to bold
$out->formats->success->style = array('bold');
// Set the color of the output format named 'failure' to red
$out->formats->failure->color = 'red';
// Set the style of the output format named 'failure' to bold
$out->formats->failure->style = array('bold');
// Set the background color of the output format named 'failure' to blue
$out->formats->failure->bgcolor = 'blue';
// Output text with default format
$out->outputText('This is default text ');
// Output text with format 'success'
$out->outputText('including success message', 'success');
// Some more output with default output.
$out->outputText("and a manual linebreak.\n");
// Manipulate the later output
$out->formats->success->color = 'green';
$out->formats->default->color = 'blue';
// This is visible, since we set verboseLevel to 10, and printed in default format (now blue)
$out->outputText("Some verbose output.\n", null, 10);
// This is not visible, since we set verboseLevel to 10
$out->outputText("Some more verbose output.\n", null, 20);
// This is visible, since we set verboseLevel to 10, and printed in format 'failure'
$out->outputText("And some not so verbose, failure output.\n", 'failure', 5);
                    $file->delete();
                    eZImageFile::removeFilepath( $contentObjectAttributeID, $filePath );
                    eZDir::cleanupEmptyDirectories( $dirpath );
                }

                // Delete the obsolete reference in the database
                $image->remove();
            }

            $progressBar->advance();
        }

        $progressBar->finish();
        $output->outputLine();
    }
    else
    {
        $output->outputText( 'No image file found !' );
        $output->outputLine();
    }

    $script->shutdown();
}
catch(Exception $e)
{
    $output->outputText( $e->getMessage(), 'error' );
    $output->outputLine();
    $script->shutdown( $e->getCode() );
}
?>
Esempio n. 11
0
// Create progress bar itself
$progress = new ezcConsoleProgressbar($out, 100, array('step' => 5));
$progress->options->emptyChar = '-';
$progress->options->progressChar = $out->formatText('>', "red");
$progress->options->formatString = "Uploading file </tmp/foobar.tar.bz2>: %act%/%max% kb [%bar%]";
// Perform actions
$i = 0;
while ($i++ < 20) {
    // Do whatever you want to indicate progress for
    usleep(mt_rand(20000, 2000000));
    // Advance the progressbar by one step ( uploading 5k per run )
    $progress->advance();
}
// Finish progress bar and jump to next line.
$progress->finish();
$out->outputText("Successfully uploaded </tmp/foobar.tar.bz2>.\n", 'success');
/*
OUTPUT: (sequential, will be printed into 1 line and updated in reallife)
Uploading file </tmp/foobar.tar.bz2>:   5/100 kb [++#----------------------------------------------]
Uploading file </tmp/foobar.tar.bz2>:  10/100 kb [+++++#-------------------------------------------]
Uploading file </tmp/foobar.tar.bz2>:  15/100 kb [++++++++#----------------------------------------]
Uploading file </tmp/foobar.tar.bz2>:  20/100 kb [+++++++++++#-------------------------------------]
Uploading file </tmp/foobar.tar.bz2>:  25/100 kb [++++++++++++++#----------------------------------]
Uploading file </tmp/foobar.tar.bz2>:  30/100 kb [+++++++++++++++++#-------------------------------]
Uploading file </tmp/foobar.tar.bz2>:  35/100 kb [++++++++++++++++++++#----------------------------]
Uploading file </tmp/foobar.tar.bz2>:  40/100 kb [+++++++++++++++++++++++#-------------------------]
Uploading file </tmp/foobar.tar.bz2>:  45/100 kb [++++++++++++++++++++++++++#----------------------]
Uploading file </tmp/foobar.tar.bz2>:  50/100 kb [+++++++++++++++++++++++++++++#-------------------]
Uploading file </tmp/foobar.tar.bz2>:  55/100 kb [++++++++++++++++++++++++++++++++#----------------]
Uploading file </tmp/foobar.tar.bz2>:  60/100 kb [+++++++++++++++++++++++++++++++++++#-------------]
Uploading file </tmp/foobar.tar.bz2>:  65/100 kb [++++++++++++++++++++++++++++++++++++++#----------]
<?php

require_once 'tutorial_autoload.php';
$output = new ezcConsoleOutput();
$output->formats->info->color = 'blue';
$output->outputText('Test text in color blue', 'info');
Esempio n. 13
0
$helpOption->isHelpOption = true;
$helpOption->shorthelp = 'Display current help information.';
$extensionOption = $input->registerOption(new ezcConsoleOption('e', 'extension', ezcConsoleInput::TYPE_STRING));
$extensionOption->mandatory = true;
$extensionOption->shorthelp = 'Full path to the eZ Publish extension e.g \'/home/ls/public_html/ezp/extension/myextension\'';
$extensionNameOption = $input->registerOption(new ezcConsoleOption('n', 'extension-name', ezcConsoleInput::TYPE_STRING));
$extensionNameOption->mandatory = true;
$extensionNameOption->shorthelp = 'Extension name. e.g \'myextension\'';
try {
    $input->process();
} catch (ezcConsoleOptionException $e) {
    $output->outputLine($e->getMessage());
    exit;
}
if ($helpOption->value === true) {
    $output->outputText($input->getHelpText('This script generate an XML definition for eZ Publish extension package type.'));
    exit;
}
$sourceDir = $extensionOption->value;
$extensionName = $extensionNameOption->value;
$fileList = array();
recursiveList($sourceDir, '', $fileList);
$doc = new DOMDocument('1.0', 'utf-8');
$doc->formatOutput = true;
$packageRoot = $doc->createElement('extension');
$packageRoot->setAttribute('name', $extensionName);
foreach ($fileList as $file) {
    $fileNode = $doc->createElement('file');
    $fileNode->setAttribute('name', $file['name']);
    if ($file['path']) {
        $fileNode->setAttribute('path', $file['path']);
<?php

require_once 'tutorial_autoload.php';
$output = new ezcConsoleOutput();
$output->formats->info->color = 'blue';
$output->formats->error->color = 'red';
$output->formats->error->style = array('bold');
$output->formats->fatal->color = 'red';
$output->formats->fatal->style = array('bold', 'underlined');
$output->formats->fatal->bgcolor = 'black';
$output->outputText('This is some standard text ');
$output->outputText('including some error', 'error');
$output->outputText(' wrapped in standard text.');
$output->outputText("\n");
$output->outputLine('This is a fatal error message.', 'fatal');
$output->outputText('Test');