Nikerabbit has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/344324 )
Change subject: Rewrite repong as symfony application
......................................................................
Rewrite repong as symfony application
I made it so that repong only prints commands in verbose mode (-v)
which is something provided by the framework. This makes the output
even more quiet.
Change-Id: I228a38e3dbcf60b7af2eb96dbda3e693531ef13f
---
M repong/composer.json
M repong/repong.php
2 files changed, 132 insertions(+), 94 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/translatewiki
refs/changes/24/344324/1
diff --git a/repong/composer.json b/repong/composer.json
index 95a7717..2df69d6 100644
--- a/repong/composer.json
+++ b/repong/composer.json
@@ -1,5 +1,6 @@
{
"require": {
+ "symfony/console": "^3.0",
"symfony/process": "^3.0"
}
}
diff --git a/repong/repong.php b/repong/repong.php
index 049d879..94aef24 100644
--- a/repong/repong.php
+++ b/repong/repong.php
@@ -1,32 +1,93 @@
+#!/usr/bin/env php
<?php
+use Symfony\Component\Console\Application;
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Process;
require_once __DIR__ . '/vendor/autoload.php';
-class RepoNg {
+abstract class RepoNgCommand extends Command {
protected $bindir;
- protected $meta;
protected $config;
protected $usernameConversion = [
'nike' => 'nikerabbit',
];
- public function __construct( array $meta, array $config ) {
- $this->bindir = realpath( __DIR__ . '/../bin' );
+ public function initialize() {
+ $base = $this->getBase();
+ if ( !file_exists( "$base/repoconfig.json" ) ) {
+ throw new RuntimeException( 'Cannot find configuration'
);
+ }
+
+ $this->bindir = realpath( __DIR__ . '/../bin' );
if ( $this->bindir === false ) {
throw new RuntimeException( __DIR__ . '/../bin/ does
not exist' );
}
- $this->meta = $meta;
- $this->config = $config;
+ $json = file_get_contents( "$base/repoconfig.json" );
+ $this->config = json_decode( $json, true );
}
- public function update() {
- $base = $this->meta['basepath'];
+ protected function getBase() {
+ $path = getcwd();
+ if ( $path === false ) {
+ return null;
+ }
- foreach ( $this->config['repos'] as $name => $repo ) {
+ while ( true ) {
+ if ( file_exists( "$path/repoconfig.json" ) ) {
+ return $path;
+ }
+
+ if ( $path === realpath( "$path/.." ) ) {
+ return null;
+ }
+
+ $path = realpath( "$path/.." );
+ }
+ }
+
+ protected function getConfig( $project ) {
+ if ( !isset( $this->config[$project] ) ) {
+ echo "Unknown project $project\n";
+ die();
+ }
+
+ return $this->config[$project];
+ }
+
+ protected function buildCommandline( $command, $options ) {
+ $str = $command;
+ foreach ( $options as $key => $value ) {
+ if ( $value !== null ) {
+ $str .= " --$key='$value'";
+ }
+ }
+
+ return $str;
+ }
+}
+
+class UpdateCommand extends RepoNgCommand {
+ protected function configure() {
+ $this->setName( 'update' );
+ $this->setDefinition( [
+ new InputArgument( 'project', InputArgument::REQUIRED ),
+ ] );
+ }
+
+ protected function execute( InputInterface $input, OutputInterface
$output ) {
+ $project = $input->getArgument( 'project' );
+ $config = $this->getConfig( $project );
+ $base = $this->getBase();
+ $bindir = $this->bindir;
+
+ foreach ( $config['repos'] as $name => $repo ) {
$type = $repo['type'];
$branch = isset( $repo['branch'] ) ? $repo['branch'] :
'master';
@@ -39,81 +100,105 @@
$repoUrl = $repo['url'];
$repoUrl = str_replace( 'USERNAME', $userName,
$repoUrl );
- $command = $this->bindir . "/clupdate-git-repo
'$repoUrl' '$base/$name' '$branch'";
+ $command = "$bindir/clupdate-git-repo
'$repoUrl' '$base/$name' '$branch'";
} elseif ( $type === 'github' ) {
- $command = $this->bindir .
"/clupdate-github-repo '{$repo['url']}' '$base/$name' '$branch'";
+ $command = "$bindir/clupdate-github-repo
'{$repo['url']}' '$base/$name' '$branch'";
} elseif ( $type === 'wmgerrit' ) {
- $command = $this->bindir .
"/clupdate-gerrit-repo '{$repo['url']}' '$base/$name' '$branch'";
+ $command = "$bindir/clupdate-gerrit-repo
'{$repo['url']}' '$base/$name' '$branch'";
} else {
throw new RuntimeException( 'Unknown repo type'
);
}
+ $output->writeln( $command,
OutputInterface::VERBOSITY_VERBOSE );
$process = new Process( $command );
$process->setTimeout( 600 );
$process->mustRun();
- print $process->getOutput();
+ $output->write( $process->getOutput() );
}
}
+}
- public function export() {
- $exporter = $this->meta['export'];
+class ExportCommand extends RepoNgCommand {
+ protected function configure() {
+ $this->setName( 'export' );
+ $this->setDefinition( [
+ new InputArgument( 'project', InputArgument::REQUIRED ),
+ ] );
+ }
+
+ protected function execute( InputInterface $input, OutputInterface
$output ) {
+ $project = $input->getArgument( 'project' );
+ $config = $this->getConfig( $project );
+ $exporter = $this->config['@meta']['export'];
$defaultOptions = [
'quiet' => true,
- 'group' => $this->config['group'],
+ 'group' => $config['group'],
'threshold' => 35,
- 'target' => $this->meta['basepath'],
+ 'target' => $this->getBase(),
];
- if ( isset( $this->config['export-hours'] ) ) {
- $defaultOptions['hours'] =
(int)$this->config['export-hours'];
+ if ( isset( $config['export-hours'] ) ) {
+ $defaultOptions['hours'] = (int)$config['export-hours'];
}
- if ( isset( $this->config['no-export-languages'] ) ) {
- $defaultOptions['skip'] =
$this->config['no-export-languages'];
+ if ( isset( $config['no-export-languages'] ) ) {
+ $defaultOptions['skip'] =
$config['no-export-languages'];
}
- if ( isset( $this->config['export-threshold'] ) ) {
- $defaultOptions['threshold'] =
(int)$this->config['export-threshold'];
+ if ( isset( $config['export-threshold'] ) ) {
+ $defaultOptions['threshold'] =
(int)$config['export-threshold'];
}
$jobOptions = [ 'lang' => '*' ] + $defaultOptions + [ 'skip' =>
'en,qqq' ];
$command = $this->buildCommandline( $exporter, $jobOptions );
- echo "$command\n";
+ $output->writeln( $command, OutputInterface::VERBOSITY_VERBOSE
);
$process = new Process( $command );
$process->setTimeout( 300 );
$process->mustRun();
- print $process->getOutput();
+ $output->write( $process->getOutput() );
// Then message documentation
$jobOptions = [ 'lang' => 'qqq', 'threshold' => null ] +
$defaultOptions;
$command = $this->buildCommandline( $exporter, $jobOptions );
- echo "$command\n";
+ $output->writeln( $command, OutputInterface::VERBOSITY_VERBOSE
);
$process = new Process( $command );
$process->mustRun();
- print $process->getOutput();
+ $output->write( $process->getOutput() );
// Last languages that have a forced export
- if ( isset( $this->config['always-export-languages'] ) ) {
- $lang = $this->config['always-export-languages'];
+ if ( isset( $config['always-export-languages'] ) ) {
+ $lang = $config['always-export-languages'];
$jobOptions = [ 'lang' => $lang, 'threshold' => null ]
+ $defaultOptions;
$command = $this->buildCommandline( $exporter,
$jobOptions );
- echo "$command\n";
+ $output->writeln( $command,
OutputInterface::VERBOSITY_VERBOSE );
$process = new Process( $command );
$process->setTimeout( 120 );
$process->mustRun();
- print $process->getOutput();
+ $output->write( $process->getOutput() );
}
+
+ }
+}
+
+class CommitCommand extends RepoNgCommand {
+ protected function configure() {
+ $this->setName( 'commit' );
+ $this->setDefinition( [
+ new InputArgument( 'project', InputArgument::REQUIRED ),
+ ] );
}
- public function commit() {
+ protected function execute( InputInterface $input, OutputInterface
$output ) {
+ $project = $input->getArgument( 'project' );
+ $config = $this->getConfig( $project );
$message = 'Localisation updates from
https://translatewiki.net.';
- $base = $this->meta['basepath'];
+ $base = $this->getBase();
- foreach ( $this->config['repos'] as $name => $repo ) {
+ foreach ( $config['repos'] as $name => $repo ) {
if ( $repo['type'] === 'git' || $repo['type'] ===
'github' ) {
$dir = "$base/$name";
$branch = isset( $repo['branch'] ) ?
$repo['branch'] : 'master';
@@ -128,80 +213,32 @@
} else {
throw new RuntimeException( 'Unknown repo type'
);
}
- echo "$command\n";
+ $output->writeln( $command,
OutputInterface::VERBOSITY_VERBOSE );
$process = new Process( $command );
$process->setTimeout( 120 );
$process->mustRun();
- print $process->getOutput();
+ $output->write( $process->getOutput() );
$autoMerge = isset( $repo['auto-merge'] ) ?
$repo['auto-merge'] : true;
// Merge patch sets submitted to Wikimedia's Gerrit.
if ( $repo['type'] === 'wmgerrit' && $autoMerge ) {
$project = str_replace(
'ssh://[email protected]:29418/', '', $repo['url'] );
- $process = new Process( $this->bindir .
"/merge-wmgerrit-patches '$project'" );
+ $command = $this->bindir .
"/merge-wmgerrit-patches '$project'";
+ $output->writeln( $command,
OutputInterface::VERBOSITY_VERBOSE );
+
+ $process = new Process( $command );
$process->setTimeout( 120 );
$process->mustRun();
- print $process->getOutput();
+ $output->write( $process->getOutput() );
}
}
}
-
- private function buildCommandline( $command, $options ) {
- $str = $command;
- foreach ( $options as $key => $value ) {
- if ( $value !== null ) {
- $str .= " --$key='$value'";
- }
- }
-
- return $str;
- }
}
-function findBase() {
- $path = getcwd();
- if ( $path === false ) {
- return null;
- }
-
- $path;
- while ( true ) {
- if ( file_exists( "$path/repoconfig.json" ) ) {
- return $path;
- }
-
- if ( $path === realpath( "$path/.." ) ) {
- return null;
- }
-
- $path = realpath( "$path/.." );
- }
-}
-
-$command = isset( $argv[1] ) ? $argv[1] : '';
-$project = isset( $argv[2] ) ? $argv[2] : '';
-$base = findBase();
-$json = file_get_contents( "$base/repoconfig.json" );
-$config = json_decode( $json, true );
-
-if ( !isset( $config[$project] ) ) {
- echo "Unknown project $project\n";
- die();
-}
-
-$meta = $config['@meta'];
-$meta['basepath'] = $base;
-
-$ng = new RepoNG( $meta, $config[$project] );
-
-if ( $command === 'update' ) {
- $ng->update();
-} elseif ( $command === 'export' ) {
- $ng->export();
-} elseif ( $command === 'commit' ) {
- $ng->commit();
-} else {
- echo "Insufficient mana\n";
-}
+$application = new Application();
+$application->add( new UpdateCommand() );
+$application->add( new ExportCommand() );
+$application->add( new CommitCommand() );
+$application->run();
--
To view, visit https://gerrit.wikimedia.org/r/344324
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I228a38e3dbcf60b7af2eb96dbda3e693531ef13f
Gerrit-PatchSet: 1
Gerrit-Project: translatewiki
Gerrit-Branch: master
Gerrit-Owner: Nikerabbit <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits