[Mapbender-commits] r3063 - in trunk/build: . checksum

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Oct 1 03:35:45 EDT 2008


Author: christoph
Date: 2008-10-01 03:35:44 -0400 (Wed, 01 Oct 2008)
New Revision: 3063

Added:
   trunk/build/1_createMySqlDump.php
   trunk/build/2_convertDataDumps.php
   trunk/build/3_addHeaderToDataDumps.php
   trunk/build/checksum/
   trunk/build/checksum/build-checksum.php
   trunk/build/checksum/checksum-utils.inc
   trunk/build/checksum/commandLine.inc
   trunk/build/commandLine.inc
   trunk/build/test_utf8.sed
Log:


Added: trunk/build/1_createMySqlDump.php
===================================================================
--- trunk/build/1_createMySqlDump.php	                        (rev 0)
+++ trunk/build/1_createMySqlDump.php	2008-10-01 07:35:44 UTC (rev 3063)
@@ -0,0 +1,65 @@
+<?php
+	require_once(dirname(__FILE__) . "/commandLine.inc");
+	
+	$mpbnFolder = $_SERVER["argv"][1];
+	
+	$fileArray = array(
+		"mysql" => 
+			array(	"from" => dirname(__FILE__) . "/" . $mpbnFolder . "/resources/db/postgresql/utf8/pgsql_data.sql",
+					"to" => dirname(__FILE__) . "/" . $mpbnFolder . "/resources/db/mysql/utf8/mysql_data.sql")
+	);
+	
+	function saveAsFile($filename, $data) {
+		if ($h = fopen($filename, "w")) {
+			if (!fwrite($h, $data)) {
+				return false;
+			}
+			fclose($h);
+		}
+		return true;
+	}
+	
+	// load file
+	$from = $fileArray["mysql"]["from"];
+	$to = $fileArray["mysql"]["to"];
+
+	if (file_exists($from)) {
+		$data = file_get_contents($from);
+	}
+	else {
+		echo "Fatal error: File not found ('" . $from . "').\n";
+		exit(1);
+	}
+
+	// replace postgresql's string escape syntax
+	$pattern = "/, E'/";
+	$data = preg_replace($pattern, ", '", $data);
+
+	// disable foreign keys
+	$pattern = "/UPDATE pg_catalog\.pg_class SET reltriggers = 0;/";
+	if (preg_match($pattern, $data)) {
+		$data = preg_replace($pattern, "SET FOREIGN_KEY_CHECKS=0;", $data);
+	}
+	else {
+		echo "Fatal error: Didn't find expression (pattern: " . $pattern . ").\n";
+		exit(1);
+	}
+	
+	// enable foreign keys
+	$pattern = 	"/UPDATE pg_catalog\.pg_class SET reltriggers = \(SELECT pg_catalog\.count\(\*\) FROM pg_catalog\.pg_trigger where pg_class\.oid = tgrelid\);/";
+	if (preg_match($pattern, $data)) {
+		$data = preg_replace($pattern, "SET FOREIGN_KEY_CHECKS=1;", $data);
+	}
+	else {
+		echo "Fatal error: Didn't find expression (pattern: " . $pattern . ").\n";
+		exit(1);
+	}
+	
+	// save mysql file
+	if (!saveAsFile($to, $data)) {
+		echo "Fatal error: File could not be saved ('" . $to . "').\n";
+		exit(1);
+	}
+	echo "Finished.\n\n";
+	exit(0);
+?>
\ No newline at end of file

