Class: PProf::OutputFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/pprof/output_formatter.rb

Overview

A helper tool to pretty-print Provisioning Profile informations

Defined Under Namespace

Classes: ASCIITable

Instance Method Summary collapse

Constructor Details

#initialize(output = $stdout) ⇒ OutputFormatter

Initialize a new OutputFormatter

Parameters:

  • output (IO) (defaults to: $stdout)

    The output destination where to print the formatted data. Defaults to $stdout



11
12
13
# File 'lib/pprof/output_formatter.rb', line 11

def initialize(output = $stdout)
  @output = output
end

Instance Method Details

Prints the filtered list of Provisioning Profiles

Convenience method. Calls self.print_list with a filter block build from a filter hash

Parameters:

  • filters (Hash<Symbol,Any>) (defaults to: {})

    The hash describing the applied filters



77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/pprof/output_formatter.rb', line 77

def print_filtered_list(dir = PProf::ProvisioningProfile::DEFAULT_DIR, filters = {})
  print_list(dir) do |p|
    (filters[:name].nil? || p.name =~ filters[:name]) &&
    (filters[:appid_name].nil? || p.app_id_name =~ filters[:appid_name]) &&
    (filters[:appid].nil? || p.entitlements.app_id =~ filters[:appid]) &&
    (filters[:uuid].nil? || p.uuid =~ filters[:uuid]) &&
    (filters[:exp].nil? || (p.expiration_date < DateTime.now) == filters[:exp]) &&
    (filters[:has_devices].nil? || !(p.provisioned_devices || []).empty? == filters[:has_devices]) &&
    (filters[:all_devices].nil? || p.provisions_all_devices == filters[:all_devices]) &&
    (filters[:aps_env].nil? || match_aps_env(p.entitlements.aps_environment, filters[:aps_env])) &&
    true
  end
end

Prints the description of a Provisioning Profile

Parameters:

  • profile (PProf::ProvisioningProfile)

    The ProvisioningProfile object to print

  • options (Hash<Symbol,Bool>) (defaults to: nil)

    Decide what to print. Valid keys are :info, :certs and :devices



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/pprof/output_formatter.rb', line 48

def print_info(profile, options = nil)
  options ||= { :info => true }
  if options[:info]
    keys = [:name, :uuid, :app_id_name, :app_id_prefix, :creation_date, :expiration_date, :ttl, :team_ids, :team_name]
    keys.each do |key|
      @output.puts "- #{key.to_s}: #{profile.send(key.to_sym)}"
    end
    @output.puts "- Entitlements:"
    @output.puts profile.entitlements.to_s.split("\n").map { |line| "   #{line}" }
  end

  if options[:info] || options[:certs] 
    @output.puts "- #{profile.developer_certificates.count} Developer Certificates"
    profile.developer_certificates.each { |cert| @output.puts "   - #{cert.subject}" } if options[:certs]
  end
  if options[:info] || options[:devices]
    @output.puts "- #{(profile.provisioned_devices || []).count} Provisioned Devices"
    profile.provisioned_devices.each { |udid| @output.puts "   - #{udid}" } if options[:devices]
    @output.puts "- Provision all devices: #{profile.provisions_all_devices.inspect}"
  end
end

Prints the filtered list

Parameters:

  • dir (String) (defaults to: PProf::ProvisioningProfile::DEFAULT_DIR)

    The directory containing the mobileprovision files to list. Defaults to ‘~/Library/MobileDevice/Provisioning Profiles’

Yields:

  • each provisioning provile for filtering/validation The block is given ProvisioningProfile object and should return true to display the row, false to filter it out



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/pprof/output_formatter.rb', line 101

def print_list(dir = PProf::ProvisioningProfile::DEFAULT_DIR)
  count = 0

  table = PProf::OutputFormatter::ASCIITable.new(36, 60, 45, 25, 2, 10)
  @output.puts table.separator
  @output.puts table.row('UUID', 'Name', 'AppID', 'Expiration Date', ' ', 'Team Name')
  @output.puts table.separator

  Dir[dir + '/*.mobileprovision'].each do |file|
    p = PProf::ProvisioningProfile.new(file)
    
    next if block_given? && !yield(p)

    state = DateTime.now < p.expiration_date ? "\u{2705}" : "\u{274c}" # 2705=checkmark, 274C=red X
    @output.puts table.row(p.uuid, p.name, p.entitlements.app_id, p.expiration_date.to_time, state, p.team_name)
    count += 1
  end

  @output.puts table.separator
  @output.puts "#{count} Provisioning Profiles found."
end