blob: 2bf13e88d1231c488106a482797b8f5b637f43c4 [file] [log] [blame]
Jonas Häggqvistb632ed12010-01-30 02:04:47 +00001#!/usr/bin/php5 -q
2<?php
3error_reporting(E_ALL);
4require_once('common.php');
Jonas Häggqvist95762392010-01-30 02:15:27 +00005chdir(dirname(__FILE__));
Jonas Häggqvistb632ed12010-01-30 02:04:47 +00006
7function 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äggqvistb632ed12010-01-30 02:04:47 +000028function update_langs() {
Jonas Häggqvist04e454b2010-01-31 01:50:52 +000029 chmod('rockbox/apps/lang', 0777); // Make sure the web server can write temp files
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000030 $cmds = <<<END
Dominik Riebeling091c3242012-05-19 19:12:11 +020031cd rockbox && /usr/bin/git checkout -f
32cd rockbox && /usr/bin/git pull
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000033END;
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äggqvist04e454b2010-01-31 01:50:52 +000042 foreach(glob('rockbox/apps/lang/*.lang') as $lang) {
Dominik Riebeling091c3242012-05-19 19:12:11 +020043 $gitstr = shell_exec(sprintf("git log --pretty=%%h -1 %s", $lang));
44 $line = sprintf("%s:%s\n", basename($lang, '.lang'), $gitstr);
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000045 fwrite($fp, $line);
46 }
47 fclose($fp);
48 return true;
49}
50
51function 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äggqvist04e454b2010-01-31 01:50:52 +000060 $cmd = sprintf("%s -s rockbox/tools/genlang -u -e=rockbox/apps/lang/english.lang rockbox/apps/lang/%s.lang", PERL, $lang);
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000061 $output = shell_exec($cmd);
62 print("$ $cmd\n");
63 #printf("%s\n", $output);
Jonas Häggqvist04e454b2010-01-31 01:50:52 +000064 file_put_contents(sprintf("rockbox/apps/lang/%s.lang.update", $lang), $output);
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000065 list($lastrev, $lastupdate) = getlastupdated($lang);
Jonas Häggqvist04e454b2010-01-31 01:50:52 +000066 $stat = array('name' => $lang, 'total' => 0, 'missing' => 0, 'desc' => 0, 'source' => 0, 'last_update' => $lastupdate, 'last_update_rev' => $lastrev);
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000067 foreach(explode("\n", $output) as $line) {
68 switch(trim($line)) {
69 case '### This phrase below was not present in the translated file':
Jonas Häggqvist04e454b2010-01-31 01:50:52 +000070 $stat['missing']++;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000071 break;
72 case '### The <source> section differs from the english!':
Jonas Häggqvist04e454b2010-01-31 01:50:52 +000073 $stat['source']++;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000074 break;
75 case '### The \'desc\' field differs from the english!':
Jonas Häggqvist04e454b2010-01-31 01:50:52 +000076 $stat['desc']++;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000077 break;
78 case '<phrase>':
Jonas Häggqvist04e454b2010-01-31 01:50:52 +000079 $stat['total']++;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000080 }
81 }
82 $stats[$lang] = $stat;
83 }
84 file_put_contents(STATS, serialize($stats));
85 return true;
86}
87
88function getlastupdated($lang) {
89 $retries = 0;
90 while ($retries < 5) {
91 try {
Dominik Riebeling091c3242012-05-19 19:12:11 +020092 $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äggqvistb632ed12010-01-30 02:04:47 +000094 $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 Riebeling091c3242012-05-19 19:12:11 +0200102 // 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äggqvistb632ed12010-01-30 02:04:47 +0000114}
115
116function 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äggqvistb632ed12010-01-30 02:04:47 +0000138update_langs();
139genstats();
140update_flags();
141?>