Added: trunk/build/2_convertDataDumps.php
===================================================================
--- trunk/build/2_convertDataDumps.php	                        (rev 0)
+++ trunk/build/2_convertDataDumps.php	2008-10-01 07:35:44 UTC (rev 3063)
@@ -0,0 +1,48 @@
+<?php
+	require_once(dirname(__FILE__) . "/commandLine.inc");
+	
+	$mpbnFolder = $_SERVER["argv"][1];
+	
+	// needs to be set, otherwise the iconv option //TRANSLIT
+	// won't work
+	setlocale(LC_CTYPE, "de_DE.utf8");
+
+	$fileArray = array(
+		"mysql" => 
+			array(	"from" => dirname(__FILE__) . "/" . $mpbnFolder . "/resources/db/mysql/utf8/mysql_data.sql",
+					"to" => dirname(__FILE__) . "/" . $mpbnFolder . "/resources/db/mysql/iso/mysql_data.sql"),
+		"pgsql" => 
+			array(	"from" => dirname(__FILE__) . "/" . $mpbnFolder . "/resources/db/postgresql/utf8/pgsql_data.sql",
+					"to" => dirname(__FILE__) . "/" . $mpbnFolder . "/resources/db/postgresql/iso/pgsql_data.sql")
+	);
+
+	function saveAsFile($filename, $data) {
+		if ($h = fopen($filename, "w")) {
+			if (!fwrite($h, $data)) {
+				return false;
+			}
+			fclose($h);
+		}
+		return true;
+	}
+	
+
+	foreach ($fileArray as $file) {
+		$from = $file["from"];
+		$to = $file["to"];
+		
+		if (file_exists($from)) {
+			$data = file_get_contents($from);
+		}
+		else {
+			echo "Fatal error: File not found ('" . $from . "').\n";
+		}
+
+		$dataConverted = iconv("UTF-8", "ASCII//TRANSLIT", $data);
+	
+		if (!saveAsFile($to, $dataConverted)) {
+			echo "Fatal error: File could not be saved ('" . $to . "').\n";
+		}
+	}		
+	echo "Finished.\n\n";
+?>
\ No newline at end of file

Added: trunk/build/3_addHeaderToDataDumps.php
===================================================================
--- trunk/build/3_addHeaderToDataDumps.php	                        (rev 0)
+++ trunk/build/3_addHeaderToDataDumps.php	2008-10-01 07:35:44 UTC (rev 3063)
@@ -0,0 +1,64 @@
+<?php
+	require_once(dirname(__FILE__) . "/commandLine.inc");
+	
+	$mpbnFolder = $_SERVER["argv"][1];
+	
+	if (!file_exists(dirname(__FILE__) . "/" . $mpbnFolder . "/core/system.php")) {
+		echo "File not found: " . dirname(__FILE__) . "/" . $mpbnFolder . "/core/system.php";
+		exit(1);		
+	}
+	else {
+		require_once(dirname(__FILE__) . "/" . $mpbnFolder . "/core/system.php");
+	}
+	
+	setlocale(LC_TIME, "de_DE.utf8");
+
+	$fileArray = array(
+		"mysql" => 
+			array(	"iso" => dirname(__FILE__) . "/" . $mpbnFolder . "/resources/db/mysql/iso/mysql_data.sql",
+					"utf8" => dirname(__FILE__) . "/" . $mpbnFolder . "/resources/db/mysql/utf8/mysql_data.sql"),
+		"postgresql" => 
+			array(	"iso" => dirname(__FILE__) . "/" . $mpbnFolder . "/resources/db/postgresql/iso/pgsql_data.sql",
+					"utf8" => dirname(__FILE__) . "/" . $mpbnFolder . "/resources/db/postgresql/utf8/pgsql_data.sql")
+	);
+	
+	function saveAsFile($filename, $data) {
+		if ($h = fopen($filename, "w")) {
+			if (!fwrite($h, $data)) {
+				return false;
+			}
+			fclose($h);
+		}
+		return true;
+	}
+	
+	foreach ($fileArray as $dbType => $files) {
+		foreach ($files as $characterSet => $file) {
+			if (file_exists($file)) {
+				$data = file_get_contents($file);
+			}
+			else {
+				echo "Fatal error: File not found ('" . $file . "').\n";
+				exit(1);
+			}
+			
+			// add header to file
+			$header = 	"--\n" .
+						"-- " . $dbType . " " . $characterSet . " data dump\n" . 
+						"-- \n" .
+						"-- Mapbender " . MB_VERSION_NUMBER . " " . MB_VERSION_APPENDIX . "\n" .
+						"-- \n" .
+						"-- " . date("Y/m/d", MB_RELEASE_DATE) . "\n" . 
+						"--\n\n";
+			$data = $header . $data;
+
+			if (!saveAsFile($file, $data)) {
+				echo "Fatal error: File could not be saved ('" . $file . "').\n";
+				exit(1);
+			}
+
+		}
+	}
+	echo "Finished.\n\n";
+	exit(0);
+?>
\ No newline at end of file

