Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 1 | #!/usr/bin/php5 -q |
| 2 | <?php |
| 3 | error_reporting(E_ALL); |
| 4 | require_once('common.php'); |
Jonas Häggqvist | 9576239 | 2010-01-30 02:15:27 +0000 | [diff] [blame] | 5 | chdir(dirname(__FILE__)); |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 6 | |
| 7 | function my_exec($cmd) { |
| 8 | $descriptorspec = array( |
| 9 | 0 => array("pipe", "r"), |
| 10 | 1 => array("pipe", "w"), |
| 11 | 2 => array("pipe", "w"), |
| 12 | ); |
| 13 | $p = proc_open($cmd, $descriptorspec, $pipes); |
| 14 | if (is_resource($p)) { |
| 15 | $stdout = stream_get_contents($pipes[1]); |
| 16 | $stderr = stream_get_contents($pipes[2]); |
| 17 | fclose($pipes[0]); |
| 18 | fclose($pipes[1]); |
| 19 | fclose($pipes[2]); |
| 20 | $retval = proc_close($p); |
| 21 | return array($retval, $stdout, $stderr); |
| 22 | } |
| 23 | else { |
| 24 | return false; |
| 25 | } |
| 26 | } |
| 27 | |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 28 | function update_langs() { |
Jonas Häggqvist | 04e454b | 2010-01-31 01:50:52 +0000 | [diff] [blame] | 29 | chmod('rockbox/apps/lang', 0777); // Make sure the web server can write temp files |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 30 | $cmds = <<<END |
Jonas Häggqvist | 04e454b | 2010-01-31 01:50:52 +0000 | [diff] [blame] | 31 | /usr/bin/svn cleanup rockbox/apps/lang |
| 32 | /usr/bin/svn update rockbox/apps/lang |
| 33 | /usr/bin/svn cleanup rockbox/tools/ |
| 34 | /usr/bin/svn update rockbox/tools/genlang |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 35 | END; |
| 36 | foreach(explode("\n", $cmds) as $cmd) { |
| 37 | print("$ ".$cmd."\n"); |
| 38 | list($retval, $stdout, $stderr) = my_exec($cmd); |
| 39 | if ($retval == 0) { print($stdout); } |
| 40 | else { printf("retval: %d\nSTDOUT:\n%s\nSTDERR:\n%s\n--------------------------------------------------\n", $retval, $stdout, $stderr); } |
| 41 | } |
| 42 | |
| 43 | $fp = fopen(VERSIONS, 'w'); |
Jonas Häggqvist | 04e454b | 2010-01-31 01:50:52 +0000 | [diff] [blame] | 44 | foreach(glob('rockbox/apps/lang/*.lang') as $lang) { |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 45 | $xmlstr = shell_exec(sprintf("svn info --xml %s", $lang)); |
| 46 | list($retval, $xml, $stderr) = new SimpleXMLElement($xmlstr); |
| 47 | $line = sprintf("%s:%d\n", basename($lang, '.lang'), $xml->entry->commit->attributes()->revision[0]); |
| 48 | fwrite($fp, $line); |
| 49 | } |
| 50 | fclose($fp); |
| 51 | return true; |
| 52 | } |
| 53 | |
| 54 | function genstats() { |
| 55 | $langs = array(); |
| 56 | foreach(file(VERSIONS) as $line) { |
| 57 | list($lang, $version) = explode(":", trim($line)); |
| 58 | $langs[$lang] = $version; |
| 59 | } |
| 60 | |
| 61 | $stats = array(); |
| 62 | foreach($langs as $lang => $rev) { |
Jonas Häggqvist | 04e454b | 2010-01-31 01:50:52 +0000 | [diff] [blame] | 63 | $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] | 64 | $output = shell_exec($cmd); |
| 65 | print("$ $cmd\n"); |
| 66 | #printf("%s\n", $output); |
Jonas Häggqvist | 04e454b | 2010-01-31 01:50:52 +0000 | [diff] [blame] | 67 | 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] | 68 | list($lastrev, $lastupdate) = getlastupdated($lang); |
Jonas Häggqvist | 04e454b | 2010-01-31 01:50:52 +0000 | [diff] [blame] | 69 | $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] | 70 | foreach(explode("\n", $output) as $line) { |
| 71 | switch(trim($line)) { |
| 72 | case '### This phrase below was not present in the translated file': |
Jonas Häggqvist | 04e454b | 2010-01-31 01:50:52 +0000 | [diff] [blame] | 73 | $stat['missing']++; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 74 | break; |
| 75 | case '### The <source> section differs from the english!': |
Jonas Häggqvist | 04e454b | 2010-01-31 01:50:52 +0000 | [diff] [blame] | 76 | $stat['source']++; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 77 | break; |
| 78 | case '### The \'desc\' field differs from the english!': |
Jonas Häggqvist | 04e454b | 2010-01-31 01:50:52 +0000 | [diff] [blame] | 79 | $stat['desc']++; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 80 | break; |
| 81 | case '<phrase>': |
Jonas Häggqvist | 04e454b | 2010-01-31 01:50:52 +0000 | [diff] [blame] | 82 | $stat['total']++; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 83 | } |
| 84 | } |
| 85 | $stats[$lang] = $stat; |
| 86 | } |
| 87 | file_put_contents(STATS, serialize($stats)); |
| 88 | return true; |
| 89 | } |
| 90 | |
| 91 | function getlastupdated($lang) { |
| 92 | $retries = 0; |
| 93 | while ($retries < 5) { |
| 94 | try { |
Jonas Häggqvist | 04e454b | 2010-01-31 01:50:52 +0000 | [diff] [blame] | 95 | $xmlstr = shell_exec(sprintf("svn log --xml rockbox/apps/lang/%s.lang", $lang)); |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 96 | $xml = new SimpleXMLElement($xmlstr); |
| 97 | $retries = 100; |
| 98 | } |
| 99 | catch (Exception $e) { |
| 100 | $retries++; |
| 101 | printf("Warning: Caught exception: %s (trying again)<br />\n", $e->getMessage()); |
| 102 | if ($retries > 5) die("Cannot succeed :("); |
| 103 | } |
| 104 | } |
| 105 | $ignorerevs = explode("\n", file_get_contents('ignoredrevs.list')); |
| 106 | foreach($xml->logentry as $logentry) { |
| 107 | $rev = (string) $logentry['revision']; |
| 108 | preg_match('@([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})\.[0-9]*(.*)@', $logentry->date, $matches); |
| 109 | $date = mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]); |
| 110 | switch($matches[7]) { |
| 111 | case 'Z': |
| 112 | $date += date("Z", $date); |
| 113 | break; |
| 114 | } |
| 115 | if (!in_array($rev, $ignorerevs)) { |
| 116 | return array($rev, $date); |
| 117 | } |
| 118 | } |
| 119 | return array(0, 0); |
| 120 | } |
| 121 | |
| 122 | function update_flags() { |
| 123 | $languageinfo = languageinfo(); |
| 124 | |
| 125 | if (!file_exists('flags')) { |
| 126 | mkdir('flags'); |
| 127 | } |
| 128 | foreach (array(SMALL_FLAGSIZE, LARGE_FLAGSIZE) as $size) { |
| 129 | if (!file_exists('flags/'.$size)) { |
| 130 | mkdir('flags/'.$size); |
| 131 | } |
| 132 | foreach($languageinfo as $lang) { |
| 133 | $dest = sprintf("flags/%d/%s.png", $size, $lang['flag']); |
| 134 | if (!file_exists($dest)) { |
| 135 | $src = sprintf('http://upload.wikimedia.org/wikipedia/commons/thumb/c/c3/Flag_of_%2$s.svg/%1$dpx-Flag_of_%2$s.svg.png', $size, $lang['flag']); |
| 136 | printf("%s \n --> %s\n", $src, $dest); |
| 137 | copy($src, $dest); |
| 138 | sleep(1.5); # Don't be rude |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 144 | update_langs(); |
| 145 | genstats(); |
| 146 | update_flags(); |
| 147 | ?> |