mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-02-17 07:33:57 +00:00
Monotone-Parent: 85f804a64af3e4f769b1bfe8e62eec8300d6e61f
Monotone-Revision: 1fb8ef38e6540891b9c5b8b0bdb02bde0768f4d9 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2009-08-13T18:31:15 Monotone-Branch: ca.inverse.sogo
This commit is contained in:
14
ChangeLog
14
ChangeLog
@@ -1,3 +1,17 @@
|
||||
2009-08-13 Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
||||
|
||||
* Tools/SOGoToolRemoveDoubles.m: new "sogo-tool" utility method
|
||||
implementing the old "sogo-contacts-removedoubles" utility.
|
||||
|
||||
* Tools/SOGoToolCheckDoubles.m: new "sogo-tool" utility method
|
||||
implementing the old "sogo-contacts-checkdoubles" utility.
|
||||
|
||||
* Tools/SOGoTool.m: new class module implementing the base class
|
||||
for all management modules for "sogo-tool".
|
||||
|
||||
* Tools/sogo-tool.m: new command-line tool that offers a generic
|
||||
utility for SOGo administration.
|
||||
|
||||
2009-08-12 Francis Lachapelle <flachapelle@inverse.ca>
|
||||
|
||||
* UI/MainUI/Version (SUBMINOR_VERSION): 1.0.4 release.
|
||||
|
||||
@@ -4,19 +4,16 @@ include ../config.make
|
||||
include $(GNUSTEP_MAKEFILES)/common.make
|
||||
include ../Version
|
||||
|
||||
SOGO_CHECKDOUBLES = sogo-contacts-checkdoubles
|
||||
$(SOGO_CHECKDOUBLES)_INSTALL_DIR = $(SOGO_ADMIN_TOOLS)
|
||||
$(SOGO_CHECKDOUBLES)_OBJC_FILES += \
|
||||
sogo-contacts-checkdoubles.m
|
||||
SOGO_TOOL = sogo-tool
|
||||
$(SOGO_TOOL)_INSTALL_DIR = $(SOGO_ADMIN_TOOLS)
|
||||
$(SOGO_TOOL)_OBJC_FILES += \
|
||||
sogo-tool.m \
|
||||
\
|
||||
SOGoTool.m \
|
||||
SOGoToolCheckDoubles.m \
|
||||
SOGoToolRemoveDoubles.m
|
||||
|
||||
SOGO_REMOVEDOUBLES = sogo-contacts-removedoubles
|
||||
$(SOGO_REMOVEDOUBLES)_INSTALL_DIR = $(SOGO_ADMIN_TOOLS)
|
||||
$(SOGO_REMOVEDOUBLES)_OBJC_FILES += \
|
||||
sogo-contacts-removedoubles.m
|
||||
$(SOGO_REMOVEDOUBLES)_LIB_DIRS = \
|
||||
-L../SOPE/NGCards/$(GNUSTEP_OBJ_DIR)/ -lNGCards
|
||||
|
||||
TOOL_NAME = $(SOGO_CHECKDOUBLES) $(SOGO_REMOVEDOUBLES)
|
||||
TOOL_NAME = $(SOGO_TOOL)
|
||||
|
||||
-include GNUmakefile.preamble
|
||||
include $(GNUSTEP_MAKEFILES)/tool.make
|
||||
|
||||
@@ -7,10 +7,12 @@ ADDITIONAL_CPPFLAGS += \
|
||||
-DSOGO_LIBDIR="\"$(SOGO_LIBDIR)\""
|
||||
|
||||
ADDITIONAL_INCLUDE_DIRS += \
|
||||
-I../SOPE/ -D_GNU_SOURCE
|
||||
-D_GNU_SOURCE -I../SOPE/ -I../SoObjects/
|
||||
|
||||
ADDITIONAL_LIB_DIRS += \
|
||||
-L../SOPE/GDLContentStore/$(GNUSTEP_OBJ_DIR)/ -lGDLContentStore
|
||||
-L../SoObjects/SOGo/$(GNUSTEP_OBJ_DIR)/ -lSOGo \
|
||||
-L../SOPE/GDLContentStore/$(GNUSTEP_OBJ_DIR)/ -lGDLContentStore \
|
||||
-L../SOPE/NGCards/$(GNUSTEP_OBJ_DIR)/ -lNGCards
|
||||
|
||||
SYSTEM_LIB_DIR += -L/usr/local/lib -L/usr/lib
|
||||
|
||||
|
||||
48
Tools/SOGoTool.h
Normal file
48
Tools/SOGoTool.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/* SOGoTool.h - this file is part of SOGo
|
||||
*
|
||||
* Copyright (C) 2009 Inverse inc.
|
||||
*
|
||||
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This file is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef SOGOTOOL_H
|
||||
#define SOGOTOOL_H
|
||||
|
||||
#import <Foundation/NSObject.h>
|
||||
|
||||
// void printStringOnChannel(int channel, NSString * format, ...);
|
||||
|
||||
@interface SOGoTool : NSObject
|
||||
{
|
||||
BOOL verbose;
|
||||
NSArray *arguments;
|
||||
}
|
||||
|
||||
+ (NSString *) command;
|
||||
+ (NSString *) description;
|
||||
|
||||
+ (BOOL) runToolWithArguments: (NSArray *) arguments
|
||||
verbose: (BOOL) verbose;
|
||||
|
||||
- (void) setArguments: (NSArray *) newArguments;
|
||||
- (void) setVerbose: (BOOL) newVerbose;
|
||||
- (BOOL) run;
|
||||
|
||||
@end
|
||||
|
||||
#endif /* SOGOTOOL_H */
|
||||
85
Tools/SOGoTool.m
Normal file
85
Tools/SOGoTool.m
Normal file
@@ -0,0 +1,85 @@
|
||||
/* SOGoTool.m - this file is part of SOGo
|
||||
*
|
||||
* Copyright (C) 2009 Inverse inc.
|
||||
*
|
||||
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This file is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#import <Foundation/NSString.h>
|
||||
|
||||
#import "SOGoTool.h"
|
||||
|
||||
@implementation SOGoTool
|
||||
|
||||
+ (NSString *) command
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (NSString *) description
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (BOOL) runToolWithArguments: (NSArray *) arguments
|
||||
verbose: (BOOL) verbose
|
||||
{
|
||||
SOGoTool *instance;
|
||||
|
||||
instance = [self new];
|
||||
[instance autorelease];
|
||||
|
||||
[instance setArguments: arguments];
|
||||
[instance setVerbose: verbose];
|
||||
|
||||
return [instance run];
|
||||
}
|
||||
|
||||
- (id) init
|
||||
{
|
||||
if ((self = [super init]))
|
||||
{
|
||||
arguments = nil;
|
||||
verbose = NO;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) setArguments: (NSArray *) newArguments
|
||||
{
|
||||
ASSIGN (arguments, newArguments);
|
||||
}
|
||||
|
||||
- (void) setVerbose: (BOOL) newVerbose
|
||||
{
|
||||
verbose = newVerbose;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[arguments release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (BOOL) run
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
@end
|
||||
35
Tools/SOGoToolCheckDoubles.h
Normal file
35
Tools/SOGoToolCheckDoubles.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/* SOGoToolCheckDoubles.h - this file is part of SOGo
|
||||
*
|
||||
* Copyright (C) 2009 Inverse inc.
|
||||
*
|
||||
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This file is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef SOGOTOOLCHECKDOUBLES_H
|
||||
#define SOGOTOOLCHECKDOUBLES_H
|
||||
|
||||
#import "SOGoTool.h"
|
||||
|
||||
@interface SOGoToolCheckDoubles : SOGoTool
|
||||
{
|
||||
unsigned int warningLimit;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#endif /* SOGOTOOLCHECKDOUBLES_H */
|
||||
@@ -1,4 +1,4 @@
|
||||
/* sogo-ab-checkdoubles.m - this file is part of SOGo
|
||||
/* SOGoToolCheckDoubles.m - this file is part of SOGo
|
||||
*
|
||||
* Copyright (C) 2009 Inverse inc.
|
||||
*
|
||||
@@ -25,7 +25,6 @@
|
||||
- make sure we don't end up using 3000 different channels because of the
|
||||
amount of tables we need to wander */
|
||||
|
||||
#import <Foundation/NSAutoreleasePool.h>
|
||||
#import <Foundation/NSDictionary.h>
|
||||
#import <Foundation/NSException.h>
|
||||
#import <Foundation/NSObject.h>
|
||||
@@ -38,38 +37,41 @@
|
||||
#import <GDLContentStore/GCSFolderManager.h>
|
||||
#import <GDLContentStore/GCSFolder.h>
|
||||
|
||||
typedef void (*NSUserDefaultsInitFunction) ();
|
||||
#import "SOGoToolCheckDoubles.h"
|
||||
|
||||
static unsigned int ContactsCountWarningLimit = 1000;
|
||||
@implementation SOGoToolCheckDoubles
|
||||
|
||||
// static void
|
||||
// NSLogInhibitor (NSString *message)
|
||||
// {
|
||||
// }
|
||||
+ (NSString *) command
|
||||
{
|
||||
return @"check-doubles";
|
||||
}
|
||||
|
||||
@interface SOGoDoublesChecker : NSObject
|
||||
+ (NSString *) description
|
||||
{
|
||||
return @"check user addressbooks with duplicate contacts";
|
||||
}
|
||||
|
||||
- (BOOL) run;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SOGoDoublesChecker
|
||||
|
||||
+ (void) initialize
|
||||
- (id) init
|
||||
{
|
||||
NSUserDefaults *ud;
|
||||
NSNumber *warningLimit;
|
||||
NSNumber *SOGoContactsCountWarningLimit;
|
||||
|
||||
// _NSLog_printf_handler = NSLogInhibitor;
|
||||
if ((self = [super init]))
|
||||
{
|
||||
ud = [NSUserDefaults standardUserDefaults];
|
||||
SOGoContactsCountWarningLimit
|
||||
= [ud objectForKey: @"SOGoContactsCountWarningLimit"];
|
||||
if (SOGoContactsCountWarningLimit)
|
||||
warningLimit
|
||||
= [SOGoContactsCountWarningLimit unsignedIntValue];
|
||||
else
|
||||
warningLimit = 1000;
|
||||
|
||||
ud = [NSUserDefaults standardUserDefaults];
|
||||
[ud addSuiteNamed: @"sogod"];
|
||||
warningLimit = [ud objectForKey: @"SOGoContactsCountWarningLimit"];
|
||||
if (warningLimit)
|
||||
ContactsCountWarningLimit = [warningLimit unsignedIntValue];
|
||||
fprintf (stderr, "The warning limit for folder records is set at %u\n",
|
||||
warningLimit);
|
||||
}
|
||||
|
||||
fprintf (stderr, "The warning limit for folder records is set at %u\n",
|
||||
ContactsCountWarningLimit);
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) processIndexResults: (EOAdaptorChannel *) channel
|
||||
@@ -89,7 +91,7 @@ static unsigned int ContactsCountWarningLimit = 1000;
|
||||
if (currentFolder)
|
||||
{
|
||||
recordsCount = [currentFolder recordsCountByExcludingDeleted: YES];
|
||||
if (recordsCount > ContactsCountWarningLimit)
|
||||
if (recordsCount > warningLimit)
|
||||
{
|
||||
fprintf (stderr, "'%s' (id: '%s'), of '%s': %u entries\n",
|
||||
[[folderRow objectForKey: @"c_foldername"]
|
||||
@@ -127,7 +129,8 @@ static unsigned int ContactsCountWarningLimit = 1000;
|
||||
ex = [channel evaluateExpressionX: sqlString];
|
||||
if (ex)
|
||||
{
|
||||
fprintf (stderr, "an exception occured during the fetching of folder names");
|
||||
fprintf (stderr, "an exception occured during the fetching of"
|
||||
" folder names");
|
||||
[ex raise];
|
||||
rc = NO;
|
||||
}
|
||||
@@ -163,26 +166,3 @@ static unsigned int ContactsCountWarningLimit = 1000;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
int
|
||||
main (int argc, char **argv, char **env)
|
||||
{
|
||||
NSAutoreleasePool *pool;
|
||||
SOGoDoublesChecker *checker;
|
||||
int rc;
|
||||
|
||||
rc = 0;
|
||||
|
||||
pool = [NSAutoreleasePool new];
|
||||
|
||||
checker = [SOGoDoublesChecker new];
|
||||
if ([checker run])
|
||||
rc = 0;
|
||||
else
|
||||
rc = -1;
|
||||
[checker release];
|
||||
|
||||
[pool release];
|
||||
|
||||
return rc;
|
||||
}
|
||||
32
Tools/SOGoToolRemoveDoubles.h
Normal file
32
Tools/SOGoToolRemoveDoubles.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/* SOGoToolRemoveDoubles.h - this file is part of SOGo
|
||||
*
|
||||
* Copyright (C) 2009 Inverse inc.
|
||||
*
|
||||
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This file is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef SOGOTOOLREMOVEDOUBLES_H
|
||||
#define SOGOTOOLREMOVEDOUBLES_H
|
||||
|
||||
#import "SOGoTool.h"
|
||||
|
||||
@interface SOGoToolRemoveDoubles : SOGoTool
|
||||
|
||||
@end
|
||||
|
||||
#endif /* SOGOTOOLREMOVEDOUBLES_H */
|
||||
@@ -1,4 +1,4 @@
|
||||
/* sogo-ab-removedoubles.m - this file is part of SOGo
|
||||
/* SOGoToolRemoveDoubles.m - this file is part of SOGo
|
||||
*
|
||||
* Copyright (C) 2009 Inverse inc.
|
||||
*
|
||||
@@ -20,7 +20,8 @@
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* TODO: NSUserDefaults bootstrapping for using different backends */
|
||||
/* TODO:
|
||||
- show usage */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -45,7 +46,7 @@
|
||||
#import <GDLContentStore/GCSFolderManager.h>
|
||||
#import <GDLContentStore/GCSFolder.h>
|
||||
|
||||
typedef void (*NSUserDefaultsInitFunction) ();
|
||||
#import "SOGoToolRemoveDoubles.h"
|
||||
|
||||
@interface NGVList (RemoveDoubles)
|
||||
|
||||
@@ -73,17 +74,16 @@ typedef void (*NSUserDefaultsInitFunction) ();
|
||||
|
||||
@end
|
||||
|
||||
@interface SOGoDoublesRemover : NSObject
|
||||
@end
|
||||
@implementation SOGoToolRemoveDoubles
|
||||
|
||||
@implementation SOGoDoublesRemover
|
||||
|
||||
+ (void) initialize
|
||||
+ (NSString *) command
|
||||
{
|
||||
NSUserDefaults *ud;
|
||||
return @"remove-doubles";
|
||||
}
|
||||
|
||||
ud = [NSUserDefaults standardUserDefaults];
|
||||
[ud addSuiteNamed: @"sogod"];
|
||||
+ (NSString *) description
|
||||
{
|
||||
return @"remove duplicate contacts from the specified user addressbook";
|
||||
}
|
||||
|
||||
- (void) feedDoubleEmails: (NSMutableDictionary *) doubleEmails
|
||||
@@ -522,47 +522,27 @@ typedef void (*NSUserDefaultsInitFunction) ();
|
||||
return rc;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
static void
|
||||
Usage (const char *name)
|
||||
- (void) usage
|
||||
{
|
||||
const char *slash, *start;
|
||||
|
||||
slash = strrchr (name, '/');
|
||||
if (slash)
|
||||
start = slash + 1;
|
||||
else
|
||||
start = name;
|
||||
fprintf (stderr, "Usage: %s USER FOLDER\n\n"
|
||||
fprintf (stderr, "Usage: remove-doubles USER FOLDER\n\n"
|
||||
" USER the owner of the contact folder\n"
|
||||
" FOLDER the id of the folder to clean up\n",
|
||||
start);
|
||||
" FOLDER the id of the folder to clean up\n");
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv, char **env)
|
||||
- (BOOL) run
|
||||
{
|
||||
NSAutoreleasePool *pool;
|
||||
SOGoDoublesRemover *remover;
|
||||
int rc;
|
||||
BOOL rc;
|
||||
|
||||
rc = -1;
|
||||
|
||||
pool = [NSAutoreleasePool new];
|
||||
|
||||
if (argc > 2)
|
||||
{
|
||||
remover = [SOGoDoublesRemover new];
|
||||
if ([remover runWithFolder: [NSString stringWithFormat: @"%s", argv[2]]
|
||||
andUser: [NSString stringWithFormat: @"%s", argv[1]]])
|
||||
rc = 0;
|
||||
[remover release];
|
||||
}
|
||||
if ([arguments count] == 2)
|
||||
rc = [self runWithFolder: [arguments objectAtIndex: 1]
|
||||
andUser: [arguments objectAtIndex: 0]];
|
||||
else
|
||||
Usage (argv[0]);
|
||||
|
||||
[pool release];
|
||||
{
|
||||
[self usage];
|
||||
rc = NO;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@end
|
||||
238
Tools/sogo-tool.m
Normal file
238
Tools/sogo-tool.m
Normal file
@@ -0,0 +1,238 @@
|
||||
/* sogo-tool.m - this file is part of SOGo
|
||||
*
|
||||
* Copyright (C) 2009 Inverse inc.
|
||||
*
|
||||
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This file is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#import <Foundation/NSAutoreleasePool.h>
|
||||
#import <Foundation/NSArray.h>
|
||||
#import <Foundation/NSDictionary.h>
|
||||
#import <Foundation/NSEnumerator.h>
|
||||
#import <Foundation/NSObject.h>
|
||||
#import <Foundation/NSProcessInfo.h>
|
||||
#import <Foundation/NSString.h>
|
||||
#import <Foundation/NSUserDefaults.h>
|
||||
|
||||
#import "SOGoTool.h"
|
||||
|
||||
@interface SOGoToolDispatcher : NSObject
|
||||
{
|
||||
NSMutableDictionary *tools;
|
||||
BOOL verboseMode;
|
||||
BOOL helpMode;
|
||||
NSString *tool;
|
||||
NSArray *toolArguments;
|
||||
}
|
||||
|
||||
- (BOOL) run;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SOGoToolDispatcher
|
||||
|
||||
- (id) init
|
||||
{
|
||||
if ((self = [super init]))
|
||||
{
|
||||
tools = [NSMutableDictionary new];
|
||||
helpMode = NO;
|
||||
verboseMode = NO;
|
||||
tool = nil;
|
||||
toolArguments = nil;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[tools release];
|
||||
[tool release];
|
||||
[toolArguments release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void) registerTool: (NSString *) command
|
||||
withClass: (NSString *) className
|
||||
andDescription: (NSString *) description
|
||||
{
|
||||
NSArray *toolData;
|
||||
|
||||
toolData = [NSArray arrayWithObjects: className, description, nil];
|
||||
[tools setObject: toolData forKey: command];
|
||||
}
|
||||
|
||||
- (void) parseArguments: (NSArray *) arguments
|
||||
{
|
||||
BOOL error;
|
||||
int count, max;
|
||||
NSString *argument;
|
||||
|
||||
error = NO;
|
||||
|
||||
max = [arguments count];
|
||||
count = 1;
|
||||
while (!error && !tool && count < max)
|
||||
{
|
||||
argument = [arguments objectAtIndex: count];
|
||||
if ([argument isEqualToString: @"-v"]
|
||||
|| [argument isEqualToString: @"--verbose"])
|
||||
verboseMode = YES;
|
||||
else if ([argument isEqualToString: @"-h"]
|
||||
|| [argument isEqualToString: @"--help"])
|
||||
helpMode = YES;
|
||||
else if ([argument hasPrefix: @"-"])
|
||||
{
|
||||
error = YES;
|
||||
helpMode = YES;
|
||||
NSLog (@"Invalid command line parameter: '%@'", argument);
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSIGN (tool,
|
||||
[[tools objectForKey: argument] objectAtIndex: 0]);
|
||||
count++;
|
||||
if (count < max)
|
||||
{
|
||||
max -= count;
|
||||
toolArguments = [arguments
|
||||
subarrayWithRange: NSMakeRange (count, max)];
|
||||
[toolArguments retain];
|
||||
}
|
||||
}
|
||||
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
- (void) help
|
||||
{
|
||||
NSMutableString *helpString;
|
||||
NSEnumerator *toolsEnum;
|
||||
NSString *command;
|
||||
NSArray *currentTool;
|
||||
|
||||
helpString = [NSMutableString stringWithString: @"sogo-tool [-v|--verbose]"
|
||||
@" [-h|--help]"
|
||||
@" command [argument1] ...\n"];
|
||||
[helpString appendString: @" -v, --verbose\tenable verbose mode\n"];
|
||||
[helpString appendString: @" -h, --help\tdisplay this help information\n\n"];
|
||||
[helpString appendString: @" argument1, ...\targuments passed to the"
|
||||
@" specified command\n\n"];
|
||||
[helpString appendString: @" Available commands:\n"];
|
||||
toolsEnum = [[tools allKeys] objectEnumerator];
|
||||
while ((command = [toolsEnum nextObject]))
|
||||
{
|
||||
currentTool = [tools objectForKey: command];
|
||||
[helpString appendFormat: @"\t%@\t-- %@\n",
|
||||
command, [currentTool objectAtIndex: 1]];
|
||||
}
|
||||
|
||||
NSLog (helpString);
|
||||
}
|
||||
|
||||
- (void) registerTools
|
||||
{
|
||||
NSEnumerator *toolsEnum;
|
||||
Class currentTool;
|
||||
NSString *command, *description;
|
||||
|
||||
toolsEnum = [GSObjCAllSubclassesOfClass ([SOGoTool class]) objectEnumerator];
|
||||
while ((currentTool = [toolsEnum nextObject]))
|
||||
{
|
||||
command = [currentTool command];
|
||||
if (command)
|
||||
{
|
||||
description = [currentTool description];
|
||||
[self registerTool: command
|
||||
withClass: NSStringFromClass (currentTool)
|
||||
andDescription: description];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL) run
|
||||
{
|
||||
NSProcessInfo *processInfo;
|
||||
NSArray *arguments;
|
||||
Class toolClass;
|
||||
NSString *toolsList;
|
||||
BOOL rc;
|
||||
|
||||
[self registerTools];
|
||||
|
||||
processInfo = [NSProcessInfo processInfo];
|
||||
arguments = [processInfo arguments];
|
||||
[self parseArguments: arguments];
|
||||
if (helpMode || !tool)
|
||||
{
|
||||
rc = YES;
|
||||
[self help];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (tool)
|
||||
{
|
||||
toolClass = NSClassFromString (tool);
|
||||
if (toolClass)
|
||||
rc = [toolClass runToolWithArguments: toolArguments
|
||||
verbose: verboseMode];
|
||||
else
|
||||
{
|
||||
rc = NO;
|
||||
toolsList = [[tools allKeys] componentsJoinedByString: @", "];
|
||||
NSLog (@"No tool named '%@'. Available tools are:\n\t%@",
|
||||
tool, toolsList);
|
||||
}
|
||||
}
|
||||
else
|
||||
rc = NO;
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
int
|
||||
main (int argc, char **argv, char **env)
|
||||
{
|
||||
NSAutoreleasePool *pool;
|
||||
SOGoToolDispatcher *dispatcher;
|
||||
NSUserDefaults *ud;
|
||||
int rc;
|
||||
|
||||
rc = 0;
|
||||
|
||||
pool = [NSAutoreleasePool new];
|
||||
|
||||
ud = [NSUserDefaults standardUserDefaults];
|
||||
[ud addSuiteNamed: @"sogod"];
|
||||
|
||||
dispatcher = [SOGoToolDispatcher new];
|
||||
if ([dispatcher run])
|
||||
rc = 0;
|
||||
else
|
||||
rc = -1;
|
||||
[dispatcher release];
|
||||
|
||||
[pool release];
|
||||
|
||||
return rc;
|
||||
}
|
||||
Reference in New Issue
Block a user