blob: f7c144f288ca4b4ffac926708eb16e90c31924ad [file] [log] [blame]
Solomon Peachyf9bfb082020-04-01 23:49:51 -04001#!/usr/bin/php -q
Jonas Häggqvistb632ed12010-01-30 02:04:47 +00002<?php
Solomon Peachya0eef362020-04-02 10:05:23 -04003/************************************************************************
4 * __________ __ ___.
5 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
6 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
7 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
8 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * \/ \/ \/ \/ \/
10 * Copyright (C) 2010 Jonas Häggqvist
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 **************************************************************************/
Solomon Peachyf9bfb082020-04-01 23:49:51 -040021error_reporting(E_ALL);
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000022require_once('common.php');
Jonas Häggqvist95762392010-01-30 02:15:27 +000023chdir(dirname(__FILE__));
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000024
25function my_exec($cmd) {
26 $descriptorspec = array(
27 0 => array("pipe", "r"),
28 1 => array("pipe", "w"),
29 2 => array("pipe", "w"),
30 );
31 $p = proc_open($cmd, $descriptorspec, $pipes);
32 if (is_resource($p)) {
33 $stdout = stream_get_contents($pipes[1]);
34 $stderr = stream_get_contents($pipes[2]);
Solomon Peachyf9bfb082020-04-01 23:49:51 -040035 fclose($pipes[0]);
36 fclose($pipes[1]);
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000037 fclose($pipes[2]);
38 $retval = proc_close($p);
39 return array($retval, $stdout, $stderr);
40 }
41 else {
42 return false;
43 }
44}
45
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000046function update_langs() {
Jonas Häggqvist04e454b2010-01-31 01:50:52 +000047 chmod('rockbox/apps/lang', 0777); // Make sure the web server can write temp files
Solomon Peachyaaf46a72020-04-10 11:53:53 -040048
49/*
50 // This is no longer needed as we have a cron job doing the git repo update
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000051 $cmds = <<<END
Dominik Riebeling091c3242012-05-19 19:12:11 +020052cd rockbox && /usr/bin/git checkout -f
53cd rockbox && /usr/bin/git pull
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000054END;
55 foreach(explode("\n", $cmds) as $cmd) {
56 print("$ ".$cmd."\n");
57 list($retval, $stdout, $stderr) = my_exec($cmd);
58 if ($retval == 0) { print($stdout); }
59 else { printf("retval: %d\nSTDOUT:\n%s\nSTDERR:\n%s\n--------------------------------------------------\n", $retval, $stdout, $stderr); }
60 }
Solomon Peachyaaf46a72020-04-10 11:53:53 -040061*/
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000062 $fp = fopen(VERSIONS, 'w');
Jonas Häggqvist04e454b2010-01-31 01:50:52 +000063 foreach(glob('rockbox/apps/lang/*.lang') as $lang) {
Dominik Riebelinge4164f02012-05-19 23:59:32 +020064 $gitstr = shell_exec(sprintf("cd rockbox && git log --pretty=%%H -1 %s",
Dominik Riebeling609de012012-05-19 23:20:18 +020065 "apps/lang/" . basename($lang)));
66 $line = sprintf("%s:%s\n", basename($lang, '.lang'), trim($gitstr));
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000067 fwrite($fp, $line);
68 }
69 fclose($fp);
70 return true;
71}
72
73function genstats() {
74 $langs = array();
75 foreach(file(VERSIONS) as $line) {
Solomon Peachyf9bfb082020-04-01 23:49:51 -040076 list($lang, $version) = explode(":", trim($line));
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000077 $langs[$lang] = $version;
78 }
Solomon Peachyf9bfb082020-04-01 23:49:51 -040079
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000080 $stats = array();
81 foreach($langs as $lang => $rev) {
Jonas Häggqvist04e454b2010-01-31 01:50:52 +000082 $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 +000083 $output = shell_exec($cmd);
84 print("$ $cmd\n");
85 #printf("%s\n", $output);
Jonas Häggqvist04e454b2010-01-31 01:50:52 +000086 file_put_contents(sprintf("rockbox/apps/lang/%s.lang.update", $lang), $output);
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000087 list($lastrev, $lastupdate) = getlastupdated($lang);
Jonas Häggqvist04e454b2010-01-31 01:50:52 +000088 $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 +000089 foreach(explode("\n", $output) as $line) {
90 switch(trim($line)) {
91 case '### This phrase below was not present in the translated file':
Jonas Häggqvist04e454b2010-01-31 01:50:52 +000092 $stat['missing']++;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000093 break;
94 case '### The <source> section differs from the english!':
Jonas Häggqvist04e454b2010-01-31 01:50:52 +000095 $stat['source']++;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000096 break;
97 case '### The \'desc\' field differs from the english!':
Jonas Häggqvist04e454b2010-01-31 01:50:52 +000098 $stat['desc']++;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000099 break;
100 case '<phrase>':
Jonas Häggqvist04e454b2010-01-31 01:50:52 +0000101 $stat['total']++;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +0000102 }
103 }
104 $stats[$lang] = $stat;
105 }
106 file_put_contents(STATS, serialize($stats));
107 return true;
108}
109
110function getlastupdated($lang) {
111 $retries = 0;
112 while ($retries < 5) {
113 try {
Solomon Peachyaaf46a72020-04-10 11:53:53 -0400114 $gitstr = shell_exec(sprintf("cd rockbox && git log --pretty=%%H,%%ct -50 apps/lang/%s.lang", $lang));
Dominik Riebeling091c3242012-05-19 19:12:11 +0200115 $line = sprintf("%s:%s\n", basename($lang, '.lang'), $gitstr);
Jonas Häggqvistb632ed12010-01-30 02:04:47 +0000116 $retries = 100;
117 }
118 catch (Exception $e) {
119 $retries++;
120 printf("Warning: Caught exception: %s (trying again)<br />\n", $e->getMessage());
121 if ($retries > 5) die("Cannot succeed :(");
122 }
123 }
Dominik Riebelinge99c24f2012-05-19 23:48:32 +0200124 $ignorehash = explode("\n", file_get_contents('ignoredhash.list'));
125 foreach(preg_split('(\n\r|\r\n|\r|\n)', $gitstr) as $logentry) {
126 list($rev, $date) = explode(",", trim($logentry));
127 if(!in_array($rev, $ignorehash)) {
128 return array($rev, $date);
129 }
130 }
131 return array(0, 0);
Jonas Häggqvistb632ed12010-01-30 02:04:47 +0000132}
133
134function update_flags() {
135 $languageinfo = languageinfo();
Solomon Peachyf9bfb082020-04-01 23:49:51 -0400136 $path = "e/e6";
Jonas Häggqvistb632ed12010-01-30 02:04:47 +0000137
138 if (!file_exists('flags')) {
139 mkdir('flags');
140 }
141 foreach (array(SMALL_FLAGSIZE, LARGE_FLAGSIZE) as $size) {
142 if (!file_exists('flags/'.$size)) {
143 mkdir('flags/'.$size);
144 }
145 foreach($languageinfo as $lang) {
146 $dest = sprintf("flags/%d/%s.png", $size, $lang['flag']);
147 if (!file_exists($dest)) {
Solomon Peachyf9bfb082020-04-01 23:49:51 -0400148 $src = sprintf('http://upload.wikimedia.org/wikipedia/commons/thumb/%3$s/Flag_of_%2$s.svg/%1$dpx-Flag_of_%2$s.svg.png', $size, $lang['flag'], $path);
Jonas Häggqvistb632ed12010-01-30 02:04:47 +0000149 printf("%s \n --> %s\n", $src, $dest);
150 copy($src, $dest);
Solomon Peachyf9bfb082020-04-01 23:49:51 -0400151 sleep(1.0); # Don't be rude
Jonas Häggqvistb632ed12010-01-30 02:04:47 +0000152 }
153 }
154 }
155}
156
Jonas Häggqvistb632ed12010-01-30 02:04:47 +0000157update_langs();
158genstats();
159update_flags();
160?>