コード例 #1
0
/**
 * @param $commands
 * @param \Symfony\Component\Console\Output\ConsoleOutput $output
 *
 * @return boolean
 */
function execute_commands($commands, $output)
{
    foreach ($commands as $command) {
        list($command, $message, $allowFailure) = $command;
        $output->write(sprintf(' - %\'.-70s', $message));
        $return = array();
        if (is_callable($command)) {
            $success = $command($output);
        } else {
            $p = new \Symfony\Component\Process\Process($command);
            $p->setTimeout(null);
            $p->run(function ($type, $data) use(&$return) {
                $return[] = $data;
            });
            $success = $p->isSuccessful();
        }
        if (!$success && !$allowFailure) {
            $output->writeln('<error>KO</error>');
            $output->writeln(sprintf('<error>Fail to run: %s</error>', is_callable($command) ? '[closure]' : $command));
            foreach ($return as $data) {
                $output->write($data, false, OutputInterface::OUTPUT_RAW);
            }
            $output->writeln("If the error is coming from the sandbox,");
            $output->writeln("please report the issue to https://github.com/sonata-project/sandbox/issues");
            return false;
        } else {
            if (!$success) {
                $output->writeln("<info>!!</info>");
            } else {
                $output->writeln("<info>OK</info>");
            }
        }
    }
    return true;
}
コード例 #2
0
 public static function run($pluginsInitCode, Kwf_SourceMaps_SourceMap $sourcemap)
 {
     $js = "\n            require('es6-promise').polyfill(); //required for older nodejs\n            var postcss = require('postcss');\n            var plugins = [];\n            " . $pluginsInitCode . "\n            var instance = postcss( plugins );\n            var css = '';\n            process.stdin.setEncoding('utf-8')\n            process.stdin.on('data', function(buf) { css += buf.toString(); });\n            process.stdin.on('end', function() {\n                instance.process(css).then(function (result) {\n                    process.stdout.write(result.css);\n                }).catch(function(e) {\n                    console.log(e);\n                    process.exit(1);\n                });\n            });\n            process.stdin.resume();\n        ";
     $runfile = tempnam("temp/", 'postcss');
     file_put_contents($runfile, $js);
     putenv("NODE_PATH=" . getcwd() . "/node_modules" . PATH_SEPARATOR . getcwd() . "/" . KWF_PATH . PATH_SEPARATOR . getcwd() . "/");
     $cmd = getcwd() . "/" . VENDOR_PATH . "/bin/node " . $runfile;
     $cmd .= " 2>&1";
     $process = new Symfony\Component\Process\Process($cmd);
     $mapData = $sourcemap->getMapContentsData(false);
     $hasSourcemap = !!$mapData->mappings;
     if ($hasSourcemap) {
         $process->setInput($sourcemap->getFileContentsInlineMap(false));
     } else {
         $process->setInput($sourcemap->getFileContents());
     }
     if ($process->run() !== 0) {
         throw new Kwf_Exception("Process '{$cmd}' failed with " . $process->getExitCode() . "\n" . $process->getOutput());
     }
     putenv("NODE_PATH=");
     unlink($runfile);
     $out = $process->getOutput();
     if (Kwf_SourceMaps_SourceMap::hasInline($out)) {
         $ret = Kwf_SourceMaps_SourceMap::createFromInline($out);
     } else {
         $ret = Kwf_SourceMaps_SourceMap::createEmptyMap($out);
         $ret->setMimeType('text/css');
     }
     $ret->setSources($sourcemap->getSources());
     return $ret;
 }
コード例 #3
0
ファイル: FetchJob.php プロジェクト: antons-/deploynaut
 public function perform()
 {
     set_time_limit(0);
     $log = new DeploynautLogFile($this->args['logfile']);
     $projects = DNProject::get()->filter('Name', Convert::raw2sql($this->args['projectName']));
     $project = $projects->first();
     $path = $project->getLocalCVSPath();
     $env = $this->args['env'];
     $log->write('Starting git fetch for project "' . $project->Name . '"');
     // if an alternate user has been configured for clone, run the command as that user
     // @todo Gitonomy doesn't seem to have any way to prefix the command properly, if you
     // set 'sudo -u composer git' as the "command" parameter, it tries to run the whole
     // thing as a single command and fails
     $user = DNData::inst()->getGitUser();
     if (!empty($user)) {
         $command = sprintf('cd %s && sudo -u %s git fetch -p origin +refs/heads/*:refs/heads/* --tags', $path, $user);
         $process = new \Symfony\Component\Process\Process($command);
         $process->setEnv($env);
         $process->setTimeout(3600);
         $process->run();
         if (!$process->isSuccessful()) {
             throw new RuntimeException($process->getErrorOutput());
         }
     } else {
         $repository = new Gitonomy\Git\Repository($path, array('environment_variables' => $env));
         $repository->run('fetch', array('-p', 'origin', '+refs/heads/*:refs/heads/*', '--tags'));
     }
     $log->write('Git fetch is finished');
 }
