blob: b1a3aaf709471de52ea1ee117897ff77a9b638ca [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 Riebeling609de012012-05-19 23:20:18 +020043 $gitstr = shell_exec(sprintf("cd rockbox && git log --pretty=%%h -1 %s",
44 "apps/lang/" . basename($lang)));
45 $line = sprintf("%s:%s\n", basename($lang, '.lang'), trim($gitstr));
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000046 fwrite($fp, $line);
47 }
48 fclose($fp);
49 return true;
50}
51
52function genstats() {
53 $langs = array();
54 foreach(file(VERSIONS) as $line) {
55 list($lang, $version) = explode(":", trim($line));
56 $langs[$lang] = $version;
57 }
58
59 $stats = array();
60 foreach($langs as $lang => $rev) {
Jonas Häggqvist04e454b2010-01-31 01:50:52 +000061 $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 +000062 $output = shell_exec($cmd);
63 print("$ $cmd\n");
64 #printf("%s\n", $output);
Jonas Häggqvist04e454b2010-01-31 01:50:52 +000065 file_put_contents(sprintf("rockbox/apps/lang/%s.lang.update", $lang), $output);
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000066 list($lastrev, $lastupdate) = getlastupdated($lang);
Jonas Häggqvist04e454b2010-01-31 01:50:52 +000067 $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 +000068 foreach(explode("\n", $output) as $line) {
69 switch(trim($line)) {
70 case '### This phrase below was not present in the translated file':
Jonas Häggqvist04e454b2010-01-31 01:50:52 +000071 $stat['missing']++;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000072 break;
73 case '### The <source> section differs from the english!':
Jonas Häggqvist04e454b2010-01-31 01:50:52 +000074 $stat['source']++;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000075 break;
76 case '### The \'desc\' field differs from the english!':
Jonas Häggqvist04e454b2010-01-31 01:50:52 +000077 $stat['desc']++;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000078 break;
79 case '<phrase>':
Jonas Häggqvist04e454b2010-01-31 01:50:52 +000080 $stat['total']++;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000081 }
82 }
83 $stats[$lang] = $stat;
84 }
85 file_put_contents(STATS, serialize($stats));
86 return true;
87}
88
89function getlastupdated($lang) {
90 $retries = 0;
91 while ($retries < 5) {
92 try {
Dominik Riebeling091c3242012-05-19 19:12:11 +020093 $gitstr = shell_exec(sprintf("cd rockbox && git log --pretty=%%h,%%at -50 apps/lang/%s.lang", $lang));
94 $line = sprintf("%s:%s\n", basename($lang, '.lang'), $gitstr);
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000095 $retries = 100;
96 }
97 catch (Exception $e) {
98 $retries++;
99 printf("Warning: Caught exception: %s (trying again)<br />\n", $e->getMessage());
100 if ($retries > 5) die("Cannot succeed :(");
101 }
102 }
Dominik Riebeling091c3242012-05-19 19:12:11 +0200103 // FIXME: ignorerevs.list / ignorehash.list doesn't work correctly right now.
104 list($rev, $date) = explode(",", trim($gitstr));
105 return array($rev, $date);
106 //$ignorehash = explode("\n", file_get_contents('ignoredhash.list'));
107 //foreach(explode('\n', $gitstr) as $logentry) {
108 // list($rev, $date) = explode(",", trim($gitstr));
109 // if(!in_array($rev, $ignorehash)) {
110 // echo("aaa");
111 // return array($rev, $date);
112 // }
113 //}
114 //return array(0, 0);
Jonas Häggqvistb632ed12010-01-30 02:04:47 +0000115}
116
117function update_flags() {
118 $languageinfo = languageinfo();
119
120 if (!file_exists('flags')) {
121 mkdir('flags');
122 }
123 foreach (array(SMALL_FLAGSIZE, LARGE_FLAGSIZE) as $size) {
124 if (!file_exists('flags/'.$size)) {
125 mkdir('flags/'.$size);
126 }
127 foreach($languageinfo as $lang) {
128 $dest = sprintf("flags/%d/%s.png", $size, $lang['flag']);
129 if (!file_exists($dest)) {
130 $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']);
131 printf("%s \n --> %s\n", $src, $dest);
132 copy($src, $dest);
133 sleep(1.5); # Don't be rude
134 }
135 }
136 }
137}
138
Jonas Häggqvistb632ed12010-01-30 02:04:47 +0000139update_langs();
140genstats();
141update_flags();
142?>