[39279] branches/gsoc08-framework/MacPorts_Framework_Release
armahg at macports.org
armahg at macports.org
Fri Aug 15 08:16:20 PDT 2008
Revision: 39279
http://trac.macosforge.org/projects/macports/changeset/39279
Author: armahg at macports.org
Date: 2008-08-15 08:16:20 -0700 (Fri, 15 Aug 2008)
Log Message:
-----------
Added -executeWithPossiblePrivileges to MPInterpreter. Operations which might require privileges are first tried without them and then with them if the first attempt fails. Created MPPortManipuationTest class to test basic port operations.
Modified Paths:
--------------
branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperCommon.h
branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperTool.m
branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperToolTest.h
branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperToolTest.m
branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreter.h
branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreter.m
branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreterTest.h
branches/gsoc08-framework/MacPorts_Framework_Release/MacPorts.Framework.xcodeproj/project.pbxproj
branches/gsoc08-framework/MacPorts_Framework_Release/MacPorts.h
branches/gsoc08-framework/MacPorts_Framework_Release/ToDo.txt
Added Paths:
-----------
branches/gsoc08-framework/MacPorts_Framework_Release/MPPortManipulationTest.h
branches/gsoc08-framework/MacPorts_Framework_Release/MPPortManipulationTest.m
Modified: branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperCommon.h
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperCommon.h 2008-08-15 11:57:29 UTC (rev 39278)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperCommon.h 2008-08-15 15:16:20 UTC (rev 39279)
@@ -51,11 +51,9 @@
//response keys
#define kTclStringEvaluationResult "TclStringEvaluationResult" //CFString
- //Actually hold off doing errors for now
- //NSError object we are passing
- #define kNSError "NSError" //Am I allowed to pass in an NSError object?
- //Lets make it a string for now
+ #define kTclReturnCode "TclReturnCode" //CFNumber (TCL_OK, TCL_ERROR etc.)
+
//Key for Testing Distributed Object implementation
#define kMPInterpreterDistObj "MPInterpreterDistObj"
Modified: branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperTool.m
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperTool.m 2008-08-15 11:57:29 UTC (rev 39278)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperTool.m 2008-08-15 15:16:20 UTC (rev 39279)
@@ -53,67 +53,8 @@
#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 proper 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;
-}
-
-
-
-
+//For now we just log to Console ... soon we will be doing fully fledged IPC
int SimpleLog_Command
(
ClientData clientData,
@@ -123,13 +64,6 @@
)
{
- //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;
@@ -146,23 +80,12 @@
err = asl_NSLog(logClient , logMsg, ASL_LEVEL_DEBUG, @"Starting simplelog Logging");
assert( err == 0);
- if (hasSetFileDescriptor) {
- err = asl_NSLog(logClient, logMsg, ASL_LEVEL_DEBUG, @"Setting file descriptor");
- assert(err == 0);
- asl_add_log_file(logClient, notificationsFileDescriptor);
- }
- else{
- err = asl_NSLog(logClient, logMsg, ASL_LEVEL_ERR, @"Unable to log to file descriptor");
- 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);
+ NSString * data = [NSString stringWithUTF8String:Tcl_GetString(*objv)];
+ err = asl_NSLog(logClient , logMsg, ASL_LEVEL_INFO, @" %@ " , data);
+ assert(err == 0);
returnCode = TCL_OK;
}
@@ -220,11 +143,10 @@
CFDictionaryAddValue(response, CFSTR("TclCommandInput"), (CFStringRef)tclCmd);
- //Initialize Tcl Interpreter
+ //Create Tcl Interpreter
Tcl_Interp * interpreter = Tcl_CreateInterp();
if(interpreter == NULL) {
NSLog(@"Error in Tcl_CreateInterp, aborting.");
-
//For Debugging
CFDictionaryAddValue(response, CFSTR("TclInterpreterCreate"), CFSTR("NO"));
retval = coreFoundationUnknownErr;
@@ -233,6 +155,8 @@
CFDictionaryAddValue(response, CFSTR("TclInterpreterCreate"), CFSTR("YES"));
}
+
+ //Initialize Tcl Interpreter
if(Tcl_Init(interpreter) == TCL_ERROR) {
NSLog(@"Error in Tcl_Init: %s", Tcl_GetStringResult(interpreter));
Tcl_DeleteInterp(interpreter);
@@ -245,6 +169,7 @@
}
+ //Load macports1.0 package
NSString * mport_fastload = [[@"source [file join \"" stringByAppendingString:tclPkgPath]
stringByAppendingString:@"\" macports1.0 macports_fastload.tcl]"];
if(Tcl_Eval(interpreter, [mport_fastload UTF8String]) == TCL_ERROR) {
@@ -271,20 +196,9 @@
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"));
- }
-
-
+ //Get path for and load interpInit.tcl file to Tcl Interpreter
NSString * interpInitFilePath = (NSString *) (CFStringRef) CFDictionaryGetValue(request, CFSTR(kInterpInitFilePath));
if (interpInitFilePath == nil) {
CFDictionaryAddValue(response, CFSTR("interpInitFilePath"), CFSTR("NO"));
@@ -292,7 +206,6 @@
}
else
CFDictionaryAddValue(response, CFSTR("interpInitFilePath"), (CFStringRef)interpInitFilePath);
-
if( Tcl_EvalFile(interpreter, [interpInitFilePath UTF8String]) == TCL_ERROR) {
NSLog(@"Error in Tcl_EvalFile init.tcl: %s", Tcl_GetStringResult(interpreter));
Tcl_DeleteInterp(interpreter);
@@ -306,25 +219,31 @@
///Evaluate String and set return string value
NSString * result;
-
- if( Tcl_Eval(interpreter, [tclCmd UTF8String]) == TCL_ERROR ) {
+ int retCode = Tcl_Eval(interpreter, [tclCmd UTF8String]);
+ NSNumber * retNum = [NSNumber numberWithInt:retCode];
+ if( retCode == TCL_ERROR ) {
//Do some error handling
retval = coreFoundationUnknownErr;
result = [@"TCL COMMAND EXECUTION FAILED BOO!:"
stringByAppendingString:[NSString stringWithUTF8String:Tcl_GetStringResult(interpreter)]];
CFDictionaryAddValue(response, CFSTR(kTclStringEvaluationResult), (CFStringRef)result);
+
+ //Set the Tcl return code
+ CFDictionaryAddValue(response, CFSTR(kTclReturnCode), (CFNumberRef)retNum);
}
else {
retval = noErr;
result = [@"TCL COMMAND EXECUTION SUCCEEDED YAAY!:"
stringByAppendingString:[NSString stringWithUTF8String:Tcl_GetStringResult(interpreter)]];
CFDictionaryAddValue(response, CFSTR(kTclStringEvaluationResult), (CFStringRef)result);
+
+ //Set the Tcl return code
+ CFDictionaryAddValue(response, CFSTR(kTclReturnCode), (CFNumberRef)retNum);
}
assert(response != NULL);
-
return retval;
}
Modified: branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperToolTest.h
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperToolTest.h 2008-08-15 11:57:29 UTC (rev 39278)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperToolTest.h 2008-08-15 15:16:20 UTC (rev 39279)
@@ -16,7 +16,7 @@
MPInterpreter * interp;
}
--(void) testMPHelperToolWithoutRights;
+//-(void) testMPHelperToolWithoutRights;
@end
Modified: branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperToolTest.m
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperToolTest.m 2008-08-15 11:57:29 UTC (rev 39278)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperToolTest.m 2008-08-15 15:16:20 UTC (rev 39279)
@@ -19,24 +19,24 @@
}
-- (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");
-}
+//- (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");
+//}
+//
-
@end
Modified: branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreter.h
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreter.h 2008-08-15 11:57:29 UTC (rev 39278)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreter.h 2008-08-15 15:16:20 UTC (rev 39279)
@@ -64,10 +64,12 @@
#define MPMETHOD @"Method"
#define MPMESSAGE @"Message"
+//Error codes for helper Tool
+#define MPHELPINSTFAILED 0 /*Installation of helper tool failed*/
+#define MPHELPUSERCANCELLED 1 /*User cancelled privileged operation.*/
-
/*!
@class MPInterpreter
@abstract Tcl interpreter object
@@ -109,7 +111,7 @@
/*!
@brief Returns the NSString result of evaluating a Tcl expression
@param statement An NSString containing the Tcl expression
- @param mportError A reference pointer to the NSError object which will be used for error handling.
+ @param mportError A reference pointer to the NSError object which will be used for error handling; should not be nil.
@discussion Using the macports::getindex {source} procedure as an example we
have the following Objective-C form for calling the macports::getindex procedure:
@@ -118,7 +120,22 @@
*/
- (NSString *)evaluateStringAsString:(NSString *)statement error:(NSError **)mportError;
+/*!
+ @brief Returns the NSString result of evaluating a Tcl expression executed as root if necessary
+ @param statement An NSString containing the Tcl expression
+ @param mportError A reference pointer to the NSError object which will be used for error handling; should not be nil.
+ @discussion This method is almost identical to -evaluateStringAsString. The only difference is that
+ it re-evaluates the Tcl expression with root privileges if the first attempt at evaluation
+ returns an error due to insufficient privileges. The -sync, -selfupdate and port exec methods
+ use this method for their operations.
+
+ [SomeMPInterpreterObject evaluateStringAsString:
+ [NSString stringWithString:@"return [macports::mportselfupdate]"]];
+ */
+- (NSString *)evaluateStringWithPossiblePrivileges:(NSString *)statement error:(NSError **)mportError;
+
+
/*!
@brief Returns an NSArray whose elements are the the elements of a Tcl list in the form of an NSString
@param list A Tcl list in the form of an NSString
@@ -159,6 +176,6 @@
- (int) execute:(NSString *)pathToExecutable withArgs:(NSArray*)args;
- (void)setAuthorizationRef:(AuthorizationRef)authRef;
- (BOOL)checkIfAuthorized;
--(NSString *)evaluateStringWithMPHelperTool:(NSString *)statement;
+-(NSString *)evaluateStringWithMPHelperTool:(NSString *)statement error:(NSError **)mportError;
@end
Modified: branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreter.m
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreter.m 2008-08-15 11:57:29 UTC (rev 39278)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreter.m 2008-08-15 15:16:20 UTC (rev 39279)
@@ -78,7 +78,7 @@
if (tclResult == TCL_OK) {
- //I have sacrificed generality for simplicity in the code below
+ //I have sacrificed generality for simplicity in the code below
if (tclElements > 0) {
[info setObject:[NSString stringWithUTF8String:tclElements[0]] forKey:MPCHANNEL];
@@ -204,7 +204,7 @@
NSLog(@"Error in Tcl_PkgProvide: %s", Tcl_GetStringResult(_interpreter));
Tcl_DeleteInterp(_interpreter);
}
-
+
if( Tcl_EvalFile(_interpreter, [[[NSBundle bundleWithIdentifier:@"org.macports.frameworks.macports"]
pathForResource:@"init"
ofType:@"tcl"] UTF8String]) != TCL_OK) {
@@ -218,7 +218,7 @@
//Initialize the MacPorts Tcl Package Path string
tclInterpreterPkgPath = [NSString stringWithString:path];
-
+
}
return self;
}
@@ -274,48 +274,6 @@
#pragma Port Settings
#pragma Utilities
-- (NSString *)evaluateStringAsString:(NSString *)statement error:(NSError**)mportError{
- //NSLog(@"Calling evaluateStringAsString with argument %@", statement);
-
- int return_code = Tcl_Eval(_interpreter, [statement UTF8String]);
-
- //Should I check for (return_code != TCL_Ok && return_code != TCL_RETURN) instead ?
- if (return_code != TCL_OK) {
-
- Tcl_Obj * interpObj = Tcl_GetObjResult(_interpreter);
- int length, errCode;
- NSString * errString = [NSString stringWithUTF8String:Tcl_GetStringFromObj(interpObj, &length)];
- //NSLog(@"TclObj string is %@ with length %d", errString , length);
- errCode = Tcl_GetErrno();
- //NSLog(@"Errno Id is %@ with value %d", [NSString stringWithUTF8String:Tcl_ErrnoId()], errCode);
- //NSLog(@"Errno Msg is %@", [NSString stringWithUTF8String:Tcl_ErrnoMsg(errCode)]);
-
- //Handle errors here ... Framework users can do !mportError to find out if
- //method was successful
- NSString *descrip = NSLocalizedString(errString, @"");
- NSDictionary *errDict;
- //For now all error codes are TCL_ERROR
-
- //Create underlying error - For now I'll create the underlying Posix Error
- NSError *undError = [[[NSError alloc] initWithDomain:NSPOSIXErrorDomain
- code:errCode
- userInfo:nil] autorelease];
- //Create and return custom domain error
- NSArray *objArray = [NSArray arrayWithObjects:descrip, undError, nil];
- NSArray *keyArray = [NSArray arrayWithObjects:NSLocalizedDescriptionKey,
- NSUnderlyingErrorKey, nil];
- errDict = [NSDictionary dictionaryWithObjects:objArray forKeys:keyArray];
- if (mportError != NULL)
- *mportError = [[[NSError alloc] initWithDomain:MPFrameworkErrorDomain
- code:TCL_ERROR
- userInfo:errDict] autorelease];
- return nil;
- }
-
- return [NSString stringWithUTF8String:Tcl_GetStringResult(_interpreter)];
-}
-
-
- (NSArray *)arrayFromTclListAsString:(NSString *)list {
NSMutableArray *array;
int tclCount;
@@ -359,36 +317,83 @@
return [NSString stringWithUTF8String:Tcl_GetVar(_interpreter, [variable UTF8String], 0)];
}
+
#pragma mark -
-#pragma mark Authorization Code
+#pragma mark -evaluateString* routines
-- (BOOL)checkIfAuthorized {
- if (internalMacPortsAuthRef == NULL ) {
- return NO;
+- (NSString *)evaluateStringAsString:(NSString *)statement error:(NSError**)mportError{
+ //NSLog(@"Calling evaluateStringAsString with argument %@", statement);
+
+ int return_code = Tcl_Eval(_interpreter, [statement UTF8String]);
+
+ //Should I check for (return_code != TCL_Ok && return_code != TCL_RETURN) instead ?
+ if (return_code != TCL_OK) {
+
+ Tcl_Obj * interpObj = Tcl_GetObjResult(_interpreter);
+ int length, errCode;
+ NSString * errString = [NSString stringWithUTF8String:Tcl_GetStringFromObj(interpObj, &length)];
+ //NSLog(@"TclObj string is %@ with length %d", errString , length);
+ errCode = Tcl_GetErrno();
+ //NSLog(@"Errno Id is %@ with value %d", [NSString stringWithUTF8String:Tcl_ErrnoId()], errCode);
+ //NSLog(@"Errno Msg is %@", [NSString stringWithUTF8String:Tcl_ErrnoMsg(errCode)]);
+
+ //Handle errors here ... Framework users can do !mportError to find out if
+ //method was successful
+ NSString *descrip = NSLocalizedString(errString, @"");
+ NSDictionary *errDict;
+ //For now all error codes are TCL_ERROR
+
+ //Create underlying error - For now I'll create the underlying Posix Error
+ NSError *undError = [[[NSError alloc] initWithDomain:NSPOSIXErrorDomain
+ code:errCode
+ userInfo:nil] autorelease];
+ //Create and return custom domain error
+ NSArray *objArray = [NSArray arrayWithObjects:descrip, undError, nil];
+ NSArray *keyArray = [NSArray arrayWithObjects:NSLocalizedDescriptionKey,
+ NSUnderlyingErrorKey, nil];
+ errDict = [NSDictionary dictionaryWithObjects:objArray forKeys:keyArray];
+ if (mportError != NULL)
+ *mportError = [[[NSError alloc] initWithDomain:MPFrameworkErrorDomain
+ code:TCL_ERROR
+ userInfo:errDict] autorelease];
+ return nil;
}
- return YES;
+
+ return [NSString stringWithUTF8String:Tcl_GetStringResult(_interpreter)];
}
--(void)setAuthorizationRef:(AuthorizationRef)authRef {
- //I can do this since Framework client responsible
- //for managing memory for Authorization
- internalMacPortsAuthRef = authRef;
+- (NSString *)evaluateStringWithPossiblePrivileges:(NSString *)statement error:(NSError **)mportError {
+ //N.B. I am going to insist that funciton users not pass in nil for the
+ //mportError parameter
+ NSString * firstResult;
+ NSString * secondResult;
+
+ firstResult = [self evaluateStringAsString:statement error:mportError];
+
+ //Because of string results of methods like mportsync (which returns the empty string)
+ //the only way to truly check for an error is to check the mportError parameter.
+ //If it is nil then there was no error, if not we re-evaluate with privileges using
+ //the helper tool
+
+ if (mportError != nil) {
+ * mportError = nil;
+ secondResult = [self evaluateStringWithMPHelperTool:statement error:mportError];
+ return secondResult;
+ }
+
+ return firstResult;
}
-
-
-#pragma mark -
-#pragma mark For Internal Use
//NOTE: We expect the Framework client to initialize the AuthorizationRef
-//Completely before calling any privileged operation. Perhaps we
-//should check for this and send an NSError ... rather than go
-//through the trouble of initializing the call and erroring out?
-- (NSString *) evaluateStringWithMPHelperTool:(NSString *) statement {
+//Completely before calling any privileged operation. If not we will pass in
+//a barely initialzed one. This method returns nil if there is an error
+- (NSString *) evaluateStringWithMPHelperTool:(NSString *) statement error:(NSError **)mportError {
OSStatus err;
BASFailCode failCode;
NSString * bundleID;
NSDictionary * request;
CFDictionaryRef response;
+ NSString * result = nil;
response = NULL;
@@ -400,8 +405,8 @@
if (serverFileDesc < 0)
NSLog(@"Uninitialized file descriptor for HelperTool IPC");
-
+
request = [NSDictionary dictionaryWithObjectsAndKeys:
@kMPHelperEvaluateTclCommand, @kBASCommandKey,
statement, @kTclStringToBeEvaluated,
@@ -426,8 +431,14 @@
(CFStringRef) bundleID,
(CFDictionaryRef) request,
&response);
+ if (err == noErr){// retrieve result here if available
+ if( response != NULL)
+ result = (NSString *) (CFStringRef) CFDictionaryGetValue(response, CFSTR(kTclStringEvaluationResult));
+ }
+
+
//Try to recover
if ( (err != noErr) && (err != userCanceledErr) ) {
failCode = BASDiagnoseFailure(internalMacPortsAuthRef, (CFStringRef) bundleID);
@@ -436,7 +447,6 @@
//Need to pass in URL's to helper and install tools since I
//modified BASFixFaliure
NSBundle * mpBundle = [NSBundle bundleForClass:[self class]];
- //NSLog(@"mpBundle is %@", [mpBundle description]);
NSString * installToolPath = [mpBundle pathForResource:@"MPHelperInstallTool" ofType:nil];
assert(installToolPath != nil);
@@ -447,37 +457,126 @@
assert(helperToolPath != nil);
NSURL * helperToolURL = [NSURL fileURLWithPath:helperToolPath];
assert(helperToolURL != nil);
- //NSLog(@"Helper and Install tool URL's are \n %@ and \n %@ respectively",
- // [helperToolURL description] , [installToolURL description]);
-
err = BASFixFailure(internalMacPortsAuthRef,
(CFStringRef) bundleID,
(CFURLRef) installToolURL,
(CFURLRef) helperToolURL,
failCode);
+
+ //Making the following assumption in error handling. If we return
+ //a noErr then response cannot be nil since everything went ok.
+ //Hence I'm only checking for errors WITHIN the following blocks ...
if (err == noErr) {
err = BASExecuteRequestInHelperTool(internalMacPortsAuthRef,
kMPHelperCommandSet,
(CFStringRef) bundleID,
(CFDictionaryRef) request,
&response);
+ if (err == noErr){// retrieve result here if available
+ if( response != NULL)
+ result = (NSString *) (CFStringRef) CFDictionaryGetValue(response, CFSTR(kTclStringEvaluationResult));
+ }
+
+
+ //If we executed unsuccessfully
+ if (err != noErr) {
+ if (mportError != NULL) {
+ NSError * undError = [[[NSError alloc] initWithDomain:NSOSStatusErrorDomain
+ code:err
+ userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
+ NSLocalizedString(@"Check error code for OSStatus returned",@""),
+ NSLocalizedDescriptionKey,
+ nil]] autorelease];
+
+ *mportError = [[[NSError alloc] initWithDomain:MPFrameworkErrorDomain
+ code:MPHELPINSTFAILED
+ userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
+ NSLocalizedString(@"Unable to execute MPHelperTool successfuly", @""),
+ NSLocalizedDescriptionKey,
+ undError, NSUnderlyingErrorKey,
+ NSLocalizedString(@"BASExecuteRequestInHelperTool execution failed", @""),
+ NSLocalizedFailureReasonErrorKey,
+ nil]] autorelease];
+
+ }
+ }
}
+ else {//This means FixFaliure failed ... Report that in returned error
+ if (mportError != NULL) {
+ //I'm not sure of exactly how to report this error ...
+ //Do we need some error codes for our domain? I'll define one
+ NSError * undError = [[[NSError alloc] initWithDomain:NSOSStatusErrorDomain
+ code:err
+ userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
+ NSLocalizedString(@"Check error code for OSStatus returned",@""),
+ NSLocalizedDescriptionKey,
+ nil]] autorelease];
+
+ *mportError = [[[NSError alloc] initWithDomain:MPFrameworkErrorDomain
+ code:MPHELPINSTFAILED
+ userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
+ NSLocalizedString(@"Unable to fix faliure for MPHelperTool execution", @""),
+ NSLocalizedDescriptionKey,
+ undError, NSUnderlyingErrorKey,
+ NSLocalizedString(@"BASFixFaliure routine wasn't completed successfuly", @""),
+ NSLocalizedFailureReasonErrorKey,
+ nil]] autorelease];
+ }
+ }
}
else {
err = userCanceledErr;
+ if (mportError != NULL) {
+ NSError * undError = [[[NSError alloc] initWithDomain:NSOSStatusErrorDomain
+ code:err
+ userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
+ NSLocalizedString(@"Check error code for OSStatus returned",@""),
+ NSLocalizedDescriptionKey,
+ nil]] autorelease];
+
+ *mportError = [[[NSError alloc] initWithDomain:MPFrameworkErrorDomain
+ code:MPHELPUSERCANCELLED
+ userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
+ NSLocalizedString(@"MPHelperTool was not executed successfully", @""),
+ NSLocalizedDescriptionKey,
+ undError, NSUnderlyingErrorKey,
+ NSLocalizedString(@"User cancelled the operation", @""),
+ NSLocalizedFailureReasonErrorKey,
+ nil]] autorelease];
+ }
}
- assert(response != NULL);
- CFStringRef newresult = CFDictionaryGetValue(response, CFSTR(kTclStringEvaluationResult));
+
NSLog(@"AFTER Tool Execution request is %@ , response is %@ \n\n", request, response);
- //NSLog(@"response dictionary is %@", response);
- return (NSString *) newresult;
+
+ return result;
+}
+
+#pragma mark -
+#pragma mark Authorization Code
+
+- (BOOL)checkIfAuthorized {
+ if (internalMacPortsAuthRef == NULL ) {
+ return NO;
+ }
+ return YES;
}
+-(void)setAuthorizationRef:(AuthorizationRef)authRef {
+ //I can do this since Framework client responsible
+ //for managing memory for Authorization
+ internalMacPortsAuthRef = authRef;
+}
+
+
+
+#pragma mark -
+#pragma mark For Internal Use
+
- (int) execute:(NSString *)pathToExecutable withArgs:(NSArray *)args {
NSTask * task = [[NSTask alloc] init];
[task setLaunchPath:pathToExecutable];
Modified: branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreterTest.h
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreterTest.h 2008-08-15 11:57:29 UTC (rev 39278)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreterTest.h 2008-08-15 15:16:20 UTC (rev 39279)
@@ -43,9 +43,7 @@
- (void)testInitialization;
- (void)testGetVariableAsArray;
-//- (void)testMPHelperTool;
-//- (void)testMutableDictionaryFromTclListAsString;
//- (void)testEvaluateStringAsString;
+//- (void)testGetVariableAsString;
-
@end
Added: branches/gsoc08-framework/MacPorts_Framework_Release/MPPortManipulationTest.h
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/MPPortManipulationTest.h (rev 0)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/MPPortManipulationTest.h 2008-08-15 15:16:20 UTC (rev 39279)
@@ -0,0 +1,23 @@
+//
+// MPPortManipulationTest.h
+// MacPorts.Framework
+//
+// Created by George Armah on 8/14/08.
+// Copyright 2008 Lafayette College. All rights reserved.
+//
+
+
+//This test class is very important. It is going to test all the basic
+//important port manipuation routines e.g. searching, installing, activation,
+//deactivation, finding dependencies etc. etc.
+
+
+#import <SenTestingKit/SenTestingKit.h>
+#import <MacPorts/MacPorts.h>
+
+ at interface MPPortManipulationTest : SenTestCase {
+ MPMacPorts * mainPort;
+}
+
+-(void) testSimpleSearch;
+ at end
Property changes on: branches/gsoc08-framework/MacPorts_Framework_Release/MPPortManipulationTest.h
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: branches/gsoc08-framework/MacPorts_Framework_Release/MPPortManipulationTest.m
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/MPPortManipulationTest.m (rev 0)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/MPPortManipulationTest.m 2008-08-15 15:16:20 UTC (rev 39279)
@@ -0,0 +1,39 @@
+//
+// MPPortManipulationTest.m
+// MacPorts.Framework
+//
+// Created by George Armah on 8/14/08.
+// Copyright 2008 Lafayette College. All rights reserved.
+//
+
+#import "MPPortManipulationTest.h"
+
+
+
+ at implementation MPPortManipulationTest
+
+-(void) setUp {
+ mainPort = [MPMacPorts sharedInstance];
+}
+
+-(void) tearDown {
+
+}
+
+-(void) testSimpleSearch {
+ NSDictionary * searchResult = [mainPort search:@"sphinx"];
+ NSLog(@"\n\nPrinting search results for \"sphinx\"");
+
+ NSLog(@" %@ ", [searchResult allKeys]);
+ NSLog(@" %@ ", [searchResult allValues]);
+
+ id key;
+ NSEnumerator * k = [searchResult keyEnumerator];
+ while ( key = [k nextObject]) {
+ NSLog(@"\n\n Key: %@ \n\n MPPort object: %@ \n\n", key, [searchResult objectForKey:key]);
+ }
+
+ NSLog(@"\n\nDone searching for \"sphinx\"\n\n");
+}
+
+ at end
Property changes on: branches/gsoc08-framework/MacPorts_Framework_Release/MPPortManipulationTest.m
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: branches/gsoc08-framework/MacPorts_Framework_Release/MacPorts.Framework.xcodeproj/project.pbxproj
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/MacPorts.Framework.xcodeproj/project.pbxproj 2008-08-15 11:57:29 UTC (rev 39278)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/MacPorts.Framework.xcodeproj/project.pbxproj 2008-08-15 15:16:20 UTC (rev 39279)
@@ -40,6 +40,7 @@
48E9939F0C82CEB000219DDF /* init.tcl in Resources */ = {isa = PBXBuildFile; fileRef = 48E9939E0C82CEB000219DDF /* init.tcl */; };
6E270D090E158CED00BAE687 /* MPNotifications.h in Headers */ = {isa = PBXBuildFile; fileRef = 6E270D070E158CED00BAE687 /* MPNotifications.h */; settings = {ATTRIBUTES = (Public, ); }; };
6E270D0A0E158CED00BAE687 /* MPNotifications.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E270D080E158CED00BAE687 /* MPNotifications.m */; };
+ 6E3345350E54AF14008A2F6C /* MPPortManipulationTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E3345340E54AF14008A2F6C /* MPPortManipulationTest.m */; };
6E44A00D0E2DAD66007DE8EC /* ToDo.txt in Resources */ = {isa = PBXBuildFile; fileRef = 6E44A00C0E2DAD66007DE8EC /* ToDo.txt */; };
6E49F37B0DFFAB0B0030C3AF /* MPInterpreterTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 489DD92E0C94674B00595506 /* MPInterpreterTest.m */; };
6E49F37F0DFFAFF80030C3AF /* MacPorts.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* MacPorts.framework */; };
@@ -124,6 +125,8 @@
48F811BF0CE4638C009630DE /* MPRegistry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPRegistry.m; sourceTree = "<group>"; };
6E270D070E158CED00BAE687 /* MPNotifications.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPNotifications.h; sourceTree = "<group>"; };
6E270D080E158CED00BAE687 /* MPNotifications.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPNotifications.m; sourceTree = "<group>"; };
+ 6E3345330E54AF14008A2F6C /* MPPortManipulationTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPPortManipulationTest.h; sourceTree = "<group>"; };
+ 6E3345340E54AF14008A2F6C /* MPPortManipulationTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPPortManipulationTest.m; sourceTree = "<group>"; };
6E44A00C0E2DAD66007DE8EC /* ToDo.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ToDo.txt; sourceTree = "<group>"; };
6E88D1CA0DF4B90B00684E9F /* MPMacPortsTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPMacPortsTest.h; sourceTree = "<group>"; };
6E88D1CB0DF4B90B00684E9F /* MPMacPortsTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPMacPortsTest.m; sourceTree = "<group>"; };
@@ -316,6 +319,8 @@
6E88D1CB0DF4B90B00684E9F /* MPMacPortsTest.m */,
6ECD99C40E48B91B00488335 /* MPHelperToolTest.h */,
6ECD99C50E48B91B00488335 /* MPHelperToolTest.m */,
+ 6E3345330E54AF14008A2F6C /* MPPortManipulationTest.h */,
+ 6E3345340E54AF14008A2F6C /* MPPortManipulationTest.m */,
);
name = Tests;
sourceTree = "<group>";
@@ -557,6 +562,7 @@
6EA294590E080DEB00902D12 /* MPMacPortsTest.m in Sources */,
6E49F37B0DFFAB0B0030C3AF /* MPInterpreterTest.m in Sources */,
6ECD99C60E48B91B00488335 /* MPHelperToolTest.m in Sources */,
+ 6E3345350E54AF14008A2F6C /* MPPortManipulationTest.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Modified: branches/gsoc08-framework/MacPorts_Framework_Release/MacPorts.h
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/MacPorts.h 2008-08-15 11:57:29 UTC (rev 39278)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/MacPorts.h 2008-08-15 15:16:20 UTC (rev 39279)
@@ -42,5 +42,3 @@
//Including this file for testing the Notifications listener
#import <MacPorts/MPNotifications.h>;
-//for testing Distributed objects
-#import <MacPorts/MPInterpreterProtocol.h>;
Modified: branches/gsoc08-framework/MacPorts_Framework_Release/ToDo.txt
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/ToDo.txt 2008-08-15 11:57:29 UTC (rev 39278)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/ToDo.txt 2008-08-15 15:16:20 UTC (rev 39279)
@@ -1,27 +1,31 @@
TO DO LIST (because there seems to be too much to get done haha)
+Guide like documentation
+Scrub Code
-Get feedback on Notifications idea and implementation
+Ask Randall to look at perform exec methods
+Implement IPC Notifications mechanism between the Helper Tool and Framework
-Test Notifications Library ... how? ... use the Tester ...
-and see if the rest of the tests build
+Modify evaluateStringAsString to try evaluating, try evaluating with privileges
+if there is an error, then return if there is still an error for the special
+privileged methods: sync, selfupdate, exec methods etc.
-Create my own branch of src ? Yes ... do that and add your patches
+Reimplement notifications so that, as Randall said, all threads should receive
+all notifications that they have registered for
-Guide like documentation
+... in coming ... rant ...
+I am thinking of another scheme instead of notifications ... I don't think
+Objective-C has high order functions ... but something cool would be for
+us to just call some user defined method when a $ui_priority
+call is made. So if say they wanted to update a progress bar during
+-sync, we would just be calling whatever method they had to update the GUI.
-Scrub Code
+I should read up some on Threading cause that might make things dicey ...
-Sanitize NSString Code
+Also, we could throw in bindings support. How would this work? Don't know
+yet ...
-Ask Randall to look at perform exec methods
-Rearrange methods orderings in both .h and .m files
-and add appropriate pragma marks for more readablity
-
-
-ASK FOR HOW TO TURN ON / OFF VARIOUS MODES FOR UI_$PRIORITY I.E.
-DEBUG, INFO ETC.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20080815/8831e38a/attachment-0001.html
More information about the macports-changes
mailing list