Added: trunk/build/checksum/build-checksum.php
===================================================================
--- trunk/build/checksum/build-checksum.php	                        (rev 0)
+++ trunk/build/checksum/build-checksum.php	2008-10-01 07:35:44 UTC (rev 3063)
@@ -0,0 +1,70 @@
+<?php
+
+#build-checksum.php 
+#@author Siddharth Prakash Singh (spsneo)
+#Google SoC 2008 Project
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# Update Script
+# To be executed from command line only.
+
+
+#check whether this file is being executed from command line or not
+#abort if it is not being executed from command line
+require_once("commandLine.inc");
+
+#This file is required 
+require_once("checksum-utils.inc");
+
+#These are the directories which are not to be scanned and checksum not to be evaluated as these 
+#directories are prone to change and always include "." and ".." in this list.
+$dir_not_to_scan = array();
+array_push($dir_not_to_scan,".", "..", "license", "log");
+
+$rootdir_path = dirname(__FILE__) . "/../" . $_SERVER["argv"][1] . "/";
+
+//remove slash if it is there at the end of the path
+if(substr($rootdir_path, -1) == '/') {
+	$rootdir_path = substr($rootdir_path, 0 , -1);
+}
+
+#check whether this is a valid directory
+if(!is_dir($rootdir_path)) {
+	echo $rootdir_path." is not a valid directory\n";
+	return FALSE;
+}
+
+#check whether this directory is readable
+if(!is_readable($rootdir_path)) {
+	echo $rootdir_path." is not readable.\nPlease make sure you have privilege to build.\nAborting...";
+	exit();
+}
+
+#initialize the directory
+$rootdir = dir($rootdir_path);
+$rootdir_path = $rootdir->path;
+
+while(false !== ($dir_to_scan = $rootdir->read())) {
+	$dir_to_scan_path = $rootdir_path.'/'.$dir_to_scan;
+	#directories to scan, hidden directories excluded
+	if(is_dir($dir_to_scan_path) && !in_array($dir_to_scan, $dir_not_to_scan) && !preg_match("/^\./", $dir_to_scan)) {
+		echo "Scanning directory: ".$dir_to_scan_path."\n";
+		build_checksum($dir_to_scan_path);
+		echo "All checksums and respective JSON files created for all the files and directories inside ".$dir_to_scan_path."\n\n";
+	}
+}
+
+echo "\n\nDone!\n\n";
+?>
\ No newline at end of file

