Revision: 70194 http://trac.macports.org/changeset/70194 Author: tzikis@macports.org Date: 2010-08-01 08:19:14 -0700 (Sun, 01 Aug 2010) Log Message: ----------- Moved the conflicts and default_variants fetching from the GUI to the port. variants selection/installation complete Modified Paths: -------------- branches/gsoc10-gui/MacPorts_Framework/MPPort.h branches/gsoc10-gui/MacPorts_Framework/MPPort.m branches/gsoc10-gui/Pallet/MPActionsController.h branches/gsoc10-gui/Pallet/MPActionsController.m Modified: branches/gsoc10-gui/MacPorts_Framework/MPPort.h =================================================================== --- branches/gsoc10-gui/MacPorts_Framework/MPPort.h 2010-08-01 12:04:15 UTC (rev 70193) +++ branches/gsoc10-gui/MacPorts_Framework/MPPort.h 2010-08-01 15:19:14 UTC (rev 70194) @@ -149,6 +149,16 @@ /*! + @brief Computes the NSMutableArray object for key "defaults_variants" of the port + */ +- (void)checkDefaults; + +/*! + @brief Computes the conflicts of the port + */ +- (void)checkConflicts; + +/*! @brief Executes the specified target for this MPPort @param target NSString target to be executed for this MPPort @param options An NSArray of NSStrings for the various options for this target Modified: branches/gsoc10-gui/MacPorts_Framework/MPPort.m =================================================================== --- branches/gsoc10-gui/MacPorts_Framework/MPPort.m 2010-08-01 12:04:15 UTC (rev 70193) +++ branches/gsoc10-gui/MacPorts_Framework/MPPort.m 2010-08-01 15:19:14 UTC (rev 70194) @@ -388,7 +388,105 @@ - (void)upgradeWithError:(NSError **)mError { [self execPortProc:@"mportupgrade" withOptions:nil version:@"" error:mError]; } +- (void)checkDefaults +{ + //Check for default variants only if this is the first time we are checking + if ([self objectForKey:@"default_variants"] == nil) + { + //NSArray *defaultVariants = [port valueForKey:@"defaultVariants"]; + NSMutableArray *defaultVariants= [NSMutableArray arrayWithCapacity:10]; + char port_command[256]; + + //Build the port variants command + strcpy(port_command, "port variants "); + strcat(port_command, [[self objectForKey:@"name"] cStringUsingEncoding: NSASCIIStringEncoding]); + strcat(port_command, " | grep \"\\[+]\" | sed 's/.*\\]//; s/:.*//' >> mpfw_default_variants"); + + //Make the CLI call + system(port_command); + //Open the output file + FILE * file = fopen("mpfw_default_variants", "r"); + + //Read all default_variants + char buffer[256]; + while(!feof(file)) + { + char * temp = fgets(buffer,256,file); + if(temp == NULL) continue; + buffer[strlen(buffer)-1]='\0'; + //Add the variant in the Array + [defaultVariants addObject:[NSString stringWithCString:buffer]]; + } + //Close and delete + fclose(file); + unlink("mpfw_default_variants"); + + NSLog(@"Default variants count: %i", [defaultVariants count]); + //Code for fetching default variants + [self setObject:[NSString stringWithString:[defaultVariants componentsJoinedByString:@" "]] forKey:@"default_variantsAsString"]; + [self setObject:defaultVariants forKey:@"default_variants"]; + } +} + +- (void)checkConflicts; +{ + //Check for only if this is the first time we are checking + if ([self objectForKey:@"conflicts"] == nil) + { + + NSMutableArray *conflicts = [NSMutableArray arrayWithCapacity:20]; + + char *script= " | python -c \"import re,sys;lines=sys.stdin.readlines();print '\\n'.join('%s,%s' % (re.sub(r'[\\W]','',lines[i-1].split()[0].rstrip(':')),','.join(l.strip().split()[3:])) for i, l in enumerate(lines) if l.strip().startswith('* conflicts'))\" >> /tmp/mpfw_conflict"; + char command[512]; + strcpy(command,"port variants "); + strcat(command, [[self name] UTF8String]); + strcat(command, script); + //printf("\n%s\n", command); + system(command); + + //Open the output file + FILE * file = fopen("/tmp/mpfw_conflict", "r"); + + //Read all conflicts + char buffer[256]; + while(!feof(file)) + { + char * temp = fgets(buffer,256,file); + if(temp == NULL) continue; + buffer[strlen(buffer)-1]='\0'; + //Add the variant in the Array + //printf("buffer:\n%s\n",buffer); + + char *token; + char *search = ","; + + token = strtok(buffer, search); + //printf("token: %s\n",token); + if(token == NULL) break; + + NSString *variant = [NSString stringWithCString:token]; + NSMutableArray *conflictsWith=[NSMutableArray arrayWithCapacity:10]; + NSLog(@"%@", variant); + while ((token = strtok(NULL, search)) != NULL) + { + NSLog(@"token: %@",[NSString stringWithCString:token]); + [conflictsWith addObject:[NSString stringWithCString:token]]; + //NSLog(@"count %i",[[checkboxes[i] conflictsWith] count]); + } + + NSDictionary *variantConflictsWith = [NSDictionary dictionaryWithObject:conflictsWith forKey:variant]; + [conflicts addObject:variantConflictsWith]; + //[defaultVariants addObject:[NSString stringWithCString:buffer]]; + } + //Close and delete + fclose(file); + unlink("/tmp/mpfw_conflict"); + + [self setObject:conflicts forKey:@"conflicts"]; + } +} + -(void)configureWithOptions:(NSArray *)options variants:(NSArray *)variants error:(NSError **)mError { [self exec:@"configure" withOptions:options variants:variants error:mError]; } Modified: branches/gsoc10-gui/Pallet/MPActionsController.h =================================================================== --- branches/gsoc10-gui/Pallet/MPActionsController.h 2010-08-01 12:04:15 UTC (rev 70193) +++ branches/gsoc10-gui/Pallet/MPActionsController.h 2010-08-01 15:19:14 UTC (rev 70194) @@ -60,7 +60,7 @@ - (IBAction)toggleInfoPanel: (id) sender; -(IBAction)clickCheckbox:(id)sender; --(void)checkConflicts: (NSString*) portName; +-(void)setConflicts: (MPPort*) port; - (void)queueOperation: (NSString*) operation portName: (NSString*) name portObject: (id) port variants: (NSMutableArray*) variants; Modified: branches/gsoc10-gui/Pallet/MPActionsController.m =================================================================== --- branches/gsoc10-gui/Pallet/MPActionsController.m 2010-08-01 12:04:15 UTC (rev 70193) +++ branches/gsoc10-gui/Pallet/MPActionsController.m 2010-08-01 15:19:14 UTC (rev 70194) @@ -97,35 +97,10 @@ [checkboxes[i] setAlphaValue:0]; } //NSLog(@"Port variants:"); + //Call checkDefaults to compute the NSMutableArray for key default_variants + [port checkDefaults]; + NSMutableArray *defaultVariants= [port objectForKey:@"default_variants"]; - //NSArray *defaultVariants = [port valueForKey:@"defaultVariants"]; - NSMutableArray *defaultVariants= [NSMutableArray arrayWithCapacity:10]; - char port_command[256]; - - //Build the port variants command - strcpy(port_command, "port variants "); - strcat(port_command, [[port objectForKey:@"name"] cStringUsingEncoding: NSASCIIStringEncoding]); - strcat(port_command, " | grep \"\\[+]\" | sed 's/.*\\]//; s/:.*//' >> mpfw_default_variants"); - - //Make the CLI call - system(port_command); - //Open the output file - FILE * file = fopen("mpfw_default_variants", "r"); - - //Read all default_variants - char buffer[256]; - while(!feof(file)) - { - char * temp = fgets(buffer,256,file); - if(temp == NULL) continue; - buffer[strlen(buffer)-1]='\0'; - //Add the variant in the Array - [defaultVariants addObject:[NSString stringWithCString:buffer]]; - } - //Close and delete - fclose(file); - unlink("mpfw_default_variants"); - NSLog(@"Default variants count: %i", [defaultVariants count]); for(UInt i=0; i<[[port valueForKey:@"variants"] count];i++) { @@ -153,8 +128,7 @@ } //NSLog(@"End of Variants"); - - [self checkConflicts:[port valueForKey:@"name"]]; + [self setConflicts:port]; [variantsPanel makeKeyAndOrderFront:self]; @@ -304,63 +278,26 @@ } --(void)checkConflicts: (NSString *) portName -{ +-(void)setConflicts: (MPPort *) port +{ + //Initialize the conflicts NSMutableArray for the port, if it wasn't already initialized + [port checkConflicts]; + + NSArray *conflicts = [port objectForKey:@"conflicts"]; - char *script= " | python -c \"import re,sys;lines=sys.stdin.readlines();print '\\n'.join('%s,%s' % (re.sub(r'[\\W]','',lines[i-1].split()[0].rstrip(':')),','.join(l.strip().split()[3:])) for i, l in enumerate(lines) if l.strip().startswith('* conflicts'))\" >> /tmp/mpfw_conflict"; - char command[512]; - strcpy(command,"port variants "); - strcat(command, [portName UTF8String]); - strcat(command, script); - //printf("\n%s\n", command); - system(command); - - //Open the output file - FILE * file = fopen("/tmp/mpfw_conflict", "r"); - - //Read all default_variants - char buffer[256]; - while(!feof(file)) + for(UInt j=0; j< [conflicts count];j++) { - char * temp = fgets(buffer,256,file); - if(temp == NULL) continue; - buffer[strlen(buffer)-1]='\0'; - //Add the variant in the Array - //printf("buffer:\n%s\n",buffer); - - char *token; - char *search = ","; - - token = strtok(buffer, search); - //printf("token: %s\n",token); - if(token == NULL) break; - UInt i; - for(i=0; i<10; i++) + for( i=0; i<10; i++) { - //NSLog(@"%@ %@",[checkboxes[i] title], [NSString stringWithCString:token]); - - if ([[checkboxes[i] title] isEqualToString:[NSString stringWithCString:token]]) + if ([[conflicts objectAtIndex:j] objectForKey:[checkboxes[i] title]] != nil) { break; } - } - [checkboxes[i] setConflictsWith:[NSMutableArray array]]; - NSLog(@"checkbox: %i",i); - while ((token = strtok(NULL, search)) != NULL) - { - //NSLog(@"token: %@",[NSString stringWithCString:token]); - [[checkboxes[i] conflictsWith] addObject:[NSString stringWithCString:token]]; - //NSLog(@"count %i",[[checkboxes[i] conflictsWith] count]); - } - - //[defaultVariants addObject:[NSString stringWithCString:buffer]]; + } + //NSLog(@"checkbox that conflicts: %@", [checkboxes[i] title]); + [checkboxes[i] setConflictsWith:[[conflicts objectAtIndex:j] objectForKey:[checkboxes[i] title]]]; } - //Close and delete - fclose(file); - unlink("/tmp/mpfw_conflict"); - - } -(BOOL)validateToolbarItem:(NSToolbarItem *)toolbarItem {