source: branches/CoreData/SapphireFrappliance/main_debug.m @ 847

Revision 847, 8.1 KB checked in by gbooker, 5 years ago (diff)

Updated the debug to new creation of moc

Line 
1/*
2 * main_debug.c
3 * Sapphire
4 *
5 * Created by Graham Booker on Aug. 2, 2008.
6 * Copyright 2007 Sapphire Development Team and/or www.nanopi.net
7 * All rights reserved.
8 *
9 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
10 * General Public License as published by the Free Software Foundation; either version 3 of the License,
11 * or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
14 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
15 * Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with this program; if not,
18 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 */
20
21#import "SapphireImportHelper.h"
22#import <CoreData/CoreData.h>
23
24#include "../SapphireCompatibilityClasses/Sapphire_Prefix.pch"
25
26//Debug Imports
27#import "SapphireCollectionDirectory.h"
28#import "SapphireDirectoryMetaData.h"
29#import "SapphireApplianceController.h"
30#import "SapphireMetaDataUpgrading.h"
31#import "SapphireMovie.h"
32#import "CoreDataSupportFunctions.h"
33#import "SapphireFileMetaData.h"
34#import "SapphireFileDataImporter.h"
35#import "SapphireXMLFileDataImporter.h"
36#import "SapphireTVShowImporter.h"
37#import "SapphireMovieImporter.h"
38#import "SapphireMetaDataSupport.h"
39#import "SapphireAllImporter.h"
40#import "SapphireTVShow.h"
41#import "SapphireGenre.h"
42#import "SapphireCast.h"
43#import "SapphireDirector.h"
44#import "SapphireXMLData.h"
45
46void overrideApplicationSupportdir(NSString *override);
47
48@interface TestFileScanning : NSObject <SapphireMetaDataScannerDelegate>
49{
50        int i;
51        NSArray *collections;
52        NSMutableSet *skip;
53}
54- (id)initWithCollections:(NSArray *)col;
55@end
56
57@implementation TestFileScanning
58
59- (id)initWithCollections:(NSArray *)col
60{
61        self = [super init];
62       
63        collections = [col retain];
64        skip = [[NSMutableSet alloc] init];
65        i=-1;
66       
67        return self;
68}
69
70- (void) dealloc
71{
72        [collections release];
73        [skip release];
74        [super dealloc];
75}
76
77- (void)gotSubFiles:(NSArray *)subs
78{
79        i++;
80        if(i==[collections count])
81                NSLog(@"DONE!!!");
82        else
83        {
84                [[(SapphireCollectionDirectory *)[collections objectAtIndex:i] directory] getSubFileMetasWithDelegate:self skipDirectories:skip];
85        }
86}
87
88- (void)scanningDir:(NSString *)dir
89{
90}
91
92- (BOOL)getSubFilesCanceled
93{
94        return NO;
95}
96
97@end
98
99@interface SapphireMetaDataUpgrading (debug)
100- (void)doUpgrade:(id)obj;
101@end
102
103@interface SapphireMetaDataSupport (debug)
104+ (void)deletePendingObjects;
105@end
106
107
108
109
110int main(int argc, char *argv[])
111{
112        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
113       
114        {
115                NSString *path = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:argv[0] length:strlen(argv[0])];
116               
117                path = [[path stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Sapphire.frappliance"];
118               
119                NSBundle *bundle = [NSBundle bundleWithPath:path];
120                [bundle load];         
121        }
122       
123//      overrideApplicationSupportdir([NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Frontrow"]);
124//#define TESTING_UPGRADE
125#ifdef TESTING_UPGRADE
126        {
127                SapphireMetaDataUpgrading *upgrade = [[SapphireMetaDataUpgrading alloc] init];
128                [upgrade doUpgrade:nil];
129                [upgrade release];
130        }
131#endif
132       
133        NSString *storeFile = [applicationSupportDir() stringByAppendingPathComponent:@"metaData.sapphireDataV2"];
134        BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:storeFile];
135        if(!exists)
136                return 0;
137       
138        NSManagedObjectContext *moc = [SapphireApplianceController newManagedObjectContextForFile:storeFile withOptions:nil];
139        [SapphireMetaDataSupport setMainContext:moc];
140       
141        //Debug code goes here:
142//#define LISTING_MOVIES
143#ifdef LISTING_MOVIES
144        {
145                NSArray *allMovies = doFetchRequest(SapphireMovieName, moc, nil);
146                NSEnumerator *movieEnum = [allMovies objectEnumerator];
147                SapphireMovie *movie;
148                while((movie = [movieEnum nextObject]) != nil)
149                {
150                        NSLog(@"Looking at movie %@ with xml: %d", [movie title], [[movie xmlSet] count]);
151                        NSLog(@"Cast is %@", [movie valueForKeyPath:@"cast.name"]);
152                        NSLog(@"Directors is %@", [movie valueForKeyPath:@"directors.name"]);
153                        NSLog(@"Genres is %@", [movie valueForKeyPath:@"genres.name"]);
154                        NSLog(@"Plot is %@", [movie plot]);
155                }               
156        }
157#endif
158//#define TESTING_XML_IMPORT
159#ifdef TESTING_XML_IMPORT
160        {
161                NSString *path = @"/Users/gbooker/Movies/Little Einsteins.avi";
162                SapphireFileMetaData *meta = [SapphireFileMetaData fileWithPath:path inContext:moc];
163                [meta clearMetaData];
164                [SapphireMetaDataSupport save:moc];
165                SapphireXMLFileDataImporter *importer = [[SapphireXMLFileDataImporter alloc] init];
166                [importer importMetaData:meta path:[meta path]];
167                [importer release];             
168        }
169#endif
170//#define TESTING_FILE_SCANNING
171#ifdef TESTING_FILE_SCANNING
172        {
173                NSMutableArray *collections = [[SapphireCollectionDirectory allCollectionsInContext:moc] mutableCopy];
174                //remove / and ~/Movies
175                [collections removeObjectAtIndex:0];
176                [collections removeObjectAtIndex:0];
177                TestFileScanning *debug = [[TestFileScanning alloc] initWithCollections:collections];
178                [NSTimer scheduledTimerWithTimeInterval:0 target:debug selector:@selector(gotSubFiles:) userInfo:nil repeats:NO];
179                [debug release];
180               
181                NSRunLoop *currentRL = [NSRunLoop currentRunLoop];
182                while([currentRL runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]])
183                        ;               
184        }
185#endif
186//#define TESTING_UPDATED_VALUES
187#ifdef TESTING_UPDATED_VALUES
188        {
189                NSString *path = @"/Users/gbooker/Movies/Little Einsteins.avi";
190                SapphireFileMetaData *meta = [SapphireFileMetaData fileWithPath:path inContext:moc];
191                [meta clearMetaData];
192                SapphireXMLFileDataImporter *xmlImpr = [[SapphireXMLFileDataImporter alloc] init];
193                SapphireFileDataImporter *fileImp = [[SapphireFileDataImporter alloc] init];
194                SapphireTVShowImporter *tvImp = [[SapphireTVShowImporter alloc] initWithContext:moc];
195                SapphireMovieImporter *movImp = [[SapphireMovieImporter alloc] initWithContext:moc];
196                SapphireAllImporter *allImporter = [[SapphireAllImporter alloc] initWithImporters:[NSArray arrayWithObjects:xmlImpr,tvImp,movImp,fileImp,nil]];
197                [xmlImpr release];
198                [fileImp release];
199                [tvImp release];
200                [movImp release];
201               
202                [allImporter importMetaData:meta path:[meta path]];
203               
204                NSDictionary *changes = [SapphireMetaDataSupport changesDictionaryForContext:moc];
205                [moc reset];
206                [SapphireMetaDataSupport applyChanges:changes toContext:moc];
207                [allImporter release];
208        }
209#endif
210//#define TESTING_DIRECTORY_RESCAN
211#ifdef TESTING_DIRECTORY_RESCAN
212        {
213                SapphireMovie *movie = [SapphireMovie movieWithTitle:@"Little Eistiens: Our Big Huge Adventure" inContext:moc];
214                SapphireFileMetaData *file = [SapphireFileMetaData fileWithPath:@"/Users/gbooker/Movies/Little Einsteins.avi" inContext:moc];
215                [moc deleteObject:file];
216                [moc processPendingChanges];
217                SapphireDirectoryMetaData *dir = [SapphireDirectoryMetaData directoryWithPath:@"/Users/gbooker/Movies" inContext:moc];
218                [dir reloadDirectoryContents];
219        }
220#endif
221//#define TESTING_AUTO_PRUNING
222#ifdef TESTING_AUTO_PRUNING
223        {
224                SapphireFileMetaData *file = [SapphireFileMetaData fileWithPath:@"/Users/gbooker/Movies/MovieTests/Little Einsteins.avi" inContext:moc];
225                SapphireXMLData *xml = [file xmlData];
226                [moc deleteObject:xml];
227                [SapphireMetaDataSupport deletePendingObjects];
228                SapphireDirectoryMetaData *dir = [SapphireDirectoryMetaData directoryWithPath:@"/Users/gbooker/Movies/MovieTests" inContext:moc];
229                [moc deleteObject:dir];
230                [SapphireMetaDataSupport deletePendingObjects];
231                dir = [SapphireDirectoryMetaData directoryWithPath:@"/Users/gbooker/Movies/TVShowsTests" inContext:moc];
232                [moc deleteObject:dir];
233                [SapphireMetaDataSupport deletePendingObjects];
234                NSArray *allMovies = doFetchRequest(SapphireMovieName, moc, nil);
235                NSArray *allShows = doFetchRequest(SapphireTVShowName, moc, nil);
236                NSArray *allGenres = doFetchRequest(SapphireGenreName, moc, nil);
237                NSArray *allCast = doFetchRequest(SapphireCastName, moc, nil);
238                NSArray *allDirectors = doFetchRequest(SapphireDirectorName, moc, nil);
239               
240                NSLog(@"Movies: %@\nShows: %@\nCast: %@\nGenres: %@\nDirectors: %@", allMovies, allShows, allCast, allGenres, allDirectors);
241        }
242#endif
243       
244        [pool release];
245       
246        return 0;
247}
Note: See TracBrowser for help on using the repository browser.