[39087] branches/gsoc08-framework/MacPorts_Framework

armahg at macports.org armahg at macports.org
Thu Aug 7 17:20:34 PDT 2008


Revision: 39087
          http://trac.macosforge.org/projects/macports/changeset/39087
Author:   armahg at macports.org
Date:     2008-08-07 17:20:34 -0700 (Thu, 07 Aug 2008)
Log Message:
-----------
Added MPHelperToolTest files. Added interInit.tcl which is used by MPHelperTool to initialize its internal Tcl interpreter. Added server side methods to MPNotifications to listen for IPC with MPHelperTool using NSFileHandle methods. Now to finish things up on the client side ...

Modified Paths:
--------------
    branches/gsoc08-framework/MacPorts_Framework/MPHelperCommon.h
    branches/gsoc08-framework/MacPorts_Framework/MPHelperTool.m
    branches/gsoc08-framework/MacPorts_Framework/MPNotifications.h
    branches/gsoc08-framework/MacPorts_Framework/MPNotifications.m
    branches/gsoc08-framework/MacPorts_Framework/MacPorts.Framework.xcodeproj/project.pbxproj
    branches/gsoc08-framework/MacPorts_Framework/init.tcl

Added Paths:
-----------
    branches/gsoc08-framework/MacPorts_Framework/HelperToolServerFile.txt
    branches/gsoc08-framework/MacPorts_Framework/MPHelperToolTest.h
    branches/gsoc08-framework/MacPorts_Framework/MPHelperToolTest.m
    branches/gsoc08-framework/MacPorts_Framework/interpInit.tcl

Added: branches/gsoc08-framework/MacPorts_Framework/HelperToolServerFile.txt
===================================================================


Property changes on: branches/gsoc08-framework/MacPorts_Framework/HelperToolServerFile.txt
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: branches/gsoc08-framework/MacPorts_Framework/MPHelperCommon.h
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework/MPHelperCommon.h	2008-08-07 22:51:26 UTC (rev 39086)
+++ branches/gsoc08-framework/MacPorts_Framework/MPHelperCommon.h	2008-08-08 00:20:34 UTC (rev 39087)
@@ -14,7 +14,11 @@
 #include <tcl.h>
 
 #define asl_NSLog(client, msg, level, format, ...) asl_log(client, msg, level, "%s", [[NSString stringWithFormat:format, ##__VA_ARGS__] UTF8String])
+#ifndef ASL_KEY_FACILITY
+#   define ASL_KEY_FACILITY "Facility"
+#endif
 
+
 //We need only one command for this Tool
 
 #define kMPHelperEvaluateTclCommand					"EvaluateTcl"

Modified: branches/gsoc08-framework/MacPorts_Framework/MPHelperTool.m
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework/MPHelperTool.m	2008-08-07 22:51:26 UTC (rev 39086)
+++ branches/gsoc08-framework/MacPorts_Framework/MPHelperTool.m	2008-08-08 00:20:34 UTC (rev 39087)
@@ -43,16 +43,139 @@
 
 
 
