blob: 06cbf9dba74674a2661c30915c0d145b735badbd [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
Jonas Häggqvist04e454b2010-01-31 01:50:52 +000031/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äggqvistb632ed12010-01-30 02:04:47 +000035END;
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äggqvist04e454b2010-01-31 01:50:52 +000044 foreach(glob('rockbox/apps/lang/*.lang') as $lang) {
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000045 $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
54function 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äggqvist04e454b2010-01-31 01:50:52 +000063 $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 +000064 $output = shell_exec($cmd);
65 print("$ $cmd\n");
66 #printf("%s\n", $output);
Jonas Häggqvist04e454b2010-01-31 01:50:52 +000067 file_put_contents(sprintf("rockbox/apps/lang/%s.lang.update", $lang), $output);
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000068 list($lastrev, $lastupdate) = getlastupdated($lang);
Jonas Häggqvist04e454b2010-01-31 01:50:52 +000069 $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 +000070 foreach(explode("\n", $output) as $line) {
71 switch(trim($line)) {
72 case '### This phrase below was not present in the translated file':
Jonas Häggqvist04e454b2010-01-31 01:50:52 +000073 $stat['missing']++;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000074 break;
75 case '### The <source> section differs from the english!':
Jonas Häggqvist04e454b2010-01-31 01:50:52 +000076 $stat['source']++;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000077 break;
78 case '### The \'desc\' field differs from the english!':
Jonas Häggqvist04e454b2010-01-31 01:50:52 +000079 $stat['desc']++;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000080 break;
81 case '<phrase>':
Jonas Häggqvist04e454b2010-01-31 01:50:52 +000082 $stat['total']++;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000083 }
84 }
85 $stats[$lang] = $stat;
86 }
87 file_put_contents(STATS, serialize($stats));
88 return true;
89}
90
91function getlastupdated($lang) {
92 $retries = 0;
93 while ($retries < 5) {
94 try {
Jonas Häggqvist04e454b2010-01-31 01:50:52 +000095 $xmlstr = shell_exec(sprintf("svn log --xml rockbox/apps/lang/%s.lang", $lang));
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000096 $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
122function 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äggqvistb632ed12010-01-30 02:04:47 +0000144update_langs();
145genstats();
146update_flags();
147?>