Pastoid

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

This paste was last updated on July 9, 2009 at 3:07 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_path = 'trunk';
 
	// 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 . ' dirs-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 );
 
 
	// 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 );
 
		// does this path match our target?
		if ( substr( $rel_path, 0, strlen( $target_path ) ) == $target_path ) {
 
			$name = implode( DS, array( $type, $extra ) );				// ie: plugins/plugin1
			$path = implode( DS, array( $type, $extra, $target_path ) );		// 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 . $name;								// 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_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_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 );
 
			// 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 );
 
		}
 
	}
	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 4
Is this paste spam?
<Hide