-static OSStatus DoEvaluateTclString (
-	 AuthorizationRef			auth,
-	 const void *				userData,
-	 CFDictionaryRef				request,
-	 CFMutableDictionaryRef		response,
-	 aslclient					asl,
-	 aslmsg						aslMsg
-)
+//According to the docs all I need is
+//the file descriptor that MPNotifications
+//obtained when creating the server socket
+//I'll save that here when retrieving info.
+//fromt he request dictionary
+int notificationsFileDescriptor;
+BOOL hasSetFileDescriptor = NO;
+
+
+#pragma mark Tcl Commands
+int MPHelperTool_Notifications_Command_One 
+(
+ ClientData clientData, 
+ Tcl_Interp *interpreter, 
+ int objc, 
+ Tcl_Obj *CONST objv[]
+) 
 {
+	NSString * data;
+	NSFileHandle * writeHandle;
+	int returnCode = TCL_ERROR;
+	int err;
 	
+	//asl logging stuff
+	aslmsg logMsg = asl_new(ASL_TYPE_MSG) ;
+	assert(logMsg != NULL);
+	asl_set(logMsg, ASL_KEY_FACILITY, "com.apple.console");
+	asl_set(logMsg, ASL_KEY_SENDER, "MPHelperTool");
+	
+	aslclient logClient = asl_open(NULL , NULL, ASL_OPT_STDERR);
+	assert(logClient != NULL);
+	
+	if (hasSetFileDescriptor) {
+		writeHandle = [[NSFileHandle alloc] initWithFileDescriptor:notificationsFileDescriptor];
+	}
+	else {
+		asl_NSLog(logClient, logMsg, ASL_LEVEL_ERR, @"Attempted to initialize writeHandle");
+		asl_NSLog(logClient, logMsg, ASL_LEVEL_ERR, @"without having set notificationsFileDescriptor value");
+	}
+	
+	err = asl_NSLog(logClient , logMsg, ASL_LEVEL_DEBUG, @"Starting writing to notification socket");
+	assert( err == 0);
+	
+	++objv, --objc;
+	
+	if (objc) {
+		data = [NSString stringWithUTF8String:Tcl_GetString(*objv)];
+		
+		//TO DO: Don't just send in raw data ... later i'll want to send in nicely
+		//formatted string or do some processing so the full notifications dictionary
+		//is sent. For now, I just want to get something functional going first
+		
+		//This is a blocking operation. I don't mind that because I'll be doing lots
+		//of heavy lifting on the MPNotifications side to ensure that it only reads
+		//when there is no writing activity taking place etc.
+		[writeHandle writeData:[data dataUsingEncoding:NSUTF8StringEncoding]];
+		err = asl_NSLog(logClient , logMsg, ASL_LEVEL_DEBUG, @"Wrote %@ " , data);
+		assert(err == 0);
+		
+		returnCode = TCL_OK;
+	}
+	
+	asl_close(logClient);
+	[writeHandle release];
+	return returnCode;
+}
+
+
+
+
+
+int SimpleLog_Command 
+(
+ ClientData clientData, 
+ Tcl_Interp *interpreter, 
+ int objc, 
+ Tcl_Obj *CONST objv[]
+) 
+{
+	
+	//NS writing to file stuff
+	NSString * data;
+	NSFileHandle * dHandle;
+	NSString * destination = @"/Users/Armahg/Desktop/logFile2.txt";
+	dHandle = [NSFileHandle fileHandleForWritingAtPath:destination];
+	[dHandle truncateFileAtOffset:[dHandle seekToEndOfFile]];
+	
+	int returnCode = TCL_ERROR;
+	int err;
+	
+	//asl logging stuff
+	aslmsg logMsg = asl_new(ASL_TYPE_MSG) ;
+	assert(logMsg != NULL);
+	asl_set(logMsg, ASL_KEY_FACILITY, "com.apple.console");
+	asl_set(logMsg, ASL_KEY_SENDER, "MPHelperTool");
+	
+	aslclient logClient = asl_open(NULL , NULL, ASL_OPT_STDERR);
+	assert(logClient != NULL);
+	
+	
+	err = asl_NSLog(logClient , logMsg, ASL_LEVEL_DEBUG, @"Starting simplelog Logging");
+	assert( err == 0);
+	
+	++objv, --objc;
+	
+	if (objc) {
+		data = [NSString stringWithUTF8String:Tcl_GetString(*objv)];
+		[dHandle writeData:[data dataUsingEncoding:NSUTF8StringEncoding]];
+		err = asl_NSLog(logClient , logMsg, ASL_LEVEL_DEBUG, @" %@ " , data);
+		assert(err == 0);
+		
+		returnCode = TCL_OK;
+	}
+	
+	asl_close(logClient);
+	return returnCode;
+}
+
+
+
+#pragma mark -
+
+static OSStatus DoEvaluateTclString 
+(
+ AuthorizationRef			auth,
+ const void *				userData,
+ CFDictionaryRef				request,
+ CFMutableDictionaryRef		response,
+ aslclient					asl,
+ aslmsg						aslMsg
+ )
+{
+	
 	OSStatus		retval = noErr;
 	
 	
@@ -101,8 +224,8 @@
 	else {//For Dbg.
 		CFDictionaryAddValue(response, CFSTR("TclInterpreterInit"), CFSTR("YES"));
 	}
-	 
 	
+	
 	NSString * mport_fastload = [[@"source [file join \"" stringByAppendingString:tclPkgPath]
 								 stringByAppendingString:@"\" macports1.0 macports_fastload.tcl]"];
 	if(Tcl_Eval(interpreter, [mport_fastload UTF8String]) == TCL_ERROR) {
@@ -117,14 +240,31 @@
 		CFDictionaryAddValue(response, CFSTR("MPFastload"), CFSTR("YES"));
 	}
 	
-	/*	
-	Tcl_CreateObjCommand(interpreter, "notifications", Notifications_Command, NULL, NULL);
-	if (Tcl_PkgProvide(interpreter, "notifications", "1.0") != TCL_OK) {
+	//Add simplelog tcl command
+	Tcl_CreateObjCommand(interpreter, "simplelog", SimpleLog_Command, NULL, NULL);
+	if (Tcl_PkgProvide(interpreter, "simplelog", "1.0") != TCL_OK) {
 		NSLog(@"Error in Tcl_PkgProvide: %s", Tcl_GetStringResult(interpreter));
-		Tcl_DeleteInterp(interpreter);
+		retval = coreFoundationUnknownErr;
+		//For Dbg
+		CFDictionaryAddValue(response, CFSTR("simplelog"), CFSTR("NO"));
 	}
-	*/
+	else {
+		CFDictionaryAddValue(response, CFSTR("simplelog"), CFSTR("YES"));
+	}
 	
+	//Add mphelpertool_notification_one tcl command
+	Tcl_CreateObjCommand(interpreter, "mphelpertool_notify1", MPHelperTool_Notifications_Command_One, NULL, NULL);
+	if (Tcl_PkgProvide(interpreter, "mphelpertool_notify1", "1.0") != TCL_OK) {
+		NSLog(@"Error in Tcl_PkgProvide: %s", Tcl_GetStringResult(interpreter));
+		retval = coreFoundationUnknownErr;
+		//For Dbg
+		CFDictionaryAddValue(response, CFSTR("mphnotone"), CFSTR("NO"));
+	}
+	else {
+		CFDictionaryAddValue(response, CFSTR("mphnotone"), CFSTR("YES"));
+	}
+	
+	
 	NSString * interpInitFilePath = (NSString *) (CFStringRef) CFDictionaryGetValue(request, CFSTR(kInterpInitFilePath));
 	if (interpInitFilePath == nil) {
 		CFDictionaryAddValue(response, CFSTR("interpInitFilePath"), CFSTR("NO"));
@@ -161,10 +301,10 @@
 		CFDictionaryAddValue(response, CFSTR(kTclStringEvaluationResult), (CFStringRef)result);
 	}
 	
-
+	
 	assert(response != NULL);
-
 	
+	
 	return retval;
 }
 
