blob: e9b08c653d20dac9992b122fec35a2781489096e [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() {
Solomon Peachy51b11d52020-04-13 22:56:53 -040047/*
Jonas Häggqvist04e454b2010-01-31 01:50:52 +000048 chmod('rockbox/apps/lang', 0777); // Make sure the web server can write temp files
Solomon Peachyaaf46a72020-04-10 11:53:53 -040049
Solomon Peachyaaf46a72020-04-10 11:53:53 -040050 // 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) {
Solomon Peachyb61343c2020-07-27 15:59:47 -040082 $cmd = sprintf("%s -s rockbox/tools/updatelang 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);
Solomon Peachy9a089422020-04-14 01:28:29 -040084// print("$ $cmd\n");
85// printf("%s\n", $output);
Solomon Peachy817a3362020-07-27 13:27:53 -040086 file_put_contents(sprintf("scratch/%s.lang.update", $lang), $output);
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000087 list($lastrev, $lastupdate) = getlastupdated($lang);
Solomon Peachyb61343c2020-07-27 15:59:47 -040088 $stat = array('name' => $lang, 'total' => 0, 'missing' => 0, 'desc' => 0, 'source' => 0, 'dest' => 0, 'destdup' => 0, 'voice' => 0, 'voicedup' => 0, 'last_update' => $lastupdate, 'last_update_rev' => $lastrev);
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000089 foreach(explode("\n", $output) as $line) {
Solomon Peachyeca8c6b2021-09-29 10:18:59 -040090 if (preg_match('/### This phrase below was not present/', $line) || // DELETEME
91 preg_match('/### This phrase is missing entirely/', $line)) {
Jonas Häggqvist04e454b2010-01-31 01:50:52 +000092 $stat['missing']++;
Solomon Peachyeca8c6b2021-09-29 10:18:59 -040093 } elseif (preg_match('/### The <source> section differs/', $line) || // DELETEME
94 preg_match("/### The <source> section for '.*' is missing/", $line) ||
95 preg_match("/### The <source> section for '.*' differs/", $line)) {
Jonas Häggqvist04e454b2010-01-31 01:50:52 +000096 $stat['source']++;
Solomon Peachyeca8c6b2021-09-29 10:18:59 -040097 } elseif (preg_match("/### The 'desc' field differs/", $line) || // DELETEME
98 preg_match("/### The 'desc' field for '.*' differs/", $line) ||
99 preg_match("/### The 'user' field for '.*' differs/", $line)) {
Jonas Häggqvist04e454b2010-01-31 01:50:52 +0000100 $stat['desc']++;
Solomon Peachyeca8c6b2021-09-29 10:18:59 -0400101 } elseif (preg_match("/### The <dest> section for '.*' is missing/", $line) ||
102 preg_match("/### The <dest> section for '.*' is blank/", $line)) {
Solomon Peachy645d5272020-07-27 14:57:41 -0400103 $stat['dest']++;
Solomon Peachyeca8c6b2021-09-29 10:18:59 -0400104 } elseif (preg_match("/### The <dest> section for '.*' is identica/", $line)) {
Solomon Peachyb61343c2020-07-27 15:59:47 -0400105 $stat['destdup']++;
Solomon Peachyeca8c6b2021-09-29 10:18:59 -0400106 } elseif (preg_match("/### The <voice> section for '.*' is missing/", $line) ||
107 preg_match("/### The <voice> section for '.*' is blank/", $line)) {
Solomon Peachy645d5272020-07-27 14:57:41 -0400108 $stat['voice']++;
Solomon Peachyeca8c6b2021-09-29 10:18:59 -0400109 } elseif (preg_match("/### The <voice> section for '.*' is identical/", $line)) {
Solomon Peachyb61343c2020-07-27 15:59:47 -0400110 $stat['voicedup']++;
Solomon Peachy645d5272020-07-27 14:57:41 -0400111 } elseif (preg_match('/<phrase>/', $line)) {
Jonas Häggqvist04e454b2010-01-31 01:50:52 +0000112 $stat['total']++;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +0000113 }
114 }
115 $stats[$lang] = $stat;
116 }
117 file_put_contents(STATS, serialize($stats));
118 return true;
119}
120
121function getlastupdated($lang) {
122 $retries = 0;
123 while ($retries < 5) {
124 try {
Solomon Peachyaaf46a72020-04-10 11:53:53 -0400125 $gitstr = shell_exec(sprintf("cd rockbox && git log --pretty=%%H,%%ct -50 apps/lang/%s.lang", $lang));
Dominik Riebeling091c3242012-05-19 19:12:11 +0200126 $line = sprintf("%s:%s\n", basename($lang, '.lang'), $gitstr);
Jonas Häggqvistb632ed12010-01-30 02:04:47 +0000127 $retries = 100;
128 }
129 catch (Exception $e) {
130 $retries++;
131 printf("Warning: Caught exception: %s (trying again)<br />\n", $e->getMessage());
132 if ($retries > 5) die("Cannot succeed :(");
133 }
134 }
Dominik Riebelinge99c24f2012-05-19 23:48:32 +0200135 $ignorehash = explode("\n", file_get_contents('ignoredhash.list'));
136 foreach(preg_split('(\n\r|\r\n|\r|\n)', $gitstr) as $logentry) {
137 list($rev, $date) = explode(",", trim($logentry));
138 if(!in_array($rev, $ignorehash)) {
139 return array($rev, $date);
140 }
141 }
142 return array(0, 0);
Jonas Häggqvistb632ed12010-01-30 02:04:47 +0000143}
144
145function update_flags() {
146 $languageinfo = languageinfo();
Solomon Peachyf9bfb082020-04-01 23:49:51 -0400147 $path = "e/e6";
Jonas Häggqvistb632ed12010-01-30 02:04:47 +0000148
149 if (!file_exists('flags')) {
150 mkdir('flags');
151 }
152 foreach (array(SMALL_FLAGSIZE, LARGE_FLAGSIZE) as $size) {
153 if (!file_exists('flags/'.$size)) {
154 mkdir('flags/'.$size);
155 }
156 foreach($languageinfo as $lang) {
157 $dest = sprintf("flags/%d/%s.png", $size, $lang['flag']);
158 if (!file_exists($dest)) {
Solomon Peachyf9bfb082020-04-01 23:49:51 -0400159 $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 +0000160 printf("%s \n --> %s\n", $src, $dest);
161 copy($src, $dest);
Solomon Peachyf9bfb082020-04-01 23:49:51 -0400162 sleep(1.0); # Don't be rude
Jonas Häggqvistb632ed12010-01-30 02:04:47 +0000163 }
164 }
165 }
166}
167
Jonas Häggqvistb632ed12010-01-30 02:04:47 +0000168update_langs();
169genstats();
170update_flags();
171?>