Bläddra i källkod

varios comandos

Luciano Andrade 7 år sedan
förälder
incheckning
f852e3658e

+ 2 - 1
tools/cmd.php

@@ -12,7 +12,8 @@ $app->add(new FD3\GetSource());
 $app->add(new FD3\MergeHostsFile());
 $app->add(new FD3\DockerInventory());
 $app->add(new FD3\ImportClient());
-$app->add(new FD3\Composer());
+$app->add(new FD3\ComposerRequireCommand());
+$app->add(new FD3\RunParallel());
 $app->add(new FD3\Command\ImportONUCommand());
 $app->add(new FD3\Command\MakeVersionCommand());
 $app->add(new FD3\Command\MakeSubversionCommand());

+ 2 - 1
tools/composer.json

@@ -7,7 +7,8 @@
         "magicalex/write-ini-file": "^1.2",
         "rlanvin/php-ip": "1.*",
         "guzzlehttp/guzzle": "~6.0",
-        "maxakawizard/json-collection-parser": "^1.1"
+        "maxakawizard/json-collection-parser": "^1.1",
+        "symfony/process": "^3.3"
     },
     "autoload": {
         "psr-4": {"FD3\\": "src/"}

+ 7 - 7
tools/composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
         "This file is @generated automatically"
     ],
