1 | <?php |
---|
2 | |
---|
3 | /* |
---|
4 | This file is part of Salvatore, the translation robot of Trad-lang (SPIP) |
---|
5 | |
---|
6 | Salvatore is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2 of the License, or |
---|
9 | (at your option) any later version. |
---|
10 | |
---|
11 | Trad-Lang is distributed in the hope that it will be useful, |
---|
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | GNU General Public License for more details. |
---|
15 | |
---|
16 | You should have received a copy of the GNU General Public License |
---|
17 | along with Trad-Lang; if not, write to the Free Software |
---|
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
19 | |
---|
20 | Copyright 2003-2013 |
---|
21 | Florent Jugla <florent.jugla@eledo.com>, |
---|
22 | Philippe Riviere <fil@rezo.net>, |
---|
23 | Chryjs <chryjs!@!free!.!fr>, |
---|
24 | kent1 <kent1@arscenic.info> |
---|
25 | */ |
---|
26 | |
---|
27 | // il envoie les fichiers dans le svn |
---|
28 | |
---|
29 | |
---|
30 | require_once(dirname(__FILE__).'/inc_tradlang.php'); |
---|
31 | require_once(_DIR_ETC.'salvatore_passwd.inc'); |
---|
32 | |
---|
33 | if (!isset($SVNUSER) or !isset($SVNPASSWD)) { |
---|
34 | die('Veuillez indiquer $SVNUSER et $SVNPASSWD dans le fichier '._DIR_ETC.'salvatore_passwd.inc'); |
---|
35 | } |
---|
36 | |
---|
37 | $propset = true; |
---|
38 | if (isset($NO_PROPSET)) { |
---|
39 | $propset = false; |
---|
40 | } |
---|
41 | |
---|
42 | $tmp=_SALVATORE_TMP; |
---|
43 | |
---|
44 | /* MAIN ***********************************************************************/ |
---|
45 | |
---|
46 | trad_log("\n=======================================\nPOUSSEUR\nPrend les fichiers langue dans sa copie locale et les commite SVN\n=======================================\n"); |
---|
47 | |
---|
48 | $liste_sources=charger_fichier_traductions(); // chargement du fichier traductions.txt |
---|
49 | |
---|
50 | foreach ($liste_sources as $source) { |
---|
51 | $credentials = false; |
---|
52 | $module = $source[1]; |
---|
53 | trad_log("===== Module $module ======================================\n"); |
---|
54 | |
---|
55 | $domaine_svn = parse_url($source[0]); |
---|
56 | $domaine_svn = $domaine_svn['host']; |
---|
57 | if (isset($domaines_exceptions) and is_array($domaines_exceptions) && in_array($domaine_svn, $domaines_exceptions)) { |
---|
58 | /** |
---|
59 | * On est dans une exception (Github?) |
---|
60 | */ |
---|
61 | if (is_array($domaines_exceptions_credentials) and isset($domaines_exceptions_credentials[$domaine_svn])) { |
---|
62 | $user = $domaines_exceptions_credentials[$domaine_svn]['user']; |
---|
63 | $pass = $domaines_exceptions_credentials[$domaine_svn]['pass']; |
---|
64 | $credentials = true; |
---|
65 | } |
---|
66 | } |
---|
67 | if (isset(${$module.'_user'})) { |
---|
68 | $user = ${$module.'_user'}; |
---|
69 | $pass = ${$module.'_passwd'}; |
---|
70 | } elseif (!$credentials) { |
---|
71 | $user = $SVNUSER; |
---|
72 | $pass = $SVNPASSWD; |
---|
73 | } |
---|
74 | |
---|
75 | $f = _SALVATORE_TMP.$module.'/'; |
---|
76 | |
---|
77 | /** |
---|
78 | * On ajoute les .xml |
---|
79 | */ |
---|
80 | trad_log(exec("svn add --quiet $f*xml 2>/dev/null")."\n"); |
---|
81 | $ignore = array( |
---|
82 | // 'spip','ecrire','public' |
---|
83 | 'couteau','couteauprive','paquet-couteau_suisse'// désactivés suite à scandale, je ne sais pas comment le gérer correctement |
---|
84 | ); |
---|
85 | |
---|
86 | if (in_array($module, $ignore)) { |
---|
87 | trad_log("$module ignore'\n"); |
---|
88 | } else { |
---|
89 | $depot = exec("env LC_MESSAGES=en_US.UTF-8 svn info $f |awk '/^Repository Root/ { print $3 }'").'/'; |
---|
90 | $svn_url = exec("env LC_MESSAGES=en_US.UTF-8 svn info $f |awk '/^URL/ { print $2 }'").'/'; |
---|
91 | $path_svn = str_replace($depot, '', $svn_url); |
---|
92 | $message = $message_commit = $commiteurs = false; |
---|
93 | if (file_exists($f.'message_commit.inc')) { |
---|
94 | $message = true; |
---|
95 | require_once(dirname(__FILE__).'/'.str_replace('./', '', $f).'message_commit.inc'); |
---|
96 | } |
---|
97 | |
---|
98 | if (is_array($commiteurs) && count($commiteurs) > 0) { |
---|
99 | foreach ($commiteurs as $lang => $email) { |
---|
100 | if (strlen($email) > 1) { |
---|
101 | $message_commit_unique = "[Salvatore] [source:$path_svn $module] Export depuis http://trad.spip.net de la langue $lang"; |
---|
102 | /** |
---|
103 | * Si plusieurs commiteurs (veut dire que plusieurs fichiers sont à commiter) |
---|
104 | * ou si le fichier original est modifié, on ne commit que fichier par fichier |
---|
105 | */ |
---|
106 | if (count($commiteurs) > 1 || in_array(substr(exec('svn status '._SALVATORE_TMP.$source[1].'/' . $source[1] . '_' . $source[2] . '.php'), 0, 1), array('A', 'M'))) { |
---|
107 | $path = $f.$module.'_'.$lang.'.php'; |
---|
108 | } else { |
---|
109 | /** |
---|
110 | * Sinon on ne s'embarasse pas, on balance tout avec cet utilisateur |
---|
111 | */ |
---|
112 | $path = $f; |
---|
113 | } |
---|
114 | trad_log("On devrait commiter $path avec comme message '$message_commit_unique' avec l'email $email\n"); |
---|
115 | trad_log(exec("svn commit $path --username $user --password $pass --no-auth-cache --non-interactive --trust-server-cert -m ".escapeshellarg($message_commit_unique))."\n"); |
---|
116 | $revision = exec("svn up $path && env LC_MESSAGES=en_US.UTF-8 svn info $path |awk '/^Last Changed Rev/ { print $4 }'"); |
---|
117 | if ($propset) { |
---|
118 | trad_log(exec("svn propset --revprop -r $revision svn:author '$email' $path --username $user --password $pass --no-auth-cache --non-interactive --trust-server-cert")."\n"); |
---|
119 | trad_log("svn propset --revprop -r $revision svn:author '$email' $path --username $user --password $pass --no-auth-cache --non-interactive --trust-server-cert\n"); |
---|
120 | } |
---|
121 | } |
---|
122 | } |
---|
123 | } |
---|
124 | |
---|
125 | /** |
---|
126 | * Si on a encore un fichier ajouté ou modifié |
---|
127 | * On commite le tout avec salvatore |
---|
128 | */ |
---|
129 | if (strlen(trim(exec("svn status $f |awk /^[MA]/"))) > 1) { |
---|
130 | $commit_message = "[Salvatore] [source:$path_svn $module] Export depuis http://trad.spip.net\n\n"; |
---|
131 | $commit_message .= $message_commit."\n"; |
---|
132 | trad_log("On commit $f car il reste des fichiers\n"); |
---|
133 | trad_log(exec("svn commit $f --username $user --password $pass --no-auth-cache --non-interactive --trust-server-cert -m ".escapeshellarg($commit_message))."\n"); |
---|
134 | $revision_fin = exec("svn up $f && env LC_MESSAGES=en_US.UTF-8 svn info $f |awk '/^Last Changed Rev/ { print $4 }'"); |
---|
135 | if (!$credentials && $propset) { |
---|
136 | trad_log(exec("svn propset --revprop -r $revision_fin svn:author 'salvatore@rezo.net' $f --username $user --password $pass --no-auth-cache --non-interactive --trust-server-cert")."\n"); |
---|
137 | trad_log("svn propset --revprop -r $revision_fin svn:author 'salvatore@rezo.net' $f --username $user --password $pass --no-auth-cache --non-interactive --trust-server-cert\n"); |
---|
138 | } |
---|
139 | } |
---|
140 | |
---|
141 | if (file_exists($f.'message_commit.inc')) { |
---|
142 | unlink($f.'message_commit.inc'); |
---|
143 | } |
---|
144 | } |
---|
145 | } |
---|
146 | |
---|
147 | return 0; |
---|
148 | /* MAIN ***********************************************************************/ |
---|