コード例 #4
0
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     $tmpDir = __DIR__ . '/tmp';
     if (defined('PHP_WINDOWS_VERSION_BUILD')) {
         $command = 'rmdir /q /s ' . escapeshellarg($tmpDir);
     } else {
         $command = 'rmdir -Rf ' . escapeshellarg($tmpDir);
     }
     $process = new \Symfony\Component\Process\Process($command);
     $process->run();
     if (!is_dir($tmpDir)) {
         mkdir($tmpDir);
     }
     self::$tmpDir = $tmpDir . '/exiftool_reader';
     if (!is_dir(self::$tmpDir)) {
         mkdir(self::$tmpDir);
     }
     copy(__DIR__ . '/../../../files/ExifTool.jpg', self::$tmpDir . '/test2.jpg');
     copy(__DIR__ . '/../../../files/ExifTool.jpg', self::$tmpDir . '/test.jpg');
     if (!is_dir(self::$tmpDir . '/dir')) {
         mkdir(self::$tmpDir . '/dir');
     }
     if (!is_dir(self::$tmpDir . '/usr')) {
         mkdir(self::$tmpDir . '/usr');
     }
     $tmpDir2 = $tmpDir . '/exiftool_reader2';
     if (!is_dir($tmpDir2)) {
         mkdir($tmpDir2);
     }
     copy(__DIR__ . '/../../../files/ExifTool.jpg', $tmpDir2 . '/test2.jpg');
     if (defined('PHP_WINDOWS_VERSION_BUILD')) {
         self::$disableSymLinkTest = true;
     } elseif (!is_link(self::$tmpDir . '/symlink')) {
         if (!@symlink($tmpDir2, self::$tmpDir . '/symlink')) {
             self::$disableSymLinkTest = true;
         }
     }
     copy(__DIR__ . '/../../../files/plop/CanonRaw.cr2', self::$tmpDir . '/dir/CanonRaw.cr2');
     $tmpDir3 = $tmpDir . '/exiftool_reader3';
     if (!is_dir($tmpDir3)) {
         mkdir($tmpDir3);
     }
     if (!is_dir($tmpDir3 . '/.svn')) {
         mkdir($tmpDir3 . '/.svn');
     }
     if (!is_dir($tmpDir3 . '/.roro')) {
         mkdir($tmpDir3 . '/.roro');
     }
     if (!is_dir($tmpDir3 . '/.git')) {
         mkdir($tmpDir3 . '/.git');
     }
     touch($tmpDir3 . '/.git/config');
     touch($tmpDir3 . '/.roro/.roro.tmp');
     copy(__DIR__ . '/../../../files/ExifTool.jpg', $tmpDir3 . '/.exiftool.jpg');
 }