@@ -179,13 +319,13 @@
  */
 
 static const BASCommandProc kMPHelperCommandProcs[] = {
-	DoEvaluateTclString,	
-	NULL
+DoEvaluateTclString,	
+NULL
 };
 
 int main(int argc, char const * argv[]) {
 	NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
-
+	
 	int result = BASHelperToolMain(kMPHelperCommandSet, kMPHelperCommandProcs);
 	
 	[pool release];

Added: branches/gsoc08-framework/MacPorts_Framework/MPHelperToolTest.h
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework/MPHelperToolTest.h	                        (rev 0)
+++ branches/gsoc08-framework/MacPorts_Framework/MPHelperToolTest.h	2008-08-08 00:20:34 UTC (rev 39087)
@@ -0,0 +1,22 @@
+//
+//  MPHelperToolTest.h
+//  MacPorts.Framework
+//
+//  Created by George  Armah on 8/5/08.
+//  Copyright 2008 Lafayette College. All rights reserved.
+//
+
+#import <SenTestingKit/SenTestingKit.h>
+#import <Security/Security.h>
+#import "MPInterpreter.h"
+
+
+
+ at interface MPHelperToolTest : SenTestCase {
+	MPInterpreter * interp;
+}
+
+-(void) testMPHelperToolWithoutRights;
+
+
+ at end


Property changes on: branches/gsoc08-framework/MacPorts_Framework/MPHelperToolTest.h
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: branches/gsoc08-framework/MacPorts_Framework/MPHelperToolTest.m
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework/MPHelperToolTest.m	                        (rev 0)
+++ branches/gsoc08-framework/MacPorts_Framework/MPHelperToolTest.m	2008-08-08 00:20:34 UTC (rev 39087)
@@ -0,0 +1,42 @@
+//
+//  MPHelperToolTest.m
+//  MacPorts.Framework
+//
+//  Created by George  Armah on 8/5/08.
+//  Copyright 2008 Lafayette College. All rights reserved.
+//
+
+#import "MPHelperToolTest.h"
+
+
+ at implementation MPHelperToolTest
+
+-(void) setUp {
+	interp = [MPInterpreter sharedInterpreter];
+}
+
+-(void) tearDown {
+	
+}
+
+- (void) testMPHelperToolWithoutRights {
+	AuthorizationRef authRef;
+	
+		
+	OSStatus junk;
+	
+	
+	junk = AuthorizationCreate (NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &authRef);
+	assert(junk == noErr);
+	
+	[interp setAuthorizationRef:authRef];
+	
+	NSString * result = [interp evaluateStringWithMPHelperTool:@"mportsync"];
+	
+	NSLog(@"Result is %@" , result);
+	STAssertTrue ( [result isEqualToString:@"TCL COMMAND EXECUTION SUCCEEDED YAAY!:"], \
+				  @"Result should succeed so long as we enter credentials");	
+}
+
+
+ at end


Property changes on: branches/gsoc08-framework/MacPorts_Framework/MPHelperToolTest.m
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: branches/gsoc08-framework/MacPorts_Framework/MPNotifications.h
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework/MPNotifications.h	2008-08-07 22:51:26 UTC (rev 39086)
+++ branches/gsoc08-framework/MacPorts_Framework/MPNotifications.h	2008-08-08 00:20:34 UTC (rev 39087)
@@ -73,6 +73,13 @@
 #define MPALL @"MPAllNotification"
 
 
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <string.h>
+
+
 /*!
  @class MPNotifications
  @abstract A class to handle notifying Framework clients of port activity
@@ -84,6 +91,15 @@
 @interface MPNotifications : NSObject {
 	NSString * performingTclCommand;
 	NSMutableDictionary * blockOptions;
+	NSFileHandle * acceptHandle; 
+	NSFileHandle * readHandle;
+	
+	//BSD sockets stuff
+	NSString * serverFilePath;
+	int sd1, rc;
+	struct sockaddr_un serveraddr;
+	BOOL hasSetFileDescriptor;
+	
 }
 
 /*!
@@ -128,4 +144,5 @@
 -(NSString *)performingTclCommand;
 
 
+
 @end

Modified: branches/gsoc08-framework/MacPorts_Framework/MPNotifications.m
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework/MPNotifications.m	2008-08-07 22:51:26 UTC (rev 39086)
+++ branches/gsoc08-framework/MacPorts_Framework/MPNotifications.m	2008-08-08 00:20:34 UTC (rev 39087)
@@ -36,7 +36,15 @@
 
 #import "MPNotifications.h"
 
+ at interface MPNotifications (Private)
+-(void) socketConnected:(NSNotification *)notification;
+-(void) readData:(NSNotification *)notification;
+-(void) notifyWithData:(NSNotification *)notification;
+-(BOOL) initBSDSocket;
+ at end
 
+
+
 @implementation MPNotifications
 
 + (MPNotifications *)sharedListener {
@@ -86,10 +94,109 @@
 						[NSNumber numberWithInt:0], MPWARN, [NSNumber numberWithInt:0], MPERROR, 
 						[NSNumber numberWithInt:0], MPDEBUG, [NSNumber numberWithInt:0], MPALL, nil];
 		//NSLog(@"Dictionary is %@ ", [blockOptions description]);
+		
+		hasSetFileDescriptor = NO;
+		
+		if ([self initBSDSocket]) {
+			//should I be using the closeDealloc version instead? 
+			acceptHandle = [[NSFileHandle alloc] initWithFileDescriptor:sd1];
+			readHandle = [[NSFileHandle alloc] initWithFileDescriptor:sd1];
+			
+	
+			
+			//It would be nice if I could somehow add the fileHandle in the HelperTool as the sender
+			//this notification. That way I don't read stuff not intended for me.
+			//Perhaps I should post a distributed notification to indicate initiation of
+			//the asynchronous notification?
+			[[NSNotificationCenter defaultCenter] addObserver:self 
+													 selector:@selector(socketConnected:)
+														 name:NSFileHandleConnectionAcceptedNotification 
+													   object:nil];
+			
+			//Posts the notification above after accepting a connection
+			[acceptHandle acceptConnectionInBackgroundAndNotify];
+		}
+		
+		
 	}
 	return self;
 }
 
+//Internal methods for IPC with helper tool
+//This method should really run in a background separate
+//thread so that it doesn't black ... I'll implement
+//that after I get the basic functionality working
+- (void) socketConnected:(NSNotification *) notification {
+	
+	[[NSNotificationCenter defaultCenter] addObserver:self 
+											 selector:@selector(readData:) 
+												 name:NSFileHandleDataAvailableNotification 
+											   object:nil];
+	
+	//Need to call this again since it is done only once in init
+	//and this is a singleton instance class
+	//acceptHandle posts the above notification
+	[acceptHandle acceptConnectionInBackgroundAndNotify];
+	
+	
+}
+
+- (void) readData:(NSNotification *) notification {
+	
+	[[NSNotificationCenter defaultCenter] addObserver:self 
+											 selector:@selector(notifyWithData:) 
+												 name:NSFileHandleReadCompletionNotification
+											   object:nil];
+	
+	//Once data is availabl we can call this method
+	//it posts the above notification on completion
+	[readHandle readInBackgroundAndNotify];
+}
+
+- (void) notifyWithData:(NSNotification *) notification {
+	NSData * inData = [[notification userInfo] objectForKey:NSFileHandleNotificationDataItem];
+	NSString * inString = [[NSString alloc] initWithData:inData 
+												encoding:NSUTF8StringEncoding];
+	//Just Log it for now
+	NSLog(@"Read in %@ from MPHelperTool", inString);
+	[inString release];
+	
+	//Once we have finished reading a stream of data and we are
+	//done logging ... we can start 
+	//[acceptHandle acceptConnectionInBackgroundAndNotify];
+}
+
+-(BOOL) initBSDSocket {
+	//BSD Socket Initialization (maybe I should put this in another method ?)
+	sd1 = -1;
+	serverFilePath = [[NSBundle bundleForClass:[MPNotifications class]]
+					  pathForResource:@"HelperToolServerFile" ofType:@"txt"];
+	sd1 = socket(AF_UNIX, SOCK_STREAM, 0);
+	if (sd1 < 0) {
+		NSLog(@"socket() failed");
+	}
+	
+	memset( &serveraddr, 0, sizeof(serveraddr));
+	serveraddr.sun_family = AF_UNIX;
+	strcpy(serveraddr.sun_path, [serverFilePath cStringUsingEncoding:NSUTF8StringEncoding]);
+	
+	rc = bind(sd1, (struct sockaddr *)&serveraddr, SUN_LEN(&serveraddr));
+	if (rc < 0) {
+		NSLog(@"bind() failed");
+	}
+	else {
+		hasSetFileDescriptor = YES;
+	}
+	return hasSetFileDescriptor;
+}
+
+
+-(int) getServerFileDescriptor {
+	return sd1;
+}
+
+
+
 - (void)dealloc {
 	[super dealloc];
 }
@@ -101,7 +208,7 @@
 		[performingTclCommand release];
 		performingTclCommand = [tclString copy];
 	}
-
+	
 }
 
 - (NSString *) performingTclCommand {

Modified: branches/gsoc08-framework/MacPorts_Framework/MacPorts.Framework.xcodeproj/project.pbxproj
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework/MacPorts.Framework.xcodeproj/project.pbxproj	2008-08-07 22:51:26 UTC (rev 39086)
+++ branches/gsoc08-framework/MacPorts_Framework/MacPorts.Framework.xcodeproj/project.pbxproj	2008-08-08 00:20:34 UTC (rev 39087)
@@ -73,6 +73,7 @@
 		6ED12A550E3E55DF0026773D /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6ED12A540E3E55DF0026773D /* Security.framework */; };
 		6ED12A560E3E55DF0026773D /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6ED12A540E3E55DF0026773D /* Security.framework */; };
 		6ED12AF10E3E9E210026773D /* Tcl.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6EA0F56E0DFEB55E00C15082 /* Tcl.framework */; };
