PageRenderTime 38ms CodeModel.GetById 17ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 0ms

/core/externals/update-engine/Samples/EngineRunner/ERListTicketsCommand.m

http://macfuse.googlecode.com/
Objective C | 83 lines | 43 code | 21 blank | 19 comment | 3 complexity | b022e1c8c8df6c710e07237803e51740 MD5 | raw file
 1// Copyright 2008 Google Inc.
 2//
 3// Licensed under the Apache License, Version 2.0 (the "License");
 4// you may not use this file except in compliance with the License.
 5// You may obtain a copy of the License at
 6//
 7//     http://www.apache.org/licenses/LICENSE-2.0
 8//
 9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#import "ERListTicketsCommand.h"
16
17#import "KSUpdateEngine.h"
18
19
20@implementation ERListTicketsCommand
21
22- (NSString *)name {
23  return @"list";
24}  // name
25
26
27- (NSString *)blurb {
28  return @"Lists all of the tickets in a ticket store";
29}  // blurb
30
31
32- (NSDictionary *)requiredArguments {
33  return [NSDictionary dictionaryWithObjectsAndKeys:
34                       @"Path to the ticket store to list", @"store",
35                       nil];
36}  // requiredArguments
37
38
39- (BOOL)runWithArguments:(NSDictionary *)args {
40  // Grab the ticket store.
41  NSString *storePath = [args objectForKey:@"store"];
42  KSTicketStore *store = [KSTicketStore ticketStoreWithPath:storePath];
43
44  // Grab all the tickets in the store.
45  NSArray *tickets = [store tickets];
46  if ([tickets count] == 0) {
47    fprintf(stderr, "no tickets found\n");
48    return YES;
49  }
50
51  // Walk the tickets printing out each one.
52  fprintf(stdout, "%d tickets at %s\n",
53          [tickets count], [storePath UTF8String]);
54  NSEnumerator *ticketEnumerator = [tickets objectEnumerator];
55
56  KSTicket *ticket;
57  int ticketCount = 0;
58  while ((ticket = [ticketEnumerator nextObject])) {
59    fprintf(stdout, "\n");
60    fprintf(stdout, "Ticket %d:\n", ticketCount);
61
62    fprintf(stdout, "    %s version %s\n", [[ticket productID] UTF8String],
63            [[ticket version] UTF8String]);
64
65    // Actually evaluate the existence checker.  Handy for debugging
66    // to make sure Update Engine really thinks what you think it's
67    // thinking.
68    KSExistenceChecker *existenceChecker = [ticket existenceChecker];
69    fprintf(stdout, "    exists? %s, with existence checker %s\n",
70            [existenceChecker exists] ? "YES" : "NO",
71            [[existenceChecker description] UTF8String]);
72
73    fprintf(stdout, "    server URL %s\n",
74            [[[ticket serverURL] description] UTF8String]);
75
76    ticketCount++;
77  }
78
79  return YES;
80
81}  // runWithArguments
82
83@end  // ERListTicketsCommand