Changeset 75076 in spip-zone
- Timestamp:
- Aug 29, 2013, 12:28:27 PM (8 years ago)
- Location:
- _galaxie_/code.spip.net/autodoc/trunk
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
_galaxie_/code.spip.net/autodoc/trunk/bin/autodoc_helper.php
r74978 r75076 23 23 $app->command(new autodoc\Helpers\Command\FromSvn()); 24 24 $app->command(new autodoc\Helpers\Command\FromDirectory()); 25 $app->command(new autodoc\Helpers\Command\FromFile()); 25 26 $app->run(); -
_galaxie_/code.spip.net/autodoc/trunk/src/autodoc/Helpers/Command/FromDirectory.php
r75044 r75076 35 35 $directory = $input->getArgument('directory'); 36 36 37 $output->writeln(" Exécuter <info>autodoc</info> avec <info>$directory</info>.");37 $output->writeln("\nExécuter autodoc avec <info>$directory</info>.\n"); 38 38 39 39 $generator = new Generator($input, $output); -
_galaxie_/code.spip.net/autodoc/trunk/src/autodoc/Helpers/Command/FromPlugin.php
r75043 r75076 36 36 $chemin = $input->getArgument('chemin'); 37 37 38 $output->writeln(" Exécuter <info>autodoc</info> sur un plugin de la Zone depuis : <info>$chemin</info>.");38 $output->writeln("\nExécuter autodoc sur un plugin de la Zone depuis : <info>$chemin</info>.\n"); 39 39 40 40 $generator = new Generator($input, $output); -
_galaxie_/code.spip.net/autodoc/trunk/src/autodoc/Helpers/Command/FromSpip.php
r75043 r75076 39 39 $chemin = $input->getArgument('chemin'); 40 40 41 $output->writeln(" Exécuter <info>autodoc</info> sur le Core : <info>$chemin</info>.");41 $output->writeln("\nExécuter autodoc sur le Core : <info>$chemin</info>.\n"); 42 42 43 43 $generator = new Generator($input, $output); -
_galaxie_/code.spip.net/autodoc/trunk/src/autodoc/Helpers/Command/FromSvn.php
r75043 r75076 36 36 $source = $input->getArgument('source'); 37 37 38 $output->writeln(" Exécuter <info>autodoc</info> avec <info>$source</info>.");38 $output->writeln("\nExécuter autodoc avec <info>$source</info>.\n"); 39 39 40 40 $generator = new Generator($input, $output); -
_galaxie_/code.spip.net/autodoc/trunk/src/autodoc/Helpers/Command/FromZone.php
r75043 r75076 36 36 $chemin = $input->getArgument('chemin'); 37 37 38 $output->writeln(" Exécuter <info>autodoc</info> sur la Zone depuis : <info>$chemin</info>.");38 $output->writeln("\nExécuter autodoc sur la Zone depuis : <info>$chemin</info>.\n"); 39 39 40 40 $generator = new Generator($input, $output); -
_galaxie_/code.spip.net/autodoc/trunk/src/autodoc/Helpers/Generator.php
r75043 r75076 131 131 $ok = $ok 132 132 && $this->retrouverInfoPaquetXml() 133 && $this->prepareConfigXml(); 133 && $this->prepareConfigXml() 134 && $this->clearLogs() 135 ; 134 136 135 137 if (!$ok) { … … 142 144 } 143 145 146 147 /** 148 * Générer la documentation à partir d'un fichier listant les documentations à exécuter 149 * 150 * On duplique le fichier chez soi et on gère une rotation de ce fichier à chaque lancement 151 * afin de supprimer les documentations devenues inutiles (disparues du nouveau fichier). 152 * 153 * @param string $file Chemin du fichier ou URL SVN 154 **/ 155 public function generateFromFile($file) { 156 157 // définir les chemins et faire tourner le backup précédent 158 $this->files['autodoc.txt'] = $this->dirs['work'] . '/autodoc.txt'; 159 $this->files['autodoc.txt.bak'] = $this->files['autodoc.txt'] . '.bak'; 160 161 if (file_exists( $this->files['autodoc.txt.bak'] )) { 162 unlink($this->files['autodoc.txt.bak']); 163 } 164 165 if (file_exists( $this->files['autodoc.txt'] )) { 166 copy($this->files['autodoc.txt'], $this->files['autodoc.txt.bak']); 167 unlink($this->files['autodoc.txt']); 168 } 169 170 // copier le fichier de liste chez soi 171 if (0 === strpos($file, 'svn://')) { 172 $this->output->write("* Obtenir <info>$file</info> "); 173 174 // si c'est en svn, on l'exporte simplement. 175 if ($res = $this->makeSvnCommand("export $file autodoc.txt", true, $this->dirs['work'])) { 176 $this->output->writeln("[<info>OK</info>]"); 177 } else { 178 $this->output->writeln("[<info>Error</info>]"); 179 throw new \Exception("Impossible de récupérer le fichier SVN : $file"); 180 } 181 } else { 182 if (file_exists($file)) { 183 copy($file, $this->files['autodoc.txt']); 184 } else { 185 throw new \Exception("Impossible de trouver le fichier : $file"); 186 } 187 } 188 189 $this->output->writeln("\n* Lecture des informations du fichier"); 190 $anciens = $this->parseFile($this->files['autodoc.txt.bak'], false); 191 $presents = $this->parseFile($this->files['autodoc.txt']); 192 193 $output_base = $this->input->getOption('sorties'); 194 if (!$output_base) $output = $this->dirs['work'] . '/output'; 195 196 if ($anciens) { 197 $absents = array_diff_key($anciens, $presents); 198 if ($absents) { 199 $this->output->writeln(" <comment>Certaines documentations ne sont plus à générer.</comment>"); 200 foreach ($absents as $prefixe=>$absent) { 201 $this->output->writeln(" <comment>- Effacement de $prefixe.</comment>"); 202 $this->deleteDirectoryContent($output_base . '/$prefixe', true); 203 $this->deleteDirectoryContent($this->dirs['work'] . 'log/$prefixe', true); 204 $this->deleteDirectoryContent($this->dirs['work'] . 'input/$prefixe', true); 205 $this->deleteDirectoryContent($this->dirs['work'] . 'cache/$prefixe', true); 206 } 207 } 208 } 209 210 foreach ($presents as $prefixe => $present) { 211 212 $this->output->writeln("\n\n"); 213 $this->output->writeln("<comment> Générer la documentation de $prefixe</comment>"); 214 $this->output->writeln("<comment> ------------------------------------------------</comment>"); 215 $this->output->writeln("\n"); 216 217 $ok = $this->createDirectories($prefixe) 218 && $this->getSvnSource($present['source']) 219 && $this->retrouverInfoPaquetXml() 220 && $this->prepareConfigXml() 221 && $this->clearLogs() 222 ; 223 if (!$ok) { 224 $this->output->writeln("<error> * La documentation de $prefixe est ignorée à cause d'une erreur.</error>"); 225 continue; 226 } 227 $this->execute(); 228 } 229 230 $this->output->writeln("\n\n\n <comment>Toutes les documentations ont été générées. Fin.</comment>\n"); 231 } 232 233 234 /** 235 * Analyse un fichier listant les documentations à générer. 236 * 237 * @param string $file Chemin du fichier 238 * @param bool $write_errors Ecrire les erreurs dans la console ? 239 * @return array|bool 240 * - false si echec, 241 * - couples (prefixe => array) sinon. Le tableau de description a les clés suivantes : 242 * - ligne : numéro de ligne 243 * - type : 'svn' 244 * - source : url du svn 245 **/ 246 private function parseFile($file, $write_errors = true) { 247 if (!file_exists($file)) return false; 248 if (!$lines = file($file)) return false; 249 250 $liste = array(); 251 foreach ($lines as $lineno => $line) { 252 if (!$line) continue; 253 $line = trim($line); 254 if (!$line OR $line[0] == '#') continue; 255 $couples = explode(';', $line); 256 $lineno++; 257 if (count($couples) != 2) { 258 if (count($couples) == 1) { 259 $this->output->writeln("<error>Ligne $lineno omise. Le préfixe ne semble pas défini. Contenu : $line</error>"); 260 } else { 261 $this->output->writeln("<error>Ligne $lineno omise. Trop de paramètres indiqués. Contenu : $line</error>"); 262 } 263 continue; 264 } 265 266 list ($url, $prefixe) = $couples; 267 if (!$url) { 268 $this->output->writeln("<error>Ligne $lineno omise. L'URL ne semble pas définie. Contenu : $line</error>"); 269 continue; 270 } 271 if (!$prefixe) { 272 $this->output->writeln("<error>Ligne $lineno omise. Le préfixe ne semble pas défini. Contenu : $line</error>"); 273 continue; 274 } 275 if (isset($liste[$prefixe])) { 276 $this->output->writeln("<error>Ligne $lineno omise. Le prefixe $prefixe est déjà déclaré ligne : " . $liste[$prefixe]['ligne'] . "</error>"); 277 continue; 278 } 279 280 // pas d'erreur ! 281 $liste[$prefixe] = array( 282 'type' => 'svn', 283 'ligne' => $lineno, 284 'source' => $url 285 ); 286 } 287 return $liste; 288 } 289 290 291 /** 292 * Effacer le contenu du répertoire log. 293 * 294 * On ne gardera du coup que les logs de la prochaine exécution. 295 * 296 * @return bool true si réussi 297 **/ 298 private function clearLogs() { 299 return $this->deleteDirectoryContent($this->dirs['log']); 300 } 144 301 145 302 /** … … 174 331 $this->output->writeln("* Vérifier/créer les répertoires de travail dans <info>$_work</info>"); 175 332 333 # si un répertoire pour toutes les sorties est indiqué, forcer son utilisation. 334 if ($this->input->hasOption('sorties') and $dir_output = $this->input->getOption('sorties')) { 335 $this->setOption('dirs/output', $dir_output . "/$prefixe"); 336 } 337 176 338 # si un répertoire de sortie est indiqué, forcer son utilisation. 177 339 if ($this->input->hasOption('sortie') and $dir_output = $this->input->getOption('sortie')) { … … 281 443 * @return mixed|bool false en cas d'erreur 282 444 **/ 283 private function makeSvnCommand($cmd, $no_error = true) { 284 $dir = $this->dirs['input']; 445 private function makeSvnCommand($cmd, $no_error = true, $dir = null) { 446 if (is_null($dir)) { 447 $dir = $this->dirs['input']; 448 } 285 449 $svn = '/usr/bin/svn'; 286 450 $no_error = $no_error ? '2> /dev/null' : '';
Note: See TracChangeset
for help on using the changeset viewer.