public function printHelp() { if (!is_null($this->short)) { pantr::writeOption($this->short, $this->long, $this->desc); } else { pantr::writeOption($this->long, $this->desc); } }
public static function task($name, $file, $spec) { $out = \pantr\fileNameTransform($file, $spec); $task = new File($name, 'create file ' . basename($out) . ' if it does not exist'); $task->src = $file; $task->target = $out; pantr::getTaskRepository()->registerTask($task); return $task; }
public function createPackage($in = null) { $this->writePackageFile(); if (!is_null($in)) { pantr::mkdirs($in); } $pkgFile = $this->options[self::OPT_BASEDIR] . DIRECTORY_SEPARATOR . 'package.xml'; pantr::create_pear_package($pkgFile, $in); }
public static function push($tgzPath) { $push = new \Pearfarm_Task_Push(); try { $push->run(array('push', $tgzPath)); } catch (\Pearfarm_TaskArgumentException $ex) { pantr::writeln($ex->getMessage(), pantr::ERROR); pantr::log()->error($ex); } }
public static function create($phar, $src = 'src') { pantr::writeAction('phar', $phar); $p = new Phar($phar); $p->startBuffering(); if (is_callable($src)) { $src($p); } else { $p->addDirectories($src); $p->setDefaultStub(); } $p->stopBuffering(); }
public function addLatestVersion($dir) { $files = pantr::fileset()->name('*.tgz')->relative()->in($dir); $highest = array_reduce($files, function ($pkg1, $pkg2) { if (is_null($pkg1)) { return $pkg2; } list($pkgname, $a) = explode('-', basename($pkg1, '.tgz')); list($pkgname, $b) = explode('-', basename($pkg2, '.tgz')); return version_compare($a, $b, '<') ? $pkg1 : $pkg2; }, null); $this->add($dir . DIRECTORY_SEPARATOR . $highest); }
public function execute(Task $task, $abortOnFailure = true) { $path = $this->executionStrategyFactory->get($task); foreach ($path as $subTaskName) { $subTask = $this->taskRepository->getTask($subTaskName); $status = $subTask($this->args); if ($status == Status::FAILURE && $abortOnFailure) { pantr::writeln('Task "' . $subTaskName . '" failed. Aborting.', pantr::ERROR); return Status::FAILURE; } } return Status::SUCCESS; }
public function printOptions() { if (count($this->descriptionTable) > 0) { pantr::out()->nl()->writeln('Options:', 'BOLD'); foreach ($this->descriptionTable as $long => $desc) { // check if there is a short version if (isset($this->requestAliasTable[$long])) { $short = $this->requestAliasTable[$long]; pantr::writeOption($short, $long, $desc); } else { pantr::writeOption($long, $desc); } } } }
public function run($verbose = false, $taskName = 'test:unit') { $suite = $this->getTestSuite(); if ($verbose) { $result = \PHPUnit_TextUI_TestRunner::run($suite, $this->arguments); } else { // execute the test ob_start(); $listener = new AssertionTestListener(); $runner = new TestRunner($listener); $result = $runner->doRun($suite, $this->arguments); ob_end_clean(); $assertions = $listener->numAssertions; if ($result->wasSuccessful()) { pantr::writeAction($taskName, $this->formatTestResult($result, $assertions)); return Task::SUCCESS; } else { pantr::writeAction($taskName, $this->formatTestResult($result, $assertions), pantr::WARNING); return Task::FAILED; } } }
public function run() { // pure args $args = func_get_args(); if (count($args) == 1 && is_array($args[0])) { $args = $args[0]; } // this request $req = self::getRequestContainer($args); $taskName = $req[0]; $useGlobalTasks = isset($req['global']); // load local pantrfile // we only need to load this once // unless the --file option is specified in which case // we load it if (!$useGlobalTasks && ($this->pantrfileLoaded == false || isset($req['file']))) { $this->pantrfileLoaded = true; $pantrfile = $this->pantrfileFactory->getTaskFile($req['file'] ?: 'pantrfile'); if (!is_null($pantrfile)) { // change current dir to pantrfile chdir($pantrfile->getPath()); $pantrfile->load($this->tasks); } else { if ($taskName[0] != ':') { // not a global task pantr::writeln('No pantrfile found.', \pantr\pantr::WARNING); } } } // prepare task $task = $this->getTask($taskName); if (is_null($task)) { throw new NoTaskFoundException($taskName); } $taskArgs = $this->getTaskArgs($taskName, $args); // and now - finally - execute it $executor = $this->taskExecutorFactory->get($taskArgs); $executor->execute($task, $req['ignore-failure'] ?: true); }
public static function sh($cmd, $interactive = false) { $verbose = true; pantr::writeAction('exec ', $cmd); if (false === $interactive) { ob_start(); } passthru($cmd . ' 2>&1', $return); if (false === $interactive) { $content = ob_get_clean(); if ($return > 0) { throw new \Exception(sprintf('Problem executing command %s', $verbose ? "\n" . $content : '')); } } else { if ($return > 0) { throw new \Exception('Problem executing command'); } } if (false === $interactive) { return $content; } }
pantr::rm($self->peardir); }); }); // preparation $self->peardir = __DIR__ . '/../../../tmp/pear'; pantr::silent(function () use(&$self) { pantr::mkdirs($self->peardir); }); $self->peardir = realpath($self->peardir); $self->repo = new Repository($self->peardir); $self->repo->create(); it('should create a new repository if there is none', function ($self) { // in case it has already been created we just delete it pantr::silent(function () use($self) { pantr::rm($self->peardir); pantr::mkdirs($self->peardir); }); theFile($self->peardir . '/.pearrc')->shouldNotExist(); $repo = new Repository($self->peardir); theValueOf($repo->exists())->shouldBe(false); $repo->create(); theValueOf($repo->exists())->shouldBeTrue(); theFile($self->peardir . '/.pearrc')->shouldExist(); }); it('should discover a channel', function ($self) { $discovery = function () use($self) { $self->repo->discoverChannel('pear.pagosoft.com'); }; evaluating($discovery)->shouldProduceOutput("Adding Channel \"pear.pagosoft.com\" succeeded\n" . "Discovery of channel \"pear.pagosoft.com\" succeeded\n"); }); it('should install a package', function ($self) {
* * @needsRequest * @hidden */ task('config:deploy-local', function ($req) { if (isset($req['l'])) { writeAction('switch', 'to local pear channel'); property('pear.channel', 'pear.localhost'); property('pear.dir', __DIR__ . '/../lpear'); } }); /** * Install/remove channels and packages */ task('deps', function () { pantr::dependencies()->in('lib')->fromChannel('pear.pagosoft.com')->usePackage('util')->usePackage('cli')->usePackage('parser')->fromChannel('pear.php-tools.net')->usePackage('vfsstream', 'alpha')->fromChannel('pear.symfony-project.com')->usePackage('yaml')->sync(); }); // build process /** * Create build directory * * @dependsOn clean */ task('build:init', function () { $lib = find()->prune('vfsStream')->discard('vfsStream')->prune('pear')->discard('pear')->prune('data')->discard('data')->prune('doc')->discard('doc')->prune('test')->discard('test')->prune('.*')->discard('.*')->not_name('.*')->ignore_version_control()->in('lib'); // copy source files mkdirs('build/pantr'); mirror($lib, 'build/pantr', pantr::SILENT); mirror(find()->in('src'), 'build/pantr', pantr::SILENT); // and executables mkdirs('build/bin');
public function sync($silent = true) { $pkgs = $this->repo->listAllPackages(); pantr::writeAction('sync', 'PEAR repository'); foreach ($this->channels as $channel => $packages) { // discover channel if it is new if (!isset($pkgs[$channel])) { if ($silent) { pantr::beginSilent('add', 'channel ' . $channel); } $this->repo->discoverChannel($channel); if ($silent) { pantr::endSilent(); } $pkgs[$channel] = array(); } // now check if all packages from this channel are installed foreach ($packages as $pkg => $version) { if (!in_array($pkg, $pkgs[$channel])) { // $channel/$pkg[-$version] if ($silent) { pantr::beginSilent('install', 'package ' . $pkg); } try { $this->repo->install($channel . '/' . $pkg . ($version != '' ? '-' . $version : '')); } catch (\Exception $ex) { pantr::writeln($ex, pantr::WARNING); } if ($silent) { pantr::endSilent(); } $pkgs[$channel][] = $pkg; } } // check if packages are installed that are not specified foreach ($pkgs[$channel] as $pkg) { if (!isset($packages[$pkg])) { if ($silent) { pantr::beginSilent('delete', 'package ' . $pkg); } $this->repo->uninstall($channel . '/' . $pkg); if ($silent) { pantr::endSilent(); } } } } // delete unknown channels foreach ($pkgs as $channel => $packs) { if (!isset($this->channels[$channel])) { pantr::writeln($channel); foreach ($packs as $pkg) { if ($silent) { pantr::beginSilent('delete', 'package ' . $pkg); } $this->repo->uninstall($channel . '/' . $pkg); if ($silent) { pantr::endSilent(); } } if ($silent) { pantr::beginSilent('delete', 'channel ' . $channel); } $this->repo->deleteChannel($channel); if ($silent) { pantr::endSilent(); } } } }
} // load dependency injection container sfServiceContainerAutoloader::register(); if (file_exists(__DIR__ . '/pantr/core/services.php')) { require_once __DIR__ . '/pantr/core/services.php'; $sc = new pantrContainer(); } else { $sc = new sfServiceContainerBuilder(); $loader = new sfServiceContainerLoaderFileYaml($sc); $loader->load(__DIR__ . '/pantr/core/services.yml'); } // drop script name from args $args = $_SERVER['argv']; array_shift($args); // setup pantr pantr::setTaskRepository($sc->taskRepository); pantr::setApplication($sc->application); pantr::setHomePathProvider($sc->homePathProvider); pantr::loadProperties(); // load pantr.yml // load standard tasks include_once __DIR__ . '/pantr/std_tasks.php'; // include bundles $bundleManager = $sc->bundleManager; $bundleManager->registerIncludePath(); $bundleManager->loadBundles(); pantr::setBundleManager($bundleManager); // display pantr info and run it pantr::writeInfo(); pantr::run($args);
public function uploadTree($tree, $stack = array()) { foreach ($tree as $k => $file) { if (is_int($k)) { $lpath = implode('/', $stack) . '/' . $file; $this->ftp->put($file, $lpath); $this->progressBar->incProgress(); pantr::log()->notice('ftp upload ' . $lpath); } else { array_push($stack, $k); $this->ftp->mkdir($k); $this->ftp->cd($k); $this->uploadTree($file, $stack); $this->ftp->cdup(); array_pop($stack); } } }
public function tearDown() { pantr::out()->disableColorizedOutput(false); }
public static function run($testsDirectory, $arguments = array()) { if (is_string($testsDirectory)) { $tests = \pantr\file\fileset('*Spec.php')->in($testsDirectory); } else { $tests = $testsDirectory; } foreach ($tests as $test) { require_once $test; } $isVerbose = isset($arguments['verbose']) && $arguments['verbose']; $taskName = isset($arguments['taskname']) ? $arguments['taskname'] : null; if (!$isVerbose && !is_null($taskName)) { ob_start(); } $result = TextUI\TestRunner::run(self::getTestSuite(), $arguments); if (!$isVerbose && !is_null($taskName)) { $content = ob_get_contents(); ob_end_clean(); if ($result->wasSuccessful()) { pantr::writeAction($taskName, $content); } else { pantr::writeAction($taskName, $content, pantr::WARNING); } } if ($result->wasSuccessful()) { return Task::SUCCESS; } else { return Task::FAILED; } }
/** * Output a formatted message to the user explaining * the current task. $action is the performed task (i.e. "move", "build", "create") * and $desc is the more detailed description ("to some other directory", * "the PEAR channel", "a PEAR package") * * It will also log the action with a Zend_Log::NOTICE priority. * * @return Output */ function writeAction($action, $desc, $style = 'PARAMETER') { pantr::writeAction($action, $desc, $style); }
$sync->sync(); }); theFile($self->peardir . '/pgs')->shouldExist(); $pkgs = $self->repo->listAllPackages(); theValueOf($pkgs['pear.pagosoft.com'])->shouldContain('cli'); }); it('should remove packages', function ($self) { skip(); $sync = new Sync($self->repo); $sync->fromChannel('pear.pagosoft.com'); $pkgs = $self->repo->listAllPackages(); theValueOf($pkgs)->shouldHaveKey('pear.pagosoft.com'); // theValueOf($pkgs['pear.pagosoft.com'])->shouldContain('util'); pantr::silent(function () use($sync) { $sync->sync(); }); theFile($self->peardir . '/pgs')->shouldNotExist(); // $pkgs = $self->repo->listAllPackages(); // theValueOf($pkgs['pear.pagosoft.com'])->shouldNotContain('util'); }); it('should remove channels', function ($self) { $sync = new Sync($self->repo); $channels = $self->repo->listChannels(); the($channels)->shouldContain('pear.pagosoft.com'); pantr::silent(function () use($sync) { $sync->sync(); }); $channels = $self->repo->listChannels(); the($channels)->shouldNotContain('pear.pagosoft.com'); }); });
$task = $tasks[$taskName]; if ($task->getName() == 'help') { $task->desc('Display detailed information for a task'); } $task->printHelp(); } } else { // show summary of all tasks pantr::writeln('Usage:', pantr::SECTION)->write('pantr [options]')->write(' <task> ', pantr::PARAMETER)->writeln('[args]'); Application::printOptions(); pantr::out()->nl()->writeln('Available tasks:', pantr::SECTION); $showGlobalTasks = isset($req['global-tasks']); $tasks = pantr::getDefinedTasks(); $names = array_keys($tasks); sort($names); foreach ($names as $key) { $task = $tasks[$key]; $taskName = $task->getName(); $isGlobalTask = $task->isGlobal(); $showTask = $task->isHidden() == false && $showGlobalTasks == $isGlobalTask; if ($showTask) { if ($task->getName() != $key) { pantr::writeAction($key, 'Alias for [' . $task->getName() . '|INFO]'); } else { pantr::writeAction($key, $task->getDescription()); } } } pantr::out()->nl()->writeln('Help', pantr::SECTION)->write('See ')->write('pantr help ', pantr::COMMENT)->write('<task> ', pantr::PARAMETER)->writeln(' for help with a specific task.'); } });
/** * it should throw an exception when colon is used in property name * @author Patrick Gotthardt * @test * @expectedException InvalidArgumentException */ public function it_should_throw_an_exception_when_colon_is_used_in_property_name() { pantr::property('test:bar', 'foo'); }
use pantr\pantr; // try to load pearfarm $tryLoad = function () { foreach (explode(PATH_SEPARATOR, get_include_path()) as $path) { $dir = $path . DIRECTORY_SEPARATOR . 'pearfarm/src/Pearfarm'; if (file_exists($dir)) { $classes = array('ITask', 'PackageSpec', 'Task' . DIRECTORY_SEPARATOR . 'Push'); foreach ($classes as $class) { require_once $dir . DIRECTORY_SEPARATOR . $class . '.php'; } } } }; $tryLoad(); if (!class_exists('Pearfarm_PackageSpec')) { // try to install it now pantr::silent(function () { $repo = pantr::getRepository(); if (!$repo->hasChannel('pearfarm')) { $repo->discoverChannel('pearfarm.pearfarm.org'); } $repo->install('pearfarm/pearfarm'); $tryLoad(); }); if (!class_exists('Pearfarm_PackageSpec')) { throw new \Exception('Pearfarm is not installed!'); } else { pantr::writeAction('install', 'Pearfarm'); } }