-    "content-hash": "3b81a3fe1e765420e2d6be50c475d093",
+    "content-hash": "52432d198963f9524bd649450874e31a",
     "packages": [
         {
             "name": "clue/stream-filter",
@@ -1884,20 +1884,20 @@
         },
         {
             "name": "symfony/process",
-            "version": "v3.3.6",
+            "version": "v3.3.13",
             "source": {
                 "type": "git",
                 "url": "https://github.com/symfony/process.git",
-                "reference": "07432804942b9f6dd7b7377faf9920af5f95d70a"
+                "reference": "a56a3989fb762d7b19a0cf8e7693ee99a6ffb78d"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/symfony/process/zipball/07432804942b9f6dd7b7377faf9920af5f95d70a",
-                "reference": "07432804942b9f6dd7b7377faf9920af5f95d70a",
+                "url": "https://api.github.com/repos/symfony/process/zipball/a56a3989fb762d7b19a0cf8e7693ee99a6ffb78d",
+                "reference": "a56a3989fb762d7b19a0cf8e7693ee99a6ffb78d",
                 "shasum": ""
             },
             "require": {
-                "php": ">=5.5.9"
+                "php": "^5.5.9|>=7.0.8"
             },
             "type": "library",
             "extra": {
@@ -1929,7 +1929,7 @@
             ],
             "description": "Symfony Process Component",
             "homepage": "https://symfony.com",
-            "time": "2017-07-13T13:05:09+00:00"
+            "time": "2017-11-13T15:31:11+00:00"
         },
         {
             "name": "symfony/property-access",

BIN
tools/src/.GetSource.php.swp


+ 4 - 4
tools/src/Composer.php

@@ -8,18 +8,18 @@ use Symfony\Component\Console\Input\InputArgument;
 use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Output\OutputInterface;
 
-class Composer extends Command{
+class ComposerRequireCommand extends Command{
     protected function configure()
     {
         $this 
-        ->setName('composer:use')
+        ->setName('composer:require')
 
         ->setDescription('Tag all composer software using a ini file.')
 
         ->setHelp('This command allows you to tag and change the required code on the composer.json file...')
 
 	 ->addArgument('ini_file', InputArgument::REQUIRED, 'The ini file from where to get the source code config.')
-	 ->addArgument('packages', InputArgument::REQUIRED, 'tag the required packages')
+	 ->addArgument('packages', InputArgument::REQUIRED, 'tag the required packages (suggested value : ik/*)')
 	 ->addArgument('version', InputArgument::REQUIRED, 'use the version expression.')
     ;
     }
@@ -43,7 +43,7 @@ class Composer extends Command{
 			foreach(array("require", "require-dev") as $k){
 				foreach($composer_data[$k] as $package => $version){
 					if(strpos($packages, "*") !== false){
-						$preg = "|". str_replace("*", "[^\b]*", $packages) . "|";
+						$preg = "|^". str_replace("*", "[^\b]*", $packages) . "$|";
 						if(preg_match($preg, $package)){
 							$composer_data[$k][$package] = (string)$new_version; 
 							$output->writeln("\t". $package . " = ". $new_version);

+ 18 - 8
tools/src/GetSource.php

@@ -25,7 +25,8 @@ class GetSource extends Command
         ->addArgument('ini_file', InputArgument::REQUIRED, 'The ini file from where to get the source code config.')
         ->addOption('remote-name', null, InputOption::VALUE_REQUIRED, 'Rename the remote to this name.', "upstream")
         ->addOption('push', null, InputOption::VALUE_NONE, 'Push to the remote.')
-        ->addOption('timeout', null, InputOption::VALUE_OPTIONAL, 'Git process timeout in seconds', 60)
+        ->addOption('timeout', null, InputOption::VALUE_OPTIONAL, 'Git process timeout in seconds', 10)
+        ->addOption('branch', null, InputOption::VALUE_OPTIONAL, 'get a diferente branch from the specified on the ini-file', "")
         ;
     }
 
@@ -46,15 +47,15 @@ class GetSource extends Command
             $git_path = $dirname.'/'.$sec;
             $url = $conf["url"];
             // Verifico si tiene ssh como protocolo y si la url es de gogs
-            $protocol = 'ssh://';
-            if (substr($url, 0, strlen($protocol)) !== $protocol && strpos($url, 'gogs.infra.flowdat.com') !== false) {
+	    $url_info = parse_url($url);
+	    if(isset($url_info["host"]) and (!isset($url_info["scheme"]) or empty($url_info["scheme"]))){
+                $protocol = 'ssh://';
                 $url = $protocol . $url;
             }
             try {
                 $output->writeln($url . " -> " . $git_path);
                 $git->clone($url, $git_path);
-            } catch (GitException $e) {
-                throw $e;
+            } catch (GitException $e){
                 $output->write("repo $sec exists \n");
             }
             $git->setRepository($git_path);
@@ -64,9 +65,18 @@ class GetSource extends Command
             } catch (GitException $e) {
             }
             $git->remote->add($input->getOption("remote-name"), $url);
-            $git->fetch($input->getOption("remote-name"));
-
-            $git->checkout($conf["branch"]);
+	    try {
+		    $git->fetch($input->getOption("remote-name"));
+	    } catch( GitException $e) {
+		$output->writeln("<error>".$e->getMessage()."</error>");
+            }
+	    $branch_from_options = $input->getOption("branch");
+	    if(!empty($branch_from_options)){
+		    $git->checkout($branch_from_options);
+		    $conf["branch"] = $branch_from_options;
+	    }else{
+		    $git->checkout($conf["branch"]);
+	    }
             $branches = $git->branch(array("all" => false,"remotes" => true));
 
     		if(isset($branches["remotes/" . $input->getOption("remote-name") . "/" . $conf["branch"]])){

+ 60 - 0
tools/src/RunParallel.php

@@ -0,0 +1,60 @@
+<?php
+
+namespace FD3;
+
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Process\Process;
+use Symfony\Component\Process\Exception\ProcessFailedException;
+
+class RunParallel extends Command{
+    protected function configure()
+    {
+        $this 
+        ->setName('run:parallel')
+
+        ->setDescription('Run in parallel from the directory of the repo using a ini file.')
+
+        ->setHelp('This command allows you to tag and change the required code on the composer.json file...')
+
+	 ->addArgument('ini_file', InputArgument::REQUIRED, 'The ini file from where to get the source code config.')
+	 ->addArgument('cmd', InputArgument::REQUIRED, 'the command to run in parallel')
+    ;
+    }
+    protected function execute(InputInterface $input, OutputInterface $output)
+    {
+	$file = $input->getArgument("ini_file");
+	$initial_dir = getcwd();
+	$realpath = realpath($file);
+	$dirname = dirname($realpath);
+	if(!chdir($dirname)){
+		throw new \Exception("Can't change working directory to ".$dirname);
+	}
+	
+	$content = parse_ini_file($realpath, true);
+	$command = $input->getArgument("cmd");
+	$p_list = array();
+	foreach($content as $sec => $conf){
+		chdir($dirname ."/".$sec);
+		$output->writeln($sec . "-> ". $command);
+		$process = new Process($command);
+		//$process->setTimeout(600);
+		//$process->setIdleTimeout(6);
+		$p_list[$sec] = $process;
+		$process->start();
+
+	}
+
+	foreach($content as $sec => $conf){
+		$process = $p_list[$sec];
+		$process->wait();
+		$output->writeln("<info>". $sec . "</info>");
+		$output->write($process->getOutput() . "\n");
+        }
+
+	chdir($initial_dir);
+    }
+}