+		6ED1AC750E4BA162000353B6 /* HelperToolServerFile.txt in Resources */ = {isa = PBXBuildFile; fileRef = 6ED1AC740E4BA162000353B6 /* HelperToolServerFile.txt */; };
 		6EE93E670E493AC600AECE9E /* interpInit.tcl in Resources */ = {isa = PBXBuildFile; fileRef = 6EE93E660E493AC600AECE9E /* interpInit.tcl */; };
 		6EE93FAB0E495C2200AECE9E /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6ECD970D0E465C7800488335 /* Security.framework */; };
 		8DC2EF530486A6940098B216 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C1666FE841158C02AAC07 /* InfoPlist.strings */; };
@@ -167,6 +168,7 @@
 		6ED12A4A0E3E552F0026773D /* MPHelperTool */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = MPHelperTool; sourceTree = BUILT_PRODUCTS_DIR; };
 		6ED12A540E3E55DF0026773D /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = /System/Library/Frameworks/Security.framework; sourceTree = "<absolute>"; };
 		6ED12AA60E3E7E900026773D /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
+		6ED1AC740E4BA162000353B6 /* HelperToolServerFile.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = HelperToolServerFile.txt; sourceTree = "<group>"; };
 		6EE93E660E493AC600AECE9E /* interpInit.tcl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = interpInit.tcl; sourceTree = "<group>"; };
 		6EE93E780E495B3100AECE9E /* Tcl.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Tcl.framework; path = Library/Frameworks/Tcl.framework; sourceTree = SDKROOT; };
 		8DC2EF5A0486A6940098B216 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
@@ -278,6 +280,7 @@
 				6E44A00C0E2DAD66007DE8EC /* ToDo.txt */,
 				6EB6FB260E448EE20057962C /* TestFile.test */,
 				6EE93E660E493AC600AECE9E /* interpInit.tcl */,
