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 |
Dominik Riebeling | 091c324 | 2012-05-19 19:12:11 +0200 | [diff] [blame] | 31 | cd rockbox && /usr/bin/git checkout -f |
| 32 | cd rockbox && /usr/bin/git pull |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 33 | END; |
| 34 | foreach(explode("\n", $cmds) as $cmd) { |
| 35 | print("$ ".$cmd."\n"); |
| 36 | list($retval, $stdout, $stderr) = my_exec($cmd); |
| 37 | if ($retval == 0) { print($stdout); } |
| 38 | else { printf("retval: %d\nSTDOUT:\n%s\nSTDERR:\n%s\n--------------------------------------------------\n", $retval, $stdout, $stderr); } |
| 39 | } |
| 40 | |
| 41 | $fp = fopen(VERSIONS, 'w'); |
Jonas Häggqvist | 04e454b | 2010-01-31 01:50:52 +0000 | [diff] [blame] | 42 | foreach(glob('rockbox/apps/lang/*.lang') as $lang) { |
Dominik Riebeling | 091c324 | 2012-05-19 19:12:11 +0200 | [diff] [blame] | 43 | $gitstr = shell_exec(sprintf("git log --pretty=%%h -1 %s", $lang)); |
| 44 | $line = sprintf("%s:%s\n", basename($lang, '.lang'), $gitstr); |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 45 | fwrite($fp, $line); |
| 46 | } |
| 47 | fclose($fp); |
| 48 | return true; |
| 49 | } |
| 50 | |
| 51 | function genstats() { |
| 52 | $langs = array(); |
| 53 | foreach(file(VERSIONS) as $line) { |
| 54 | list($lang, $version) = explode(":", trim($line)); |
| 55 | $langs[$lang] = $version; |
| 56 | } |
| 57 | |
| 58 | $stats = array(); |
| 59 | foreach($langs as $lang => $rev) { |
Jonas Häggqvist | 04e454b | 2010-01-31 01:50:52 +0000 | [diff] [blame] | 60 | $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] | 61 | $output = shell_exec($cmd); |
| 62 | print("$ $cmd\n"); |
| 63 | #printf("%s\n", $output); |
Jonas Häggqvist | 04e454b | 2010-01-31 01:50:52 +0000 | [diff] [blame] | 64 | 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] | 65 | list($lastrev, $lastupdate) = getlastupdated($lang); |
Jonas Häggqvist | 04e454b | 2010-01-31 01:50:52 +0000 | [diff] [blame] | 66 | $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] | 67 | foreach(explode("\n", $output) as $line) { |
| 68 | switch(trim($line)) { |
| 69 | case '### This phrase below was not present in the translated file': |
Jonas Häggqvist | 04e454b | 2010-01-31 01:50:52 +0000 | [diff] [blame] | 70 | $stat['missing']++; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 71 | break; |
| 72 | case '### The <source> section differs from the english!': |
Jonas Häggqvist | 04e454b | 2010-01-31 01:50:52 +0000 | [diff] [blame] | 73 | $stat['source']++; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 74 | break; |
| 75 | case '### The \'desc\' field differs from the english!': |
Jonas Häggqvist | 04e454b | 2010-01-31 01:50:52 +0000 | [diff] [blame] | 76 | $stat['desc']++; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 77 | break; |
| 78 | case '<phrase>': |
Jonas Häggqvist | 04e454b | 2010-01-31 01:50:52 +0000 | [diff] [blame] | 79 | $stat['total']++; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 80 | } |
| 81 | } |
| 82 | $stats[$lang] = $stat; |
| 83 | } |
| 84 | file_put_contents(STATS, serialize($stats)); |
| 85 | return true; |
| 86 | } |
| 87 | |
| 88 | function getlastupdated($lang) { |
| 89 | $retries = 0; |
| 90 | while ($retries < 5) { |
| 91 | try { |
Dominik Riebeling | 091c324 | 2012-05-19 19:12:11 +0200 | [diff] [blame] | 92 | $gitstr = shell_exec(sprintf("cd rockbox && git log --pretty=%%h,%%at -50 apps/lang/%s.lang", $lang)); |
| 93 | $line = sprintf("%s:%s\n", basename($lang, '.lang'), $gitstr); |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 94 | $retries = 100; |
| 95 | } |
| 96 | catch (Exception $e) { |
| 97 | $retries++; |
| 98 | printf("Warning: Caught exception: %s (trying again)<br />\n", $e->getMessage()); |
| 99 | if ($retries > 5) die("Cannot succeed :("); |
| 100 | } |
| 101 | } |
Dominik Riebeling | 091c324 | 2012-05-19 19:12:11 +0200 | [diff] [blame] | 102 | // FIXME: ignorerevs.list / ignorehash.list doesn't work correctly right now. |
| 103 | list($rev, $date) = explode(",", trim($gitstr)); |
| 104 | return array($rev, $date); |
| 105 | //$ignorehash = explode("\n", file_get_contents('ignoredhash.list')); |
| 106 | //foreach(explode('\n', $gitstr) as $logentry) { |
| 107 | // list($rev, $date) = explode(",", trim($gitstr)); |
| 108 | // if(!in_array($rev, $ignorehash)) { |
| 109 | // echo("aaa"); |
| 110 | // return array($rev, $date); |
| 111 | // } |
| 112 | //} |
| 113 | //return array(0, 0); |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | function update_flags() { |
| 117 | $languageinfo = languageinfo(); |
| 118 | |
| 119 | if (!file_exists('flags')) { |
| 120 | mkdir('flags'); |
| 121 | } |
| 122 | foreach (array(SMALL_FLAGSIZE, LARGE_FLAGSIZE) as $size) { |
| 123 | if (!file_exists('flags/'.$size)) { |
| 124 | mkdir('flags/'.$size); |
| 125 | } |
| 126 | foreach($languageinfo as $lang) { |
| 127 | $dest = sprintf("flags/%d/%s.png", $size, $lang['flag']); |
| 128 | if (!file_exists($dest)) { |
| 129 | $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']); |
| 130 | printf("%s \n --> %s\n", $src, $dest); |
| 131 | copy($src, $dest); |
| 132 | sleep(1.5); # Don't be rude |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 138 | update_langs(); |
| 139 | genstats(); |
| 140 | update_flags(); |
| 141 | ?> |