Pastoid

The page you are looking at now is at this URL: http://pastoid.com/b0d

This paste was last updated on February 22, 2010 at 3:10 pm.

Pasted Coderaw

#!/usr/bin/php
 
<?php
 
	define( 'DS', DIRECTORY_SEPARATOR );
 
	// what path under an extra are we looking for?
	//	this could be 'tags/stable' or any other path relative to the extra's base
	$target_paths = array(
		'%^(?P<version>trunk)%', 
		'%^tags/(?P<version>[\d\.]+-[\d\.]+)%',
	);
 
	// the ABSOLUTE PATH for the destination folder for zip files - NO TRAILING SLASH
	//	zip files will be placed in either /plugins/plugin.zip or /themes/theme.zip under this directory
	//	MAKE SURE THE plugins AND themes DIRECTORIES EXIST UNDER THIS PATH!
	$destination = '/home/habari/public_html/habariproject.org/htdocs/dist';
 
 
	// the ABSOLUTE PATH for the temp folder that we'll use for storing the svn export - NO TRAILING SLASH
	//	MAKE SURE THE plugins AND themes DIRECTORIES EXIST UNDER THIS PATH!
	$export = '/home/habari/public_html/svn.habariproject.org/private/extras-export';
 
	// the URL of the svn repo we'll export from - NO TRAILING SLASH
	$svn = 'http://svn.habariproject.org/habari-extras';
 
 
 
	// the path to the 'svnlook' command
	$svnlook_cmd = '/usr/bin/svnlook';
 
	// the path to the 'svn' command
	$svn_cmd = '/usr/bin/svn';
 
	// the path to the 'zip' command
	$zip_cmd = '/usr/bin/zip';
 
	// the path to the 'rm' command
	$rm_cmd = '/bin/rm';
 
 
 
	if ( count( $argv ) < 3 ) {
		echo 'USAGE: ' . $argv[0] . ' <repo path> <revision>';
		echo "\n\n";
		exit();
	}
 
 
	$repo = $argv[1];
	$revision = $argv[2];
 
	// trim the leading 'r' from revision
	$revision_num = ltrim( $revision, 'r' );
 
	// first, get the list of paths changed
	$changed_paths = shell_exec( $svnlook_cmd . ' changed -r ' . $revision_num . ' ' . $repo );
 
	// split the changed paths into an array
	$paths = explode( "\n", $changed_paths );
 
	// dump any blank entries
	$paths= array_filter( $paths );
 
 	$newpaths = array();
 	foreach($paths as $path) {
 		preg_match('%\s(\S.+)$%', $path, $matches);
 		$dir = $matches[1];
 		if(substr($dir, -1, 1) == DS) {
 			$dir .= 'file';
 		}
 		$newpaths[dirname($dir)] = dirname($dir);
 	}
 	$paths = $newpaths;
 
 	print_r($paths);
 
	// null out our array of extras we care about
	$matches = array();
	$pieces = array();
 
	file_put_contents(dirname(__FILE__) . '/post-commit.log', date('Y-m-d H:i:s') . '  DIST BUILD BEGINS' . "\n", FILE_APPEND);
 
	foreach ( $paths as $path ) {
 
		$pieces = explode( DS, $path );
 
		switch ( $type = array_shift( $pieces ) ) {
 
			case 'plugins':
			case 'themes':
				$extra = array_shift( $pieces );
				break;
 
			default:
				// unsupported type!
				break;
 
		}
 
		// what's left of the path
		$rel_path = implode( DS, $pieces );
 
 		echo "rel_path: {$rel_path}\n";
 		print_r($pieces);
 
		// does this path match our target?
		foreach($target_paths as $target_path) {
 			echo "target_path: {$target_path}\n";
 
			if ( preg_match($target_path, $rel_path, $vmatches) ) {
 
				$name = implode( DS, array( $type, $extra, $extra . '-' . $vmatches['version'] ) );				// ie: plugins/plugin1
				$path = implode( DS, array( $type, $extra, $vmatches[0] ) );		// ie: plugins/plugin1/trunk
 
				// add this extra to the list of ones we care about
				// we don't use it right now, but we might later (ie: for logging)
				$matches[ $name ] = $path;
 
				$svn_dir = $svn . '/' . ltrim( $path, '/' );							// the full URL of the directory we'll export from
 
				$export_dir = $export . DS . $type . DS . $extra;								// the absolute path of the directory we'll export to
				$export_command = $svn_cmd . ' export --force "' . $svn_dir . '" "' . $export_dir . '"';		// the svn command we'll execute
 
				// we go to the trouble of cd'ing so we get a zip with only the extra's dir in it. ie: plugin1/
				$zip_dir = $export . DS . $type;								// the absolute path of the directory we'll cd into before zipping
				$zip_name = $destination . DS . $name . '.zip';							// the absolute path of the zip file we'll create
				$zip_mkdir = 'mkdir -p ' . dirname($zip_name);  // The directory where the zip file will be created
				$zip_command = 'cd "' . $zip_dir . '"; ' . $zip_cmd . ' -9 -r -q "' . $zip_name . '" "' . $extra . '"'; // the zip command we'll execute
 
				$rm_export_command = $rm_cmd . ' -rfd "' . $export_dir . '"';
				$rm_zip_command = $rm_cmd . ' -rfd "' . $zip_name . '"';
 
				// everything we're actually doing
				echo $rm_export_command . "\n";
				echo $rm_zip_command . "\n";
				echo $export_command . "\n";
				echo $zip_mkdir . "\n\n";
				echo $zip_command . "\n\n";
 
 
				// delete everything first
				file_put_contents(dirname(__FILE__) . '/post-commit.log', date('Y-m-d H:i:s') . '   ' . $rm_export_command . "\n", FILE_APPEND);
				$result = shell_exec( $rm_export_command );
				file_put_contents(dirname(__FILE__) . '/post-commit.log', date('Y-m-d H:i:s') . '   ' . $rm_zip_command . "\n", FILE_APPEND);
				$result = shell_exec( $rm_zip_command );
 
				// export it
				file_put_contents(dirname(__FILE__) . '/post-commit.log', date('Y-m-d H:i:s') . '   ' . $export_command . "\n", FILE_APPEND);
				$result = shell_exec( $export_command );
 
				// make sure the zipfile directory exists
				file_put_contents(dirname(__FILE__) . '/post-commit.log', date('Y-m-d H:i:s') . '   ' . $zip_mkdir . "\n", FILE_APPEND);
				$result = shell_exec( $zip_mkdir );
				// zip it up
				file_put_contents(dirname(__FILE__) . '/post-commit.log', date('Y-m-d H:i:s') . '   ' . $zip_command . "\n", FILE_APPEND);
				$result = shell_exec( $zip_command );
 
				// delete export after
				file_put_contents(dirname(__FILE__) . '/post-commit.log', date('Y-m-d H:i:s') . '   ' . $rm_export_command . "\n", FILE_APPEND);
				$result = shell_exec( $rm_export_command );
 
			}
		}
 
	}
	file_put_contents(dirname(__FILE__) . '/post-commit.log', date('Y-m-d H:i:s') . '  END OF DIST' . "\n", FILE_APPEND);
 
 
?>

Toggle wordwrap

Referring DomainHits
Unknown Referer 127
pastoid.com 12
www.google.com 2
Is this paste spam?
<Hide