[30968] users/rhwood/MacPorts.Framework
source_changes at macosforge.org
source_changes at macosforge.org
Mon Nov 12 06:50:42 PST 2007
Revision: 30968
http://trac.macosforge.org/projects/macports/changeset/30968
Author: rhwood at macports.org
Date: 2007-11-12 06:50:41 -0800 (Mon, 12 Nov 2007)
Log Message:
-----------
Refactor the MPIndex and MPPort classes to reduce resource consumption when initializing objects and to handle installation receipts on demand:
1. Post notifications when generating an index.
1. Add a "state" MPPortStateLearnState which when set for an MPPort, causes it to calculate its state
1. Remove code reading PortIndex files in favor of loading the ports list using the [MPMacPorts search] method. This reduces the number of calls against the Tcl API from 5 + number of ports available to 2 + the number of installed ports, ensures that all MPPort objects are complete, and reduces complexity of the code.
1. A couple on convenience methods have been created to support the refactoring because they might be useful in other situations.
Modified Paths:
--------------
users/rhwood/MacPorts.Framework/MPConstants.h
users/rhwood/MacPorts.Framework/MPIndex.h
users/rhwood/MacPorts.Framework/MPIndex.m
users/rhwood/MacPorts.Framework/MPPort.h
users/rhwood/MacPorts.Framework/MPPort.m
Modified: users/rhwood/MacPorts.Framework/MPConstants.h
===================================================================
--- users/rhwood/MacPorts.Framework/MPConstants.h 2007-11-12 14:38:56 UTC (rev 30967)
+++ users/rhwood/MacPorts.Framework/MPConstants.h 2007-11-12 14:50:41 UTC (rev 30968)
@@ -12,8 +12,9 @@
#define MPPortsAll @".+"
-#define MPPortStateUnknown 0
-#define MPPortStateActive 1
+#define MPPortStateLearnState 5
+#define MPPortStateUnknown 0
+#define MPPortStateActive 1
#define MPPortStateInstalled 2
-#define MPPortStateOutdated 3
+#define MPPortStateOutdated 3
#define MPPortStateNotInstalled 4
\ No newline at end of file
Modified: users/rhwood/MacPorts.Framework/MPIndex.h
===================================================================
--- users/rhwood/MacPorts.Framework/MPIndex.h 2007-11-12 14:38:56 UTC (rev 30967)
+++ users/rhwood/MacPorts.Framework/MPIndex.h 2007-11-12 14:50:41 UTC (rev 30968)
@@ -37,6 +37,8 @@
#import "MPMacPorts.h"
#import "MPPort.h"
+#define MPIndexWillSetIndex @"org.macports.framework.index.willSetIndex"
+#define MPIndexDidSetIndex @"org.macports.framework.index.didSetIndex"
@interface MPIndex : MPMutableDictionary {
@@ -46,7 +48,6 @@
- (NSArray *)portNames;
- (void)setIndex;
-- (void)addEntriesFromPortIndex:(NSString *)portIndex;
- (MPPort *)port:(NSString *)name;
- (NSEnumerator *)portEnumerator;
Modified: users/rhwood/MacPorts.Framework/MPIndex.m
===================================================================
--- users/rhwood/MacPorts.Framework/MPIndex.m 2007-11-12 14:38:56 UTC (rev 30967)
+++ users/rhwood/MacPorts.Framework/MPIndex.m 2007-11-12 14:50:41 UTC (rev 30968)
@@ -58,34 +58,30 @@
[super dealloc];
}
+/*
+ * We enumerate the list of ports, adding each port object to our own dictionary instead of simply copying the
+ * source dictionary in since we want to explicitely set the port state to uninstalled instead of the default
+ * state of unknown.
+ *
+ * After that we enumerate through the list of installation reciepts and set the port states for in the installed
+ * ports as installed, active, or outdated as appropriate
+ */
- (void)setIndex {
- NSEnumerator *portIndexEnumerator;
- NSString *portIndex;
- MPMacPorts *macPorts;
- macPorts = [MPMacPorts sharedInstance];
- [self removeAllObjects];
- portIndexEnumerator = [[macPorts sources] objectEnumerator];
- while (portIndex = [portIndexEnumerator nextObject]) {
- [self addEntriesFromPortIndex:portIndex];
+ NSDictionary *ports;
+ NSEnumerator *enumerator;
+ id port;
+ [[NSNotificationCenter defaultCenter] postNotificationName:MPIndexWillSetIndex object:nil];
+ ports = [[MPMacPorts sharedInstance] search:MPPortsAll];
+ enumerator = [ports keyEnumerator];
+ while (port = [enumerator nextObject]) {
+ [self setPort:[ports objectForKey:port]];
}
-}
-
-- (void)addEntriesFromPortIndex:(NSString *)portIndex {
- NSString* file;
- NSArray* lines;
- NSEnumerator* linesEnumerator;
- id line;
- MPMacPorts *macPorts;
- macPorts = [MPMacPorts sharedInstance];
- file = [[NSString alloc] initWithContentsOfFile:[macPorts pathToPortIndex:portIndex]];
- lines = [file componentsSeparatedByString:@"\n"];
- linesEnumerator = [lines objectEnumerator];
- while (line = [linesEnumerator nextObject]) {
- // if there are only two token (a portname and a number) we don't want to deal with it
- if ([[line componentsSeparatedByString:@" "] count] > 2) {
- [self setPort:[[MPPort alloc] initWithTclListAsString:line]];
- }
+ ports = [[MPRegistry sharedRegistry] installed];
+ enumerator = [ports keyEnumerator];
+ while (port = [enumerator nextObject]) {
+ [[self objectForKey:port] setStateFromReceipts:[ports objectForKey:port]];
}
+ [[NSNotificationCenter defaultCenter] postNotificationName:MPIndexDidSetIndex object:self];
}
- (NSArray *)ports {
@@ -109,6 +105,7 @@
}
- (void)setPort:(MPPort *)port {
+ [port setState:MPPortStateNotInstalled];
[self setObject:port forKey:[port name]];
}
Modified: users/rhwood/MacPorts.Framework/MPPort.h
===================================================================
--- users/rhwood/MacPorts.Framework/MPPort.h 2007-11-12 14:38:56 UTC (rev 30967)
+++ users/rhwood/MacPorts.Framework/MPPort.h 2007-11-12 14:50:41 UTC (rev 30968)
@@ -61,6 +61,7 @@
- (void) setPortWithTclListAsString:(NSString *)string;
- (void) addDependencyAsPortName:(NSString *)dependency;
- (void)setState:(int)state;
+- (void)setStateFromReceipts:(NSArray *)receipts;
- (void)setDictionary:(NSDictionary *)otherDictionary;
Modified: users/rhwood/MacPorts.Framework/MPPort.m
===================================================================
--- users/rhwood/MacPorts.Framework/MPPort.m 2007-11-12 14:38:56 UTC (rev 30967)
+++ users/rhwood/MacPorts.Framework/MPPort.m 2007-11-12 14:50:41 UTC (rev 30968)
@@ -69,17 +69,8 @@
- (void) setPortWithTclListAsString:(NSString *)string {
MPInterpreter *interpreter;
- MPRegistry *registry;
- NSArray *installed;
- NSEnumerator *installedEnumerator;
- id item;
interpreter = [MPInterpreter sharedInterpreter];
- registry = [MPRegistry sharedRegistry];
- NSString *installedVersion;
- NSString *activeVersion;
-
[self setDictionary:[interpreter dictionaryFromTclListAsString:string]];
-
// for each of the following properties:
// create strings for tokenizable properties to facilitate rapid searching
// tokenize the properties
@@ -123,29 +114,8 @@
@"Error statement for exception raised when testing long_description.")]
forKey:@"long_description"];
}
- // generate a composite version string: version_revision
- [self setValue:[[[self valueForKey:@"version"] stringByAppendingString:@"_"] stringByAppendingString:[self valueForKey:@"revision"]] forKey:@"compositeVersion"];
// set the status flag to unknown
[self setState:MPPortStateUnknown];
- installed = [[registry installed:[self valueForKey:@"name"]] valueForKey:[self valueForKey:@"name"]];
- // the following logic is flawed - it makes the assuption that if the active version is not equal to the
- // version in the PortIndex that the port is outdated + I don't know that this logic works at all on
- // direct installs
- if (installed) {
- [self setState:MPPortStateInstalled];
- installedEnumerator = [installed objectEnumerator];
- while (item = [installedEnumerator nextObject]) {
- if ([item valueForKey:@"active"]) {
- [self setState:MPPortStateActive];
- [self setObject:item forKey:@"activeReceipt"];
- if (![[item valueForKey:@"compositeVersion"] isEqualToString:[self valueForKey:@"compositeVersion"]]) {
- [self setState:MPPortStateOutdated];
- }
- }
- }
- } else {
- [self setState:MPPortStateNotInstalled];
- }
}
- (void)addDependencyAsPortName:(NSString *)dependency {
@@ -180,15 +150,58 @@
#pragma MPMutableDictionary Protocal
+- (id)objectForKey:(id)aKey {
+ if ([aKey isEqualToString:@"receipts"] && ![super objectForKey:aKey]) {
+ [self setObject:[[[MPRegistry sharedRegistry] installed:[self objectForKey:@"name"]] objectForKey:[self objectForKey:@"name"]]forKey:aKey];
+ }
+ return [super objectForKey:aKey];
+}
+
- (void)setDictionary:(NSDictionary *)otherDictionary {
[super setDictionary:otherDictionary];
[self setState:MPPortStateUnknown];
}
- (void)setState:(int)state {
- [self setObject:[NSNumber numberWithInt:state] forKey:@"state"];
+ id receipt;
+ NSEnumerator *receiptsEnumerator;
+ switch (state) {
+ case MPPortStateLearnState:
+ if ([self objectForKey:@"receipts"]) {
+ receiptsEnumerator = [[self objectForKey:@"receipts"] objectEnumerator];
+ // the following logic is flawed - it makes the assuption that if the active version is not equal to the
+ // version in the PortIndex that the port is outdated + I don't know that this logic works at all on
+ // direct installs
+ [self setState:MPPortStateInstalled];
+ while (receipt = [receiptsEnumerator nextObject]) {
+ if ([receipt valueForKey:@"active"]) {
+ [self setState:MPPortStateActive];
+ [self setObject:receipt forKey:@"active"];
+ if (![[receipt valueForKey:@"compositeVersion"] isEqualToString:[self valueForKey:@"compositeVersion"]]) {
+ [self setState:MPPortStateOutdated];
+ }
+ }
+ }
+ } else {
+ [self setState:MPPortStateNotInstalled];
+ }
+ break;
+ case MPPortStateUnknown:
+ [self removeObjectForKey:@"active"];
+ [self removeObjectForKey:@"receipts"];
+ [super setObject:[NSNumber numberWithInt:MPPortStateUnknown] forKey:@"state"];
+ break;
+ default:
+ [super setObject:[NSNumber numberWithInt:state] forKey:@"state"];
+ break;
+ }
}
+- (void)setStateFromReceipts:(NSArray *)receipts {
+ [self setObject:receipts forKey:@"receipts"];
+ [self setState:MPPortStateLearnState];
+}
+
- (Class)classForKeyedArchiver {
return [MPPort class];
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20071112/9ff748e4/attachment.html
More information about the macports-changes
mailing list