Added: trunk/build/checksum/checksum-utils.inc
===================================================================
--- trunk/build/checksum/checksum-utils.inc	                        (rev 0)
+++ trunk/build/checksum/checksum-utils.inc	2008-10-01 07:35:44 UTC (rev 3063)
@@ -0,0 +1,72 @@
+<?php
+
+#Author: Siddharth Prakash Singh(spsneo)
+#Google Summer Of Code Project 2008
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+function build_checksum($dir_path) {
+	
+	#This array holds the file-name and sha1 checksum for the files in the current directory
+	$file_arr = array();
+	
+	//remove slash if it is there at the end of the path
+	if(substr($dir_path, -1) == '/') {
+		$dir_path = substr($dir_path, 0 , -1);
+	}
+	
+	
+	if(!is_dir($dir_path)) {
+		echo $dir_path." is not a valid directory\n";
+		return FALSE;
+	}
+	
+	if(!is_readable($dir_path)) {
+		echo $dir_path." is not readable.\nPlease make sure you have privilege to build.\nAborting...\n";
+		exit();
+	}
+	
+	$directory = dir($dir_path);
+	while(false !== ($file = $directory->read())) {
+		$file_path = $dir_path.'/'.$file;
+		if(is_file($file_path) && $file != 'checksum.json' && !preg_match("/~$/", $file) && !preg_match("/^\./", $file)) {
+			if(is_readable($file_path)) {
+				$file_arr[$file] = sha1_file($file_path);
+			} else {
+				echo $file_path." is not readable.\nPlease make sure you have privelege to build.\nAborting...\n";
+				exit();
+			}
+		} else if (is_dir($file_path) && !preg_match("/^\./", $file)) {
+			if($file != '.' && $file != '..' ) {
+				//echo "Scanning directory: ".$file_path."\n";
+				build_checksum($file_path);
+			}
+		} else {
+			
+		}
+	}
+	$file_json_string = json_encode($file_arr);
+	$file_json_name = $dir_path."/checksum.json";
+	$file_json_handle = fopen($file_json_name, "w");
+	if(!file_json_handle) {
+		echo "Error creating file checksum.json\nPlease execute this script again.\nAborting...\n ";
+		exit();
+	}
+	fwrite($file_json_handle, $file_json_string);
+	fclose($file_json_handle);
+	//echo "Succesfully created checksums of files in directory: ".$dir_path."\n";
+	return TRUE;
+}

Added: trunk/build/checksum/commandLine.inc
===================================================================
--- trunk/build/checksum/commandLine.inc	                        (rev 0)
+++ trunk/build/checksum/commandLine.inc	2008-10-01 07:35:44 UTC (rev 3063)
@@ -0,0 +1,39 @@
+<?php
+
+#Mapbender Updater File
+#Author: Siddharth Prakash Singh(spsneo)
+#Google Summer Of Code Project 2008
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+#
+# This file tests whether the update script has been called from command line or browser.
+# Aborts the update process if called from a web browser
+
+
+if ( isset( $_SERVER ) && array_key_exists( 'REQUEST_METHOD', $_SERVER ) ) {
+	echo "This script must be executed from the command line ";
+	exit();
+}
+
+if(PHP_SAPI != 'cli') {
+echo "This script must be executed from the command line.";
+exit();
+}
+
+#Set the execution time to infinity
+ at set_time_limit( 0 );
+?>

Added: trunk/build/commandLine.inc
===================================================================
--- trunk/build/commandLine.inc	                        (rev 0)
+++ trunk/build/commandLine.inc	2008-10-01 07:35:44 UTC (rev 3063)
@@ -0,0 +1,39 @@
+<?php
+
+#Mapbender Updater File
+#Author: Siddharth Prakash Singh(spsneo)
+#Google Summer Of Code Project 2008
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+#
+# This file tests whether the update script has been called from command line or browser.
+# Aborts the update process if called from a web browser
+
+
+if ( isset( $_SERVER ) && array_key_exists( 'REQUEST_METHOD', $_SERVER ) ) {
+	echo "This script must be executed from the command line ";
+	exit();
+}
+
+if(PHP_SAPI != 'cli') {
+echo "This script must be executed from the command line.";
+exit();
+}
+
+#Set the execution time to infinity
+ at set_time_limit( 0 );
+?>

Added: trunk/build/test_utf8.sed
===================================================================
--- trunk/build/test_utf8.sed	                        (rev 0)
+++ trunk/build/test_utf8.sed	2008-10-01 07:35:44 UTC (rev 3063)
@@ -0,0 +1,20 @@
+s/ß/ss/g;
+s/ä/ae/g;
+s/ü/ue/g;
+s/ö/oe/g;
+s/Ä/Ae/g;
+s/Å‚/l/g;
+s/ó/o/g;
+s/í/i/g;
+s/é/e/g;
+s/é/e/g;
+s/A?AE'A,A-/i/g;
+s/á/a/g;
+s/ú/u/g;
+s/á/a/g;
+s/ñ/n/g;
+s/ú/u/g;
+s/ó/o/g;
+s/í/i/g;
+s/ñ/n/g;
+s/ü/ue/g;
\ No newline at end of file



More information about the Mapbender_commits mailing list