+				6ED1AC740E4BA162000353B6 /* HelperToolServerFile.txt */,
 			);
 			name = Resources;
 			sourceTree = "<group>";
@@ -570,6 +573,7 @@
 				6EB6FB270E448EE20057962C /* TestFile.test in Resources */,
 				6EE93E670E493AC600AECE9E /* interpInit.tcl in Resources */,
 				6E22BD420E4A30C700CA76C4 /* mycredentials in Resources */,
+				6ED1AC750E4BA162000353B6 /* HelperToolServerFile.txt in Resources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Modified: branches/gsoc08-framework/MacPorts_Framework/init.tcl
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework/init.tcl	2008-08-07 22:51:26 UTC (rev 39086)
+++ branches/gsoc08-framework/MacPorts_Framework/init.tcl	2008-08-08 00:20:34 UTC (rev 39087)
@@ -80,6 +80,7 @@
 
 
 
+
 #Modifying UI initialization to enable notifications
 #Redefine ui_$pritority to throw global notifications
 #This is currently under works ... a reasonable solution

Added: branches/gsoc08-framework/MacPorts_Framework/interpInit.tcl
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework/interpInit.tcl	                        (rev 0)
+++ branches/gsoc08-framework/MacPorts_Framework/interpInit.tcl	2008-08-08 00:20:34 UTC (rev 39087)
@@ -0,0 +1,210 @@
+#catch {source \
+#	[file join "/Library/Tcl" macports1.0 macports_fastload.tcl]}
+
+#Trying my own MacPorts build rather than default one on the system
+#catch {source \
+#	[file join "/Users/Armahg/macportsbuild/build1/Library/Tcl" macports1.0 macports_fastload.tcl]}
+
+
+
+package require macports
+package require simplelog
+package require mphelpertool_notify1
+
+
+#Set ui_options to log all messages to stdout and notify system
+#filtering is done on the Obj-C side of things
+set ui_options(ports_debug) "yes"
+set ui_options(ports_verbose) "yes"
+
+# ui_options accessor
+proc ui_isset {val} {
+	global ui_options
+	if {[info exists ui_options($val)]} {
+		if {$ui_options($val) == "yes"} {
+			return 1
+		}
+	}
+	return 0
+}
+
+# UI Callback
+proc ui_prefix {priority} {
+    switch $priority {
+        debug {
+        	return "DEBUG: "
+        }
+        error {
+        	return "Error: "
+        }
+        warn {
+        	return "Warning: "
+        }
+        default {
+        	return ""
+        }
+    }
+}
+
+proc ui_channels {priority} {
+    global logfd
+    switch $priority {
+        debug {
+            if {[ui_isset ports_debug]} {
+            	return {stderr}
+            } else {
+            	return {}
+            }
+        }
+        info {
+            if {[ui_isset ports_verbose]} {
+                return {stdout}
+            } else {
+                return {}
+			}
+		}
+        msg {
+            if {[ui_isset ports_quiet]} {
+                return {}
+			} else {
+				return {stdout}
+			}
+		}
+        error {
+        	return {stderr}
+        }
+        default {
+        	return {stdout}
+        }
+    }
+}
+
+
+set logDest [ open "/Users/Armahg/Desktop/logFile.txt" w]
+puts $logDest "SOMETHING DEY HERE"
+simplelog "SOMETHING DEY HERE"
+
+#Modifying UI initialization to enable notifications
+#Redefine ui_$pritority to throw global notifications
+#This is currently under works ... a reasonable solution
+#should be coming up soon
+proc ui_init {priority prefix channels message} {
+	#puts "INSIDE ui_init priority with prefix $prefix and message $message"
+	
+	switch $priority {
+		msg {
+			set nottype "MPMsgNotification" 
+		}
+		debug {
+			set "MPDebugNotification"
+			puts "Recieved Debug"
+		}
+		warn {
+			set nottype "MPWarnNotification"
+		}
+		error {
+			set nottype "MPErrorNotification"
+			puts "Recieved Error"
+		}
+		info {
+			set nottype "MPInfoNotification"
+			puts "Recieved Info"
+		}
+		default {
+			set nottype "MPDefaultNotification"
+		}	
+	}
+	
+    # Get the list of channels.
+    try {
+        set channels [ui_channels $priority]
+    } catch * {
+        set channels [ui_channels_default $priority]
+    }
+    
+    #set channels [ui_channels $priority]
+    
+    # Simplify ui_$priority.
+    set nbchans [llength $channels]
+    if {$nbchans == 0} {
+        proc ::ui_$priority {str} [subst {
+        	puts stdout "\$str"
+        	puts $logDest "\$str"
+        	simplelog "\$str"
+        }]
+    } else {
+        try {
+            set prefix [ui_prefix $priority]
+        } catch * {
+            set prefix [ui_prefix_default $priority]
+        }
+        
+        #set prefix [ui_prefix $priority]
+        
+        if {$nbchans == 1} {
+            set chan [lindex $channels 0]
+            
+            proc ::ui_$priority {str} [subst { 
+            	puts $chan "$prefix\$str"
+            	puts $logDest "$prefix\$str"
+            	simplelog "$prefix\$str"
+            }]
+        } else {
+        	proc ::ui_$priority {str} [subst {
+        		foreach chan \$channels {
+        			puts $chan "$prefix\$str"
+        			puts $logDest "$prefix\$str"
+        			simplelog "$prefix\$str"
+        		}
+        	}]
+        }
+        
+    # Call ui_$priority - Is this step necessary? Consult with Randall
+    #::ui_$priority $message
+    }
+}
+
+
+#Wrapping the following API routines to catch errors
+#and log error Information in a similar fashion to code
+#in macports.tcl.
+proc mportuninstall {portname {v ""} optionslist} {
+	if {[catch {portuninstall::uninstall $portname $v $optionslist} result]} {
+		
+			global errorInfo
+			ui_debug "$errorInfo"
+			ui_error "Uninstall $portname $v failed: $result"
+			return 1
+	}
+}
+
+proc mportactivate {portname v optionslist} {
+	if {[catch {portimage::activate $portname $v $optionslist} result]} {
+			
+			global errorInfo
+			ui_debug "$errorInfo"
+			ui_error "Activate $portname $v failed: $result"
+			return 1
+	}
+}
+
+proc mportdeactivate {portname v optionslist} {
+	if {[catch {portimage::deactivate $portname $v $optionslist} result]} {
+			
+			global errorInfo
+			ui_debug "$errorInfo"
+			ui_error "Deactivate $portname $v failed: $result"
+			return 1
+	}
+}
+
+
+
+# Initialize dport
+# This must be done following parse of global options, as some options are
+# evaluated by dportinit.
+if {[catch {mportinit ui_options global_options global_variations} result]} {
+	global errorInfo
+	puts "$errorInfo"
+	fatal "Failed to initialize ports system, $result"
+}
\ No newline at end of file


Property changes on: branches/gsoc08-framework/MacPorts_Framework/interpInit.tcl
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20080807/cb9eca0d/attachment-0001.html 


More information about the macports-changes mailing list