コード例 #5
0
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     $tmpDir = __DIR__ . '/tmp';
     if (defined('PHP_WINDOWS_VERSION_BUILD')) {
         $command = 'rmdir /q /s ' . escapeshellarg($tmpDir);
     } else {
         $command = 'rmdir -Rf ' . escapeshellarg($tmpDir);
     }
     $process = new \Symfony\Component\Process\Process($command);
     $process->run();
     if (!is_dir($tmpDir)) {
         mkdir($tmpDir);
     }
     self::$tmpDir = $tmpDir . '/exiftool_reader';
     if (!is_dir(self::$tmpDir)) {
         mkdir(self::$tmpDir);
     }
     file_put_contents(self::$tmpDir . '/hello.world', 'Hello');
     file_put_contents(self::$tmpDir . '/hello.exiftool', 'Hello');
     if (!is_dir(self::$tmpDir . '/dir')) {
         mkdir(self::$tmpDir . '/dir');
     }
     if (!is_dir(self::$tmpDir . '/usr')) {
         mkdir(self::$tmpDir . '/usr');
     }
     $tmpDir2 = $tmpDir . '/exiftool_reader2';
     if (!is_dir($tmpDir2)) {
         mkdir($tmpDir2);
     }
     file_put_contents($tmpDir2 . '/hello2.world', 'Hello');
     if (defined('PHP_WINDOWS_VERSION_BUILD')) {
         self::$disableSymLinkTest = true;
     } elseif (!is_link(self::$tmpDir . '/symlink')) {
         if (!@symlink($tmpDir2, self::$tmpDir . '/symlink')) {
             self::$disableSymLinkTest = true;
         }
     }
     file_put_contents(self::$tmpDir . '/dir/newfile.txt', 'Hello');
     $tmpDir3 = $tmpDir . '/exiftool_reader3';
     if (!is_dir($tmpDir3)) {
         mkdir($tmpDir3);
     }
     if (!is_dir($tmpDir3 . '/.svn')) {
         mkdir($tmpDir3 . '/.svn');
     }
     if (!is_dir($tmpDir3 . '/.roro')) {
         mkdir($tmpDir3 . '/.roro');
     }
     if (!is_dir($tmpDir3 . '/.git')) {
         mkdir($tmpDir3 . '/.git');
     }
     touch($tmpDir3 . '/.git/config');
     touch($tmpDir3 . '/.roro/.roro.tmp');
     touch($tmpDir3 . '/.phrasea.xml');
 }
コード例 #6
0
ファイル: load_data.php プロジェクト: karousn/sandbox
/**
 * @param $commands
 * @param \Symfony\Component\Console\Output\ConsoleOutput $output
 * @return void
 */
function execute_commands($commands, $output)
{
    foreach ($commands as $command) {
        $output->writeln(sprintf('<info>Executing : </info> %s', $command));
        $p = new \Symfony\Component\Process\Process($command);
        $exit = $p->run(function ($type, $data) use($output) {
            $output->write($data);
        });
        $output->writeln("");
    }
}
コード例 #7
0
ファイル: ForeachCommand.php プロジェクト: totten/git-scan
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!$input->getOption('command')) {
         $output->writeln("<error>Missing required option: --command</error>");
         return 1;
     }
     $statusCode = 0;
     if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
         $output->writeln("<info>[[ Finding repositories ]]</info>");
     }
     $scanner = new \GitScan\GitRepoScanner();
     $gitRepos = $scanner->scan($input->getArgument('path'));
     foreach ($gitRepos as $gitRepo) {
         /** @var \GitScan\GitRepo $gitRepo */
         if (!$gitRepo->matchesStatus($input->getOption('status'))) {
             continue;
         }
         $topLevel = $this->fs->findFirstParent($gitRepo->getPath(), $input->getArgument('path'));
         if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
             $output->writeln("<info>[[ {$gitRepo->getPath()} ]]</info>");
         }
         $process = new \Symfony\Component\Process\Process($input->getOption('command'));
         $process->setWorkingDirectory($gitRepo->getPath());
         // $process->setEnv(...); sucks in Debian/Ubuntu
         putenv("path=" . $this->fs->makePathRelative($gitRepo->getPath(), $topLevel));
         putenv("toplevel=" . $topLevel);
         $errorOutput = $output;
         if (is_callable($output, 'getErrorOutput') && $output->getErrorOutput()) {
             $errorOutput = $output->getErrorOutput();
         }
         $process->run(function ($type, $buffer) use($output, $errorOutput) {
             if (\Symfony\Component\Process\Process::ERR === $type) {
                 if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
                     $errorOutput->write("<error>STDERR</error> ");
                 }
                 $errorOutput->write($buffer, FALSE, OutputInterface::OUTPUT_RAW);
             } else {
                 if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
                     $output->write("<comment>STDOUT</comment> ");
                 }
                 $output->write($buffer, FALSE, OutputInterface::OUTPUT_RAW);
             }
         });
         if (!$process->isSuccessful()) {
             $errorOutput->writeln("<error>[[ {$gitRepo->getPath()}: exit code = {$process->getExitCode()} ]]</error>");
             $statusCode = 2;
         }
     }
     putenv("path");
     putenv("toplevel");
     return $statusCode;
 }
