From b5f6caeffb9feac002db40651cd947824813b786 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20L=20F=20S=20Bacci?= Date: Sat, 23 Nov 2024 10:38:06 -0300 Subject: [PATCH 1/3] New utilitary for local language repositories --- languages.php | 304 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 304 insertions(+) create mode 100644 languages.php diff --git a/languages.php b/languages.php new file mode 100644 index 000000000..c066c48c2 --- /dev/null +++ b/languages.php @@ -0,0 +1,304 @@ + | ++------------------------------------------------------------------------------+ +| Description: Creates and maintains manual languages checkouts. | ++------------------------------------------------------------------------------+ +*/ + +// dir manual revcheck cloneUrl label + +lang( "de" , true , true , "git@github.com:php/doc-de.git" , "German" ); +lang( "en" , true , false , "git@github.com:php/doc-en.git" , "English" ); +lang( "es" , true , true , "git@github.com:php/doc-es.git" , "Spanish" ); +lang( "fr" , true , true , "git@github.com:php/doc-fr.git" , "French" ); +lang( "it" , true , true , "git@github.com:php/doc-it.git" , "Italian" ); +lang( "ja" , true , true , "git@github.com:php/doc-ja.git" , "Japanese" ); +lang( "pl" , false , true , "git@github.com:php/doc-pl.git" , "Polish" ); +lang( "pt_BR" , true , true , "git@github.com:php/doc-pt_br.git" , "Brazilian Portuguese" ); +lang( "ro" , false , true , "git@github.com:php/doc-ro.git" , "Romanian" ); +lang( "ru" , true , true , "git@github.com:php/doc-ru.git" , "Russian" ); +lang( "tr" , true , true , "git@github.com:php/doc-tr.git" , "Turkish" ); +lang( "uk" , true , true , "git@github.com:php/doc-uk.git" , "Ukrainian" ); +lang( "zh" , true , true , "git@github.com:php/doc-zh.git" , "Chinese (Simplified)" ); + +if ( count( $argv ) == 1 ) + print_usage(); +else + run(); +return; + +function print_usage() +{ + print <<path = realpath( __DIR__ . '/..' ) . "/{$code}"; + } +} + +function run() +{ + global $argv; + array_shift( $argv ); + foreach( $argv as $arg ) + { + switch( $arg ) + { + case "--clone": Conf::$clone = true; break; + case "--undo": Conf::$undo = true; break; + case "--pull": Conf::$pull = true; break; + case "--mark": Conf::$mark = true; break; + + case "--quiet": Conf::$quiet = "--quiet"; break; + + case "--list-csv": Conf::$listCsv = true; break; + case "--list-ssv": Conf::$listSsv = true; break; + + case "--rev": langAddRev(); break; + case "--all": langAddAll(); break; + default: langAdd( $arg ); break; + } + } + + // Default: languages with build manual flag + + if ( count( Conf::$langs ) == 0 ) + foreach( Conf::$knowLangs as $lang ) + if ( $lang->manual ) + Conf::$langs[ $lang->code ] = $lang; + + // Exclusive listing commands + + if ( Conf::$listCsv || Conf::$listSsv ) + { + $lst = []; + foreach( Conf::$langs as $lang ) + $lst[] = $lang->code; + if ( Conf::$listCsv ) + print implode( ',' , $lst ); + else + print implode( ' ' , $lst ); + exit; + } + + // Composite commands + + echo "Selected languages:"; + foreach( Conf::$langs as $lang ) + echo ' ' . $lang->code; + echo "\n"; + + gitAll(); + dirMark(); +} + +function langAdd( string $langCode ) +{ + foreach( Conf::$knowLangs as $lang ) + { + if ( $lang->code == $langCode ) + { + Conf::$langs[ $lang->code ] = $lang; + return; + } + } + fprintf( STDERR , "Unknown option or langcode: $langCode\n" ); + exit(-1); +} + +function langAddAll() +{ + foreach( Conf::$knowLangs as $lang ) + Conf::$langs[ $lang->code ] = $lang; +} + +function langAddRev() +{ + foreach( Conf::$knowLangs as $lang ) + if ( $lang->revcheck ) + Conf::$langs[ $lang->code ] = $lang; +} + +function gitAll() +{ + foreach( Conf::$langs as $lang ) + { + gitClone( $lang ); + gitUndo ( $lang ); + gitPull ( $lang ); + } +} + +function gitClone( Lang $lang ) +{ + if ( Conf::$clone == false ) + return; + + if ( file_exists( $lang->path ) ) + { + echo "clone {$lang->code} (already exists)\n"; + return; + } + else + echo "clone {$lang->code}\n"; + + $cmd = array( 'git' , 'clone' , Conf::$quiet , $lang->cloneUrl , $lang->path ); + cmdExecute( $cmd ); +} + +function gitUndo( Lang $lang ) +{ + if ( Conf::$undo == false ) + return; + + if ( ! file_exists( $lang->path ) ) + { + echo "undo {$lang->code}: path does not exists, skipping.\n"; + return; + } + else + echo "undo {$lang->code}\n"; + + $cmd = array( 'git' , '-C' , $lang->path , 'reset' , Conf::$quiet ); + cmdExecute( $cmd ); + + $cmd = array( 'git' , '-C' , $lang->path , 'clean' , Conf::$quiet , '-f' , '-d' ); + cmdExecute( $cmd ); + + $cmd = array( 'git' , '-C' , $lang->path , 'checkout' , Conf::$quiet , '.' ); + cmdExecute( $cmd ); +} + +function gitPull( Lang $lang ) +{ + if ( Conf::$pull == false ) + return; + + if ( ! file_exists( $lang->path ) ) + { + echo "pull {$lang->code}: path does not exists, skipping.\n"; + return; + } + else + echo "pull {$lang->code}\n"; + + $cmd = array( 'git' , '-C' , $lang->path , 'pull' , Conf::$quiet ); + cmdExecute( $cmd ); +} + +function cmdExecute( array $parts ) +{ + $escaped = []; + foreach( $parts as $part ) + if ( $part != null ) + $escaped[] = escapeshellarg( $part ); + + $cmd = implode( ' ' , $escaped ); + $rsc = null; + $ret = passthru( $cmd , $rsc ); + + if ( $ret === false || $rsc != 0 ) + { + echo "\nCommand failed, aborting: $cmd\n\n"; + exit(-1); + } +} + +function dirMark() +{ + if ( Conf::$mark == false ) + return; + + // TODO: Check if these markings are ok + + foreach( Conf::$langs as $lang ) + { + // Flag lang dir to build manual or not + + $path = "{$lang->path}/BUILDMAN"; + $text = $lang->label; + + if ( $lang->manual && ! file_exists( $path ) ) + file_put_contents( $path , $text ); + + if ( ! $lang->manual && file_exists( $path ) ) + unlink( $path ); + + // Flag lang dir to generate revcheck or not + + $path = "{$lang->path}/BUILDREV"; + + if ( $lang->revcheck && ! file_exists( $path ) ) + file_put_contents( $path , $text ); + + if ( ! $lang->revcheck && file_exists( $path ) ) + unlink( $path ); + } +} From 27378647223155cfac99e9b17ffe1086024833db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20L=20F=20S=20Bacci?= Date: Mon, 25 Nov 2024 10:06:01 -0300 Subject: [PATCH 2/3] Fix clean -x and dir marks --- languages.php | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/languages.php b/languages.php index c066c48c2..134810c20 100644 --- a/languages.php +++ b/languages.php @@ -48,7 +48,7 @@ function print_usage() Options that operates on local repositories: --clone Clone a sibling language repo, if not exists - --undo Reset, restore and clean up local changes + --undo Restore and clean up repositories to a pristine state --pull Executes git pull --mark Creates/deletes marking files --quiet Set this option on git commands @@ -60,7 +60,7 @@ function print_usage() Options that select more languages to operate: - --rev Include all languages with revcheck flag + --rev Include languages with revcheck flag --all Include all languages @@ -182,7 +182,7 @@ function langAddAll() function langAddRev() { foreach( Conf::$knowLangs as $lang ) - if ( $lang->revcheck ) + if ( $lang->manual || $lang->revcheck ) Conf::$langs[ $lang->code ] = $lang; } @@ -226,13 +226,13 @@ function gitUndo( Lang $lang ) else echo "undo {$lang->code}\n"; - $cmd = array( 'git' , '-C' , $lang->path , 'reset' , Conf::$quiet ); + $cmd = array( 'git' , '-C' , $lang->path , 'restore' , Conf::$quiet , '.' ); cmdExecute( $cmd ); $cmd = array( 'git' , '-C' , $lang->path , 'clean' , Conf::$quiet , '-f' , '-d' ); cmdExecute( $cmd ); - $cmd = array( 'git' , '-C' , $lang->path , 'checkout' , Conf::$quiet , '.' ); + $cmd = array( 'git' , '-C' , $lang->path , 'clean' , '--quiet' , '-fdx' ); cmdExecute( $cmd ); } @@ -276,29 +276,28 @@ function dirMark() if ( Conf::$mark == false ) return; - // TODO: Check if these markings are ok - foreach( Conf::$langs as $lang ) { - // Flag lang dir to build manual or not - - $path = "{$lang->path}/BUILDMAN"; $text = $lang->label; - if ( $lang->manual && ! file_exists( $path ) ) - file_put_contents( $path , $text ); - - if ( ! $lang->manual && file_exists( $path ) ) - unlink( $path ); - - // Flag lang dir to generate revcheck or not + if ( $lang->manual ) // Flags langDir as manual build + { + $path = "{$lang->path}/BUILDMAN"; - $path = "{$lang->path}/BUILDREV"; + if ( $lang->manual && ! file_exists( $path ) ) + file_put_contents( $path , $text ); + if ( ! $lang->manual && file_exists( $path ) ) + unlink( $path ); + } - if ( $lang->revcheck && ! file_exists( $path ) ) - file_put_contents( $path , $text ); + if ( $lang->manual ) // Flags langDir as genrevdb.php + { + $path = "{$lang->path}/BUILDREV"; - if ( ! $lang->revcheck && file_exists( $path ) ) - unlink( $path ); + if ( $lang->revcheck && ! file_exists( $path ) ) + file_put_contents( $path , $text ); + if ( ! $lang->revcheck && file_exists( $path ) ) + unlink( $path ); + } } } From 63a3009071827d2e206c525560aaf5e29c72336d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20L=20F=20S=20Bacci?= Date: Tue, 26 Nov 2024 08:50:28 -0300 Subject: [PATCH 3/3] Include option for doc-base repo --- languages.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/languages.php b/languages.php index 134810c20..a387858a9 100644 --- a/languages.php +++ b/languages.php @@ -62,6 +62,7 @@ function print_usage() --rev Include languages with revcheck flag --all Include all languages + --base Include doc-base repo USAGE; @@ -121,9 +122,11 @@ function run() case "--list-csv": Conf::$listCsv = true; break; case "--list-ssv": Conf::$listSsv = true; break; - case "--rev": langAddRev(); break; - case "--all": langAddAll(); break; - default: langAdd( $arg ); break; + case "--all": langAddAll(); break; + case "--rev": langAddRev(); break; + case "--base": langDocbase(); break; + + default: langAdd( $arg ); break; } } @@ -186,6 +189,13 @@ function langAddRev() Conf::$langs[ $lang->code ] = $lang; } +function langDocbase() +{ + $code = basename( __DIR__ ); + $lang = new Lang( $code , false , false , "" , "" ); + Conf::$langs[ $lang->code ] = $lang; +} + function gitAll() { foreach( Conf::$langs as $lang ) @@ -200,6 +210,8 @@ function gitClone( Lang $lang ) { if ( Conf::$clone == false ) return; + if ( $lang->cloneUrl == "" ) + return; if ( file_exists( $lang->path ) ) {