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() { |
Jonas Häggqvist | 04e454b | 2010-01-31 01:50:52 +0000 | [diff] [blame] | 47 | 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] | 48 | |
| 49 | /* |
| 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) { |
Jonas Häggqvist | 04e454b | 2010-01-31 01:50:52 +0000 | [diff] [blame] | 82 | $cmd = sprintf("%s -s rockbox/tools/genlang -u -e=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); |
| 84 | print("$ $cmd\n"); |
| 85 | #printf("%s\n", $output); |
Jonas Häggqvist | 04e454b | 2010-01-31 01:50:52 +0000 | [diff] [blame] | 86 | file_put_contents(sprintf("rockbox/apps/lang/%s.lang.update", $lang), $output); |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 87 | list($lastrev, $lastupdate) = getlastupdated($lang); |
Jonas Häggqvist | 04e454b | 2010-01-31 01:50:52 +0000 | [diff] [blame] | 88 | $stat = array('name' => $lang, 'total' => 0, 'missing' => 0, 'desc' => 0, 'source' => 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) { |
| 90 | switch(trim($line)) { |
| 91 | case '### This phrase below was not present in the translated file': |
Jonas Häggqvist | 04e454b | 2010-01-31 01:50:52 +0000 | [diff] [blame] | 92 | $stat['missing']++; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 93 | break; |
| 94 | case '### The <source> section differs from the english!': |
Jonas Häggqvist | 04e454b | 2010-01-31 01:50:52 +0000 | [diff] [blame] | 95 | $stat['source']++; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 96 | break; |
| 97 | case '### The \'desc\' field differs from the english!': |
Jonas Häggqvist | 04e454b | 2010-01-31 01:50:52 +0000 | [diff] [blame] | 98 | $stat['desc']++; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 99 | break; |
| 100 | case '<phrase>': |
Jonas Häggqvist | 04e454b | 2010-01-31 01:50:52 +0000 | [diff] [blame] | 101 | $stat['total']++; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | $stats[$lang] = $stat; |
| 105 | } |
| 106 | file_put_contents(STATS, serialize($stats)); |
| 107 | return true; |
| 108 | } |
| 109 | |
| 110 | function getlastupdated($lang) { |
| 111 | $retries = 0; |
| 112 | while ($retries < 5) { |
| 113 | try { |
Solomon Peachy | aaf46a7 | 2020-04-10 11:53:53 -0400 | [diff] [blame] | 114 | $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] | 115 | $line = sprintf("%s:%s\n", basename($lang, '.lang'), $gitstr); |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 116 | $retries = 100; |
| 117 | } |
| 118 | catch (Exception $e) { |
| 119 | $retries++; |
| 120 | printf("Warning: Caught exception: %s (trying again)<br />\n", $e->getMessage()); |
| 121 | if ($retries > 5) die("Cannot succeed :("); |
| 122 | } |
| 123 | } |
Dominik Riebeling | e99c24f | 2012-05-19 23:48:32 +0200 | [diff] [blame] | 124 | $ignorehash = explode("\n", file_get_contents('ignoredhash.list')); |
| 125 | foreach(preg_split('(\n\r|\r\n|\r|\n)', $gitstr) as $logentry) { |
| 126 | list($rev, $date) = explode(",", trim($logentry)); |
| 127 | if(!in_array($rev, $ignorehash)) { |
| 128 | return array($rev, $date); |
| 129 | } |
| 130 | } |
| 131 | return array(0, 0); |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | function update_flags() { |
| 135 | $languageinfo = languageinfo(); |
Solomon Peachy | f9bfb08 | 2020-04-01 23:49:51 -0400 | [diff] [blame] | 136 | $path = "e/e6"; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 137 | |
| 138 | if (!file_exists('flags')) { |
| 139 | mkdir('flags'); |
| 140 | } |
| 141 | foreach (array(SMALL_FLAGSIZE, LARGE_FLAGSIZE) as $size) { |
| 142 | if (!file_exists('flags/'.$size)) { |
| 143 | mkdir('flags/'.$size); |
| 144 | } |
| 145 | foreach($languageinfo as $lang) { |
| 146 | $dest = sprintf("flags/%d/%s.png", $size, $lang['flag']); |
| 147 | if (!file_exists($dest)) { |
Solomon Peachy | f9bfb08 | 2020-04-01 23:49:51 -0400 | [diff] [blame] | 148 | $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] | 149 | printf("%s \n --> %s\n", $src, $dest); |
| 150 | copy($src, $dest); |
Solomon Peachy | f9bfb08 | 2020-04-01 23:49:51 -0400 | [diff] [blame] | 151 | sleep(1.0); # Don't be rude |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 152 | } |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 157 | update_langs(); |
| 158 | genstats(); |
| 159 | update_flags(); |
| 160 | ?> |