コード例 #8
0
ファイル: CloneGitRepo.php プロジェクト: antons-/deploynaut
 public function perform()
 {
     set_time_limit(0);
     $path = $this->args['path'];
     $repo = $this->args['repo'];
     $env = $this->args['env'];
     $logfile = DEPLOYNAUT_LOG_PATH . '/clonegitrepo.log';
     $fh = fopen($logfile, 'a');
     if (!$fh) {
         throw new RuntimeException(sprintf('Can\'t open file "%s" for logging.', $logfile));
     }
     // if an alternate user has been configured for clone, run the command as that user
     $user = DNData::inst()->getGitUser();
     if (file_exists($path)) {
         $command = array();
         if (!empty($user)) {
             $command[] = sprintf('sudo -u %s', $user);
         }
         $command[] = sprintf('rm -rf %s', $path);
         fwrite($fh, sprintf('[%s] Cleaning up existing repository %s', date('Y-m-d H:i:s'), $path) . PHP_EOL);
         fwrite($fh, sprintf('[%s] Running command: %s', date('Y-m-d H:i:s'), implode(' ', $command)) . PHP_EOL);
         $process = new \Symfony\Component\Process\Process(implode(' ', $command));
         $process->setEnv($env);
         $process->setTimeout(3600);
         $process->run();
         if (!$process->isSuccessful()) {
             fwrite($fh, sprintf('[%s] Error cleaning up existing repository: %s', date('Y-m-d H:i:s'), $process->getErrorOutput()) . PHP_EOL);
             throw new RuntimeException($process->getErrorOutput());
         }
     }
     fwrite($fh, sprintf('[%s] Cloning repository %s to %s', date('Y-m-d H:i:s'), $repo, $path) . PHP_EOL);
     echo "[-] CloneGitRepo starting" . PHP_EOL;
     $command = array();
     if (!empty($user)) {
         $command[] = sprintf('sudo -u %s', $user);
     }
     $command[] = sprintf('git clone --bare -q %s %s', $repo, $path);
     fwrite($fh, sprintf('[%s] Running command: %s', date('Y-m-d H:i:s'), implode(' ', $command)) . PHP_EOL);
     $process = new \Symfony\Component\Process\Process(implode(' ', $command));
     $process->setEnv($env);
     $process->setTimeout(3600);
     $process->run();
     if (!$process->isSuccessful()) {
         fwrite($fh, sprintf('[%s] Error cloning repository %s to %s: %s', date('Y-m-d H:i:s'), $repo, $path, $process->getErrorOutput()) . PHP_EOL);
         throw new RuntimeException($process->getErrorOutput());
     }
     fwrite($fh, sprintf('[%s] Successfully cloned repository %s to %s', date('Y-m-d H:i:s'), $repo, $path) . PHP_EOL);
 }
コード例 #9
0
ファイル: load_data.php プロジェクト: awesemo/cms-sandbox
/**
 * @param $commands
 * @param \Symfony\Component\Console\Output\ConsoleOutput $output
 *
 * @return boolean
 */
function execute_commands($commands, $output)
{
    foreach ($commands as $command) {
        $output->writeln(sprintf('<info>Executing : </info> %s', $command));
        $p = new \Symfony\Component\Process\Process($command);
        $p->setTimeout(null);
        $p->run(function ($type, $data) use($output) {
            $output->write($data);
        });
        if (!$p->isSuccessful()) {
            return false;
        }
        $output->writeln("");
    }
    return true;
}
コード例 #10
0
 /**
  * 编译脚本(字符串格式), 返回编译后的命令数组
  * @param $script
  */
 public static function complie($script, $siteId)
 {
     $s = new \Symfony\Component\Process\Process('sdf');
     $s->run();
     $realScript = self::twigVar($script, $siteId);
     $commandList = self::commandInit();
     $lines = explode("\n", $realScript);
     //去除空行
     $scriptLines = array();
     foreach ($lines as $line) {
         $line = trim($line);
         if (empty($line)) {
             continue;
         }
         $scriptLines[] = $line;
     }
     $startPattern = '/^@(after|before):(remote|local|handle)$/i';
     $len = count($scriptLines);
     for ($psl = 0; $psl < $len;) {
         while ($psl < $len && $scriptLines[$psl][0] != '@') {
             $psl++;
         }
         if ($psl >= $len) {
             break;
         }
         if (preg_match($startPattern, $scriptLines[$psl], $matchs)) {
             $order = $matchs[1];
             $position = $matchs[2];
             $psl++;
             while ($psl < $len && $scriptLines[$psl][0] != '@') {
                 $commandList[$order][$position][] = $scriptLines[$psl];
                 $psl++;
             }
         } else {
             throw new Exception('complie error at : ' . $scriptLines[$psl]);
         }
     }
     return $commandList;
 }
