From f045996ac6d6c6c92d9972ccacb52acef7204e8d Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Fri, 7 Oct 2011 15:27:41 +0000 Subject: [PATCH] Converted teststrings into a tool Monotone-Parent: ae0c0cd3dbc947562a3dbd28f513f46bcd28a5b4 Monotone-Revision: f6ec5191473f90384de5c3301569150128a2ae63 Monotone-Author: ludovic@Sophos.ca Monotone-Date: 2011-10-07T15:27:41 Monotone-Branch: ca.inverse.sogo --- GNUmakefile | 3 +- Main/GNUmakefile | 3 +- Main/SOGo.h | 1 + Main/SOGo.m | 117 +++++++++++++++++++++++++++++++ Tests/Integration/GNUmakefile | 21 ++---- Tests/Integration/teststrings.sh | 4 +- 6 files changed, 129 insertions(+), 20 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index af8be3570..bf7c13528 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -10,6 +10,7 @@ SUBPROJECTS = \ SoObjects \ Main \ UI \ - Tools + Tools \ + Bundles/Sample include $(GNUSTEP_MAKEFILES)/aggregate.make diff --git a/Main/GNUmakefile b/Main/GNUmakefile index 382776728..329d12909 100644 --- a/Main/GNUmakefile +++ b/Main/GNUmakefile @@ -4,9 +4,10 @@ include ../config.make include $(GNUSTEP_MAKEFILES)/common.make include ../Version -ADDITIONAL_INCLUDE_DIRS += +ADDITIONAL_INCLUDE_DIRS += -I/usr/include/python2.6/ ADDITIONAL_LIB_DIRS += -L../SOPE/GDLContentStore/obj/ ADDITIONAL_LDFLAGS += -Wl,--no-as-needed +ADDITIONAL_LDFLAGS += -lpython2.6 SOGOD = sogod TOOL_NAME = $(SOGOD) diff --git a/Main/SOGo.h b/Main/SOGo.h index 02bce3c4c..25c3f878d 100644 --- a/Main/SOGo.h +++ b/Main/SOGo.h @@ -33,6 +33,7 @@ @interface SOGo : SoApplication { + NSMutableArray *bundles; SOGoCache *cache; } diff --git a/Main/SOGo.m b/Main/SOGo.m index 7b0bf80aa..658c2fd86 100644 --- a/Main/SOGo.m +++ b/Main/SOGo.m @@ -25,6 +25,8 @@ #import #import #import +#import +#import #import #import #import @@ -65,6 +67,8 @@ #import #import +#include + #import "NSException+Stacktrace.h" #import "SOGo.h" @@ -147,6 +151,116 @@ static BOOL debugLeaks; [[SOGoProductLoader productLoader] loadAllProducts]; } +- (void) _loadBundles +{ + NSFileManager *aFileManager; + NSMutableArray *allPaths; + NSArray *allFiles; + NSString *aPath; + int i, j; + + bundles = [[NSMutableArray alloc] init]; + + aFileManager = [NSFileManager defaultManager]; + allPaths = [[NSMutableArray alloc] initWithArray: NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, + NSLocalDomainMask| + NSNetworkDomainMask| + NSSystemDomainMask| + NSUserDomainMask, + YES)]; + for (i = 0; i < [allPaths count]; i++) + { + // We remove any potential duplicate paths in our allPaths array. + [allPaths removeObject: [allPaths objectAtIndex: i] inRange: NSMakeRange(i+1, [allPaths count]-i-1)]; + + aPath = [NSString stringWithFormat: @"%@/SOGo", [allPaths objectAtIndex: i]]; + allFiles = [aFileManager directoryContentsAtPath: aPath]; + + for (j = 0; j < [allFiles count]; j++) + { + NSString *aString; + + aString = [allFiles objectAtIndex: j]; + + // If we found a bundle, let's load it! + if ([[aString pathExtension] isEqualToString: @"bundle"]) + { + NSBundle *aBundle; + NSString *path; + + path = [NSString stringWithFormat: @"%@/%@", aPath, aString]; + aBundle = [NSBundle bundleWithPath: path]; + + if (aBundle) + { + PyObject *pName, *pModule; + NSString *ppath; + + NSLog(@"Loaded bundle at path %@ successfully...", path); + + // We add that path to the PYTHONPATH environment + ppath = [NSString stringWithFormat: @"%@/Resources/:%s", path, getenv("PYTHONPATH")]; + NSLog(@"Setting environment to %@", ppath); + setenv("PYTHONPATH", [ppath UTF8String], 1); + NSLog(@"New environment: %s", getenv("PYTHONPATH")); + + Py_Initialize(); + pName = PyString_FromString("main"); + + if (pName) + { + NSLog(@"Trying to initialize module..."); + pModule = PyImport_Import(pName); + Py_DECREF(pName); + + if (pModule != NULL) + { + id aModule; + Class c; + int len; + + NSLog(@"Loaded main Python file at path %@", path); + + len = [aString length]; + + c = NSClassFromString([aString substringToIndex: (len-7)]); + aModule = [c new]; + + if (aModule) + { + [bundles addObject: aModule]; + RELEASE(aModule); + + NSLog(@"Successfully instanciated Sample"); + + if ([aModule respondsToSelector: @selector(userWasCreated:atDate:)]) + { + [aModule userWasCreated: @"foo" atDate: @"bar"]; + } + } + else + { + NSLog(@"Failed to instanciate Sample"); + } + } + else + { + NSLog(@"Failed to load module."); + } + } + else + { + NSLog(@"Failed to load module. You MUST have main.py in your SOGo Python bundle."); + } + } + } + } + } +} + +// +// +// - (id) init { if ((self = [super init])) @@ -157,6 +271,9 @@ static BOOL debugLeaks; rm = [[WEResourceManager alloc] init]; [self setResourceManager:rm]; [rm release]; + + /* load all bundles */ + [self _loadBundles]; } return self; diff --git a/Tests/Integration/GNUmakefile b/Tests/Integration/GNUmakefile index e154b6304..c93ca1c10 100644 --- a/Tests/Integration/GNUmakefile +++ b/Tests/Integration/GNUmakefile @@ -1,19 +1,8 @@ -PROGRAM=teststrings - -SRCS=teststrings.m -OBJS=$(SRCS:.m=.o) - -teststrings: $(OBJS) - $(CC) -o $@ $< $(GNUSTEP_LIBRARIES_FLAGS) -lgnustep-base -L../../SoObjects/SOGo/SOGo.framework -lSOGo -lobjc - include $(GNUSTEP_MAKEFILES)/common.make -all: $(PROGRAM) +TOOL_NAME = teststrings +teststrings_OBJC_FILES += \ + teststrings.m -clean: - rm -f $(PROGRAM) $(OBJS) *~ - -.m.o: - $(CC) -o $@ -c $(GNUSTEP_HEADERS_FLAGS) $(AUXILIARY_OBJCFLAGS) $(OBJCFLAGS) $(CPPFLAGS) -I../../SoObjects $< - -.SUFFIXES: .m .o +-include GNUmakefile.preamble +include $(GNUSTEP_MAKEFILES)/tool.make diff --git a/Tests/Integration/teststrings.sh b/Tests/Integration/teststrings.sh index 6d0f2e5c0..6d7c2b9c6 100755 --- a/Tests/Integration/teststrings.sh +++ b/Tests/Integration/teststrings.sh @@ -5,12 +5,12 @@ RC=0 if [ ! -f teststrings ] then - make teststrings + make fi for stringfile in ${TOPDIR}/*/*/*.lproj/Localizable.strings do - ./teststrings "$stringfile" > /dev/null + ./obj/teststrings "$stringfile" > /dev/null code=$? if test $code -eq 0; then