Scripts d'export SVN

Tagged:

Bon le but à terme c'est de faire un truc cohérent qui tienne la route ... Dans l'immédiat je balbutie et je construit !

Mon but: avoir un site web php à qui je dis quel projet je veux exporter, quels tags, version date et hop ... magique j'ai ce qu'il faut où il faut ! (je l'ai toujours dit ça !!!)

Donc c'est brut, ça utilise le ZendFramework mais si vous ne voulez pas, dans l'état c'est facile à modifier !

Un premier fichier de config: (config.php)

$config = array(
	'url' => 'http://10.0.0.2/svn',
	'user' => 'pitilezard',
	'password' => 'password',
	'path' => '/tmp/tests/svn/',
	'svn' => '/usr/local/bin/svn'
);

Oui je suis sous mac, alors ma commande svn est placé n'importe où et surtout pas dans le classpath par défaut... :) (il faut absolument que je modifie ça quand j'ai le temps ...)

Une classe SVN qui va tout faire (qui fait que du checkout basique dans un premier temps) :

class SVN {
 
	private static $config = null;
	
	public static function configure(Zend_Config $cfg) {
		self::$config = $cfg;
	}
	
	public static function checkout($project) {
		$cmd = SVN::getCommand('checkout', $project);
		passthru($cmd, $return);
		echo $return;
	}
	
	private static function getCommand($cmd, $project) {
		SVN::checkPath();
 
		$auth = (isset(self::$config->user) && isset(self::$config->password)) ?
			(' --username '.self::$config->user.' --password '.self::$config->password) : ''; 
 
		return self::$config->svn ." $cmd $auth ". self::$config->url ." ". $project;
	}
	
	private static function checkPath() {
		if (!file_exists(self::$config->path)) 
			if (!mkdir(self::$config->path, 0744, true))
				throw new Exception('Unable to create path ' . self::$config->path);
		chdir(self::$config->path);
	}
 
}

Et ensuite le fichier qui teste tout ça histroire de savoir si ça marche et si on peut continuer :

<html>
	<head>
		<title>exportSVN</title>
	</head>
	<body>
	</body>
	
	<form method="post">
		Project: <input type="text" value="" name="project" /><br />
		<input type="submit" value="checkOut" />
	</form>
	
	<?php
		if (isset($_REQUEST['project'])) {
			require_once('Zend/Config.php');
			require_once('config.php');
			require_once('SVN.php');
			SVN::configure(new Zend_Config($config));
			echo "<pre>";
			SVN::checkout($_REQUEST['project']);
			echo "</pre>";
		}
	?>
</html>

Voila c'est moche et imparfait, mais disons qu'il est tard et que je suis encore loin d'être couché, alors je terminerai tout ça bientot :)