コード例 #11
0
ファイル: CloneGitRepo.php プロジェクト: ss23/deploynaut
 public function perform()
 {
     set_time_limit(0);
     $path = $this->args['path'];
     $repo = $this->args['repo'];
     $env = $this->args['env'];
     $logfile = DEPLOYNAUT_LOG_PATH . '/clonegitrepo.log';
     $fh = fopen($logfile, 'a');
     if (!$fh) {
         throw new RuntimeException('Can\'t open file "' . $logfile . '" for logging.');
     }
     // if an alternate user has been configured for clone, run the command as that user
     $user = DNData::inst()->getGitUser();
     if (file_exists($path)) {
         if ($user) {
             exec(sprintf('sudo -u %s rm -rf %s', $user, $path));
         } else {
             exec(sprintf('rm -rf %s', $path));
         }
     }
     fwrite($fh, '[' . date('Y-m-d H:i:s') . '] Cloning ' . $repo . ' to ' . $path . PHP_EOL);
     echo "[-] CloneGitRepo starting" . PHP_EOL;
     // using git clone straight via system call since doing it via the
     // Gitonomy\Git\Admin times out. Silly.
     if ($user) {
         $command = sprintf('sudo -u %s git clone --bare -q %s %s', $user, $repo, $path);
     } else {
         $command = sprintf('git clone --bare -q %s %s', $repo, $path);
     }
     fwrite($fh, '[' . date('Y-m-d H:i:s') . '] Running command: ' . $command . PHP_EOL);
     $process = new \Symfony\Component\Process\Process($command);
     $process->setEnv($env);
     $process->setTimeout(3600);
     $process->run();
     if (!$process->isSuccessful()) {
         throw new RuntimeException($process->getErrorOutput());
     }
     fwrite($fh, '[' . date('Y-m-d H:i:s') . '] Cloned ' . $repo . ' to ' . $path . PHP_EOL);
 }
コード例 #12
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $cfg = $this->getServices()->get('blogCfg');
     $workdir = $cfg->get('blog.workdir', getcwd() . '/workdir');
     if (is_dir($workdir)) {
         throw new \RuntimeException("Blog already initialized");
     }
     $repodir = $workdir;
     $repoUrl = $cfg->get('blog.repository');
     if (!$repoUrl) {
         throw new \RuntimeException("Missing blog.repository configuration.");
     }
     $output->writeln(sprintf("Clonning repository %s into workdir ...", $repoUrl));
     $cmd = sprintf("git clone %s %s", $repoUrl, $repodir);
     $proc = new \Symfony\Component\Process\Process($cmd);
     $proc->setTimeout(null);
     $proc->run(function ($type, $buffer) use($output) {
         $output->write('<comment>' . $buffer . '</comment>');
     });
     if (!$proc->isSuccessful()) {
         throw new \RuntimeException('Git process failed.');
     }
     $output->writeln("<info>Blog is ready.</info>");
 }
