Solomon Peachy | f9bfb08 | 2020-04-01 23:49:51 -0400 | [diff] [blame] | 1 | #!/usr/bin/php -q |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 2 | <?php |
Solomon Peachy | a0eef36 | 2020-04-02 10:05:23 -0400 | [diff] [blame] | 3 | /************************************************************************ |
| 4 | * __________ __ ___. |
| 5 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 6 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 7 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 8 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 9 | * \/ \/ \/ \/ \/ |
| 10 | * Copyright (C) 2010 Jonas Häggqvist |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License |
| 14 | * as published by the Free Software Foundation; either version 2 |
| 15 | * of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | **************************************************************************/ |
Solomon Peachy | f9bfb08 | 2020-04-01 23:49:51 -0400 | [diff] [blame] | 21 | error_reporting(E_ALL); |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 22 | require_once('common.php'); |
Jonas Häggqvist | 9576239 | 2010-01-30 02:15:27 +0000 | [diff] [blame] | 23 | chdir(dirname(__FILE__)); |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 24 | |
| 25 | function my_exec($cmd) { |
| 26 | $descriptorspec = array( |
| 27 | 0 => array("pipe", "r"), |
| 28 | 1 => array("pipe", "w"), |
| 29 | 2 => array("pipe", "w"), |
| 30 | ); |
| 31 | $p = proc_open($cmd, $descriptorspec, $pipes); |
| 32 | if (is_resource($p)) { |
| 33 | $stdout = stream_get_contents($pipes[1]); |
| 34 | $stderr = stream_get_contents($pipes[2]); |
Solomon Peachy | f9bfb08 | 2020-04-01 23:49:51 -0400 | [diff] [blame] | 35 | fclose($pipes[0]); |
| 36 | fclose($pipes[1]); |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 37 | fclose($pipes[2]); |
| 38 | $retval = proc_close($p); |
| 39 | return array($retval, $stdout, $stderr); |
| 40 | } |
| 41 | else { |
| 42 | return false; |
| 43 | } |
| 44 | } |
| 45 | |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 46 | function update_langs() { |
Solomon Peachy | 51b11d5 | 2020-04-13 22:56:53 -0400 | [diff] [blame] | 47 | /* |
Jonas Häggqvist | 04e454b | 2010-01-31 01:50:52 +0000 | [diff] [blame] | 48 | chmod('rockbox/apps/lang', 0777); // Make sure the web server can write temp files |
Solomon Peachy | aaf46a7 | 2020-04-10 11:53:53 -0400 | [diff] [blame] | 49 | |
Solomon Peachy | aaf46a7 | 2020-04-10 11:53:53 -0400 | [diff] [blame] | 50 | // This is no longer needed as we have a cron job doing the git repo update |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 51 | $cmds = <<<END |
Dominik Riebeling | 091c324 | 2012-05-19 19:12:11 +0200 | [diff] [blame] | 52 | cd rockbox && /usr/bin/git checkout -f |
| 53 | cd rockbox && /usr/bin/git pull |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 54 | END; |
| 55 | foreach(explode("\n", $cmds) as $cmd) { |
| 56 | print("$ ".$cmd."\n"); |
| 57 | list($retval, $stdout, $stderr) = my_exec($cmd); |
| 58 | if ($retval == 0) { print($stdout); } |
| 59 | else { printf("retval: %d\nSTDOUT:\n%s\nSTDERR:\n%s\n--------------------------------------------------\n", $retval, $stdout, $stderr); } |
| 60 | } |
Solomon Peachy | aaf46a7 | 2020-04-10 11:53:53 -0400 | [diff] [blame] | 61 | */ |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 62 | $fp = fopen(VERSIONS, 'w'); |
Jonas Häggqvist | 04e454b | 2010-01-31 01:50:52 +0000 | [diff] [blame] | 63 | foreach(glob('rockbox/apps/lang/*.lang') as $lang) { |
Dominik Riebeling | e4164f0 | 2012-05-19 23:59:32 +0200 | [diff] [blame] | 64 | $gitstr = shell_exec(sprintf("cd rockbox && git log --pretty=%%H -1 %s", |
Dominik Riebeling | 609de01 | 2012-05-19 23:20:18 +0200 | [diff] [blame] | 65 | "apps/lang/" . basename($lang))); |
| 66 | $line = sprintf("%s:%s\n", basename($lang, '.lang'), trim($gitstr)); |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 67 | fwrite($fp, $line); |
| 68 | } |
| 69 | fclose($fp); |
| 70 | return true; |
| 71 | } |
| 72 | |
| 73 | function genstats() { |
| 74 | $langs = array(); |
| 75 | foreach(file(VERSIONS) as $line) { |
Solomon Peachy | f9bfb08 | 2020-04-01 23:49:51 -0400 | [diff] [blame] | 76 | list($lang, $version) = explode(":", trim($line)); |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 77 | $langs[$lang] = $version; |
| 78 | } |
Solomon Peachy | f9bfb08 | 2020-04-01 23:49:51 -0400 | [diff] [blame] | 79 | |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 80 | $stats = array(); |
| 81 | foreach($langs as $lang => $rev) { |
Solomon Peachy | b61343c | 2020-07-27 15:59:47 -0400 | [diff] [blame] | 82 | $cmd = sprintf("%s -s rockbox/tools/updatelang rockbox/apps/lang/english.lang rockbox/apps/lang/%s.lang -", PERL, $lang); |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 83 | $output = shell_exec($cmd); |
Solomon Peachy | 9a08942 | 2020-04-14 01:28:29 -0400 | [diff] [blame] | 84 | // print("$ $cmd\n"); |
| 85 | // printf("%s\n", $output); |
Solomon Peachy | 817a336 | 2020-07-27 13:27:53 -0400 | [diff] [blame] | 86 | file_put_contents(sprintf("scratch/%s.lang.update", $lang), $output); |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 87 | list($lastrev, $lastupdate) = getlastupdated($lang); |
Solomon Peachy | b61343c | 2020-07-27 15:59:47 -0400 | [diff] [blame] | 88 | $stat = array('name' => $lang, 'total' => 0, 'missing' => 0, 'desc' => 0, 'source' => 0, 'dest' => 0, 'destdup' => 0, 'voice' => 0, 'voicedup' => 0, 'last_update' => $lastupdate, 'last_update_rev' => $lastrev); |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 89 | foreach(explode("\n", $output) as $line) { |
Solomon Peachy | 645d527 | 2020-07-27 14:57:41 -0400 | [diff] [blame] | 90 | if (preg_match('/### This phrase below was not present in the translated file/', $line) || // DELETEME |
| 91 | preg_match('/### This phrase is missing entirely, copying from english!/', $line)) { |
Jonas Häggqvist | 04e454b | 2010-01-31 01:50:52 +0000 | [diff] [blame] | 92 | $stat['missing']++; |
Solomon Peachy | 645d527 | 2020-07-27 14:57:41 -0400 | [diff] [blame] | 93 | } elseif (preg_match('/### The <source> section differs from the english!/', $line) || // DELETEME |
| 94 | preg_match("/### The <source> section for '.*' is missing! Copying from english!/", $line) || |
| 95 | preg_match("/### The <source> section for '.*' differs from the english!/", $line)) { |
Jonas Häggqvist | 04e454b | 2010-01-31 01:50:52 +0000 | [diff] [blame] | 96 | $stat['source']++; |
Solomon Peachy | 645d527 | 2020-07-27 14:57:41 -0400 | [diff] [blame] | 97 | } elseif (preg_match("/### The 'desc' field differs from the english!/", $line) || // DELETEME |
| 98 | preg_match("/### The 'desc' field for '.*' differs from the english!/", $line) || |
| 99 | preg_match("/### The 'user' field for '.*' differs from the english!/", $line)) { |
Jonas Häggqvist | 04e454b | 2010-01-31 01:50:52 +0000 | [diff] [blame] | 100 | $stat['desc']++; |
Solomon Peachy | 645d527 | 2020-07-27 14:57:41 -0400 | [diff] [blame] | 101 | } elseif (preg_match("/### The <dest> section for '.*' is missing! Copying from english!/", $line) || |
| 102 | preg_match("/### The <dest> section for '.*' is blank! Copying from english!/", $line)) { |
| 103 | $stat['dest']++; |
| 104 | } elseif (preg_match("/### The <dest> section for '.*' is identical to english!/", $line)) { |
Solomon Peachy | b61343c | 2020-07-27 15:59:47 -0400 | [diff] [blame] | 105 | $stat['destdup']++; |
Solomon Peachy | 645d527 | 2020-07-27 14:57:41 -0400 | [diff] [blame] | 106 | } elseif (preg_match("/### The <voice> section for '.*' is missing! Copying from english!/", $line) || |
| 107 | preg_match("/### The <voice> section for '.*' is blank! Copying from english!/", $line)) { |
| 108 | $stat['voice']++; |
| 109 | } elseif (preg_match("/### The <voice> section for '.*' is identical to english!/", $line)) { |
Solomon Peachy | b61343c | 2020-07-27 15:59:47 -0400 | [diff] [blame] | 110 | $stat['voicedup']++; |
Solomon Peachy | 645d527 | 2020-07-27 14:57:41 -0400 | [diff] [blame] | 111 | } elseif (preg_match('/<phrase>/', $line)) { |
Jonas Häggqvist | 04e454b | 2010-01-31 01:50:52 +0000 | [diff] [blame] | 112 | $stat['total']++; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 113 | } |
| 114 | } |
| 115 | $stats[$lang] = $stat; |
| 116 | } |
| 117 | file_put_contents(STATS, serialize($stats)); |
| 118 | return true; |
| 119 | } |
| 120 | |
| 121 | function getlastupdated($lang) { |
| 122 | $retries = 0; |
| 123 | while ($retries < 5) { |
| 124 | try { |
Solomon Peachy | aaf46a7 | 2020-04-10 11:53:53 -0400 | [diff] [blame] | 125 | $gitstr = shell_exec(sprintf("cd rockbox && git log --pretty=%%H,%%ct -50 apps/lang/%s.lang", $lang)); |
Dominik Riebeling | 091c324 | 2012-05-19 19:12:11 +0200 | [diff] [blame] | 126 | $line = sprintf("%s:%s\n", basename($lang, '.lang'), $gitstr); |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 127 | $retries = 100; |
| 128 | } |
| 129 | catch (Exception $e) { |
| 130 | $retries++; |
| 131 | printf("Warning: Caught exception: %s (trying again)<br />\n", $e->getMessage()); |
| 132 | if ($retries > 5) die("Cannot succeed :("); |
| 133 | } |
| 134 | } |
Dominik Riebeling | e99c24f | 2012-05-19 23:48:32 +0200 | [diff] [blame] | 135 | $ignorehash = explode("\n", file_get_contents('ignoredhash.list')); |
| 136 | foreach(preg_split('(\n\r|\r\n|\r|\n)', $gitstr) as $logentry) { |
| 137 | list($rev, $date) = explode(",", trim($logentry)); |
| 138 | if(!in_array($rev, $ignorehash)) { |
| 139 | return array($rev, $date); |
| 140 | } |
| 141 | } |
| 142 | return array(0, 0); |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | function update_flags() { |
| 146 | $languageinfo = languageinfo(); |
Solomon Peachy | f9bfb08 | 2020-04-01 23:49:51 -0400 | [diff] [blame] | 147 | $path = "e/e6"; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 148 | |
| 149 | if (!file_exists('flags')) { |
| 150 | mkdir('flags'); |
| 151 | } |
| 152 | foreach (array(SMALL_FLAGSIZE, LARGE_FLAGSIZE) as $size) { |
| 153 | if (!file_exists('flags/'.$size)) { |
| 154 | mkdir('flags/'.$size); |
| 155 | } |
| 156 | foreach($languageinfo as $lang) { |
| 157 | $dest = sprintf("flags/%d/%s.png", $size, $lang['flag']); |
| 158 | if (!file_exists($dest)) { |
Solomon Peachy | f9bfb08 | 2020-04-01 23:49:51 -0400 | [diff] [blame] | 159 | $src = sprintf('http://upload.wikimedia.org/wikipedia/commons/thumb/%3$s/Flag_of_%2$s.svg/%1$dpx-Flag_of_%2$s.svg.png', $size, $lang['flag'], $path); |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 160 | printf("%s \n --> %s\n", $src, $dest); |
| 161 | copy($src, $dest); |
Solomon Peachy | f9bfb08 | 2020-04-01 23:49:51 -0400 | [diff] [blame] | 162 | sleep(1.0); # Don't be rude |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 163 | } |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 168 | update_langs(); |
| 169 | genstats(); |
| 170 | update_flags(); |
| 171 | ?> |