/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. #import "ERListTicketsCommand.h"
  15. #import "KSUpdateEngine.h"
  16. @implementation ERListTicketsCommand
  17. - (NSString *)name {
  18. return @"list";
  19. } // name
  20. - (NSString *)blurb {
  21. return @"Lists all of the tickets in a ticket store";
  22. } // blurb
  23. - (NSDictionary *)requiredArguments {
  24. return [NSDictionary dictionaryWithObjectsAndKeys:
  25. @"Path to the ticket store to list", @"store",
  26. nil];
  27. } // requiredArguments
  28. - (BOOL)runWithArguments:(NSDictionary *)args {
  29. // Grab the ticket store.
  30. NSString *storePath = [args objectForKey:@"store"];
  31. KSTicketStore *store = [KSTicketStore ticketStoreWithPath:storePath];
  32. // Grab all the tickets in the store.
  33. NSArray *tickets = [store tickets];
  34. if ([tickets count] == 0) {
  35. fprintf(stderr, "no tickets found\n");
  36. return YES;
  37. }
  38. // Walk the tickets printing out each one.
  39. fprintf(stdout, "%d tickets at %s\n",
  40. [tickets count], [storePath UTF8String]);
  41. NSEnumerator *ticketEnumerator = [tickets objectEnumerator];
  42. KSTicket *ticket;
  43. int ticketCount = 0;
  44. while ((ticket = [ticketEnumerator nextObject])) {
  45. fprintf(stdout, "\n");
  46. fprintf(stdout, "Ticket %d:\n", ticketCount);
  47. fprintf(stdout, " %s version %s\n", [[ticket productID] UTF8String],
  48. [[ticket version] UTF8String]);
  49. // Actually evaluate the existence checker. Handy for debugging
  50. // to make sure Update Engine really thinks what you think it's
  51. // thinking.
  52. KSExistenceChecker *existenceChecker = [ticket existenceChecker];
  53. fprintf(stdout, " exists? %s, with existence checker %s\n",
  54. [existenceChecker exists] ? "YES" : "NO",
  55. [[existenceChecker description] UTF8String]);
  56. fprintf(stdout, " server URL %s\n",
  57. [[[ticket serverURL] description] UTF8String]);
  58. ticketCount++;
  59. }
  60. return YES;
  61. } // runWithArguments
  62. @end // ERListTicketsCommand