コード例 #13
0
 /**
  * Run a shell command.
  *
  * @param string $command The command to run
  * @param string|null $workingDir The working dir to run command in
  * @throws RuntimeException
  */
 protected function runCommand($command, $workingDir = null)
 {
     if (!empty($this->user)) {
         $command = sprintf('sudo -u %s %s', $this->user, $command);
     }
     if ($this->log) {
         $this->log->write(sprintf('Running command: %s', $command));
     }
     $process = new \Symfony\Component\Process\Process($command, $workingDir);
     $process->setEnv($this->project->getProcessEnv());
     $process->setTimeout(1800);
     $process->run();
     if (!$process->isSuccessful()) {
         throw new RuntimeException($process->getErrorOutput());
     }
 }
 protected function compileWithCommand($bin, $source, $target)
 {
     $sourceFilePath = trim(Director::getAbsFile($source));
     $targetFilePath = trim(Director::getAbsFile($target));
     $command = $bin . " " . escapeshellarg($sourceFilePath);
     $process = new \Symfony\Component\Process\Process($command);
     $process->run();
     if ($process->isSuccessful()) {
         $css = $process->getOutput();
         if (!file_exists(dirname($targetFilePath))) {
             mkdir(dirname($targetFilePath), null, true);
         }
         file_put_contents($targetFilePath, $css);
         $this->filesCacheAdd($source);
         $this->log[] = ["compiled {$source} to {$target}", 'info'];
     } else {
         $message = $process->getErrorOutput();
         if ($process->getExitCode() != 1 || !$message) {
             $message = "\"{$command}\": non-zero exit code {$process->getExitCode()} '{$process->getExitCodeText()}'. (Output: '{$message}')";
         }
         $this->log[] = ["failed to compile {$source} with {$bin}: {$message}", 'error'];
         SS_Log::log(new Exception($message), SS_Log::ERR);
     }
 }
コード例 #15
0
 /**
  * @param string      $command
  * @param bool        $async
  * @param string|null $cwd
  *
  * @return \Symfony\Component\Process\Process
  */
 private static function _runProcess($command, $async = false, $cwd = null)
 {
     $process = new \Symfony\Component\Process\Process($command, $cwd);
     self::_log(sprintf('Running command: %s', $command));
     if ($async) {
         $process->start();
         sleep(1);
         if (!$process->isRunning()) {
             throw new RuntimeException(sprintf('Failed to start %s: %s', $command, $process->getErrorOutput()));
         }
     } else {
         $process->run();
         if (!$process->isSuccessful()) {
             throw new RuntimeException(sprintf('Failed to run %s: %s', $command, $process->getErrorOutput()));
         }
     }
     return $process;
 }
コード例 #16
0
ファイル: AdminSite.php プロジェクト: tomaka17/niysu
 /**
  * @url /git/git-pull
  * @method POST
  */
 public function gitPull($redirectionOutput)
 {
     $dir = dirname(dirname(dirname(dirname(dirname(dirname(__DIR__))))));
     $process = new \Symfony\Component\Process\Process('git pull', $dir);
     $process->setTimeout(60);
     $process->run();
     $redirectOutput->setLocationToRoute(get_class() . '::gitPanel');
 }
コード例 #17
0
ファイル: Mission.php プロジェクト: u0mo5/php_crontab
 /**
  * start mission process
  */
 public function run()
 {
     $out = $this->out;
     $err = $this->err;
     $process = new \Symfony\Component\Process\Process($this->cmd);
     $process->run(function ($type, $buffer) use($out, $err) {
         if ($type == \Symfony\Component\Process\Process::ERR) {
             $err->error($buffer);
         } else {
             $out->info($buffer);
         }
     });
 }
コード例 #18
0
ファイル: update.php プロジェクト: justnx/deployer.org
        $data = json_decode($payload, true);
        $payloadHash = hash_hmac($algo, $payload, $secret);
        if ($hash === $payloadHash) {
            $request->attributes->set('payload', $data);
        } else {
            return new Response('Payload hash does not match hub signature.', Response::HTTP_FORBIDDEN);
        }
    }
}, Silex\Application::EARLY_EVENT);
// Auto update deployer.phar on GitHub WebHook.
$controller->post('update/deployer', function (Request $request) use($app) {
    $event = $request->headers->get('X-Github-Event');
    $payload = $request->attributes->get('payload');
    if ($event === 'create' && $payload['ref_type'] === 'tag') {
        file_put_contents($app['schedule'], "update:deployer\n", FILE_APPEND);
        return new Response('Schedule task to update deployer created.', Response::HTTP_OK, ['Content-Type' => 'text/plain']);
    }
    return new Response('', Response::HTTP_FORBIDDEN, ['Content-Type' => 'text/plain']);
});
// Auto update docs on GitHub WebHook.
$controller->post('update/{what}', function (Request $request, $what) use($app) {
    $event = $request->headers->get('X-Github-Event');
    $payload = $request->attributes->get('payload');
    if ($event === 'pull_request' && $payload['action'] === 'closed' && $payload['pull_request']['merged'] || $event === 'push') {
        $process = new \Symfony\Component\Process\Process('php ' . $app['cli'] . ' update:' . $what);
        $process->run();
        return new Response("Update `{$what}` successfully.\n\n" . $process->getOutput(), Response::HTTP_OK, ['Content-Type' => 'text/plain']);
    }
    return new Response("The `{$what}` was not updated.", Response::HTTP_OK, ['Content-Type' => 'text/plain']);
})->assert('what', '(documentation)|(recipes)');
return $controller;
コード例 #19
0
ファイル: behat.php プロジェクト: alfred-nutile-inc/setup
 */
$yml = new Symfony\Component\Yaml\Yaml();
$tests = $yml->parse(__DIR__ . '/../behat.yml');
$run = [];
$env = getenv('APP_ENV');
foreach ($tests as $key => $test) {
    if (strpos($key, $env) !== false) {
        $run[] = $key;
    }
}
$failing_test = [];
foreach ($run as $test) {
    $command = "bin/behat --stop-on-failure --no-paths --tags='@api,~@wip' --profile={$test}";
    $run = new \Symfony\Component\Process\Process($command);
    $run->setTimeout(600);
    $run->run(function ($type, $buffer) use($failing_test, $test) {
        if (Symfony\Component\Process\Process::ERR === $type) {
            $failing_test[] = $test;
            //throw new \Exception(sprintf("Test Failed %s", $buffer));
        } else {
            echo $buffer;
        }
    });
    if ($run->getExitCode() != 0) {
        $failing_test[] = $test;
    }
}
if (count($failing_test)) {
    $message = print_r($failing_test, 1);
    throw new \Exception(sprintf("Tests Failed the behat profiles are %s", $message));
}
コード例 #20
0
ファイル: CreateCommand.php プロジェクト: langeland/Bazinga
 private function getSystemGroups()
 {
     $process = new \Symfony\Component\Process\Process('cat /etc/group | cut -d: -f1');
     $process->run();
     foreach (explode("\n", $process->getOutput()) as $line) {
         if ($line != '' && substr($line, 0, 1) != '#') {
             $groups[] = $line;
         }
     }
     return $groups;
 }
コード例 #21
0
ファイル: functions.php プロジェクト: onedal88/deployer
/**
 * Execute commands on local machine.
 * @param string $command Command to run locally.
 * @param int $timeout (optional) Override process command timeout in seconds.
 * @return Result Output of command.
 * @throws \RuntimeException
 */
function runLocally($command, $timeout = 60)
{
    $command = env()->parse($command);
    if (isVeryVerbose()) {
        writeln("<comment>Run locally</comment>: {$command}");
    }
    $process = new Symfony\Component\Process\Process($command);
    $process->setTimeout($timeout);
    $process->run(function ($type, $buffer) {
        if (isDebug()) {
            if ('err' === $type) {
                write("<fg=red>></fg=red> {$buffer}");
            } else {
                write("<fg=green>></fg=green> {$buffer}");
            }
        }
    });
    if (!$process->isSuccessful()) {
        throw new \RuntimeException($process->getErrorOutput());
    }
    return new Result($process->getOutput());
}
コード例 #22
0
ファイル: Controller.php プロジェクト: urbanindo/yii2-queue
 /**
  * Run the queue fetching process.
  * @param string  $command The command.
  * @param string  $cwd     The working directory.
  * @param integer $timeout The timeout.
  * @param array   $env     The environment to be passed.
  * @return void
  */
 protected function runQueueFetching($command, $cwd = null, $timeout = null, array $env = [])
 {
     $process = new \Symfony\Component\Process\Process($command, isset($cwd) ? $cwd : getcwd(), $env, null, $timeout);
     $process->setTimeout($timeout);
     $process->setIdleTimeout(null);
     $process->run();
     if ($process->isSuccessful()) {
         //TODO logging.
         $this->stdout($process->getOutput() . PHP_EOL);
         $this->stdout($process->getErrorOutput() . PHP_EOL);
     } else {
         //TODO logging.
         $this->stdout($process->getOutput() . PHP_EOL);
         $this->stdout($process->getErrorOutput() . PHP_EOL);
     }
 }