Class: PProf::OutputFormatter
- Inherits:
-
Object
- Object
- PProf::OutputFormatter
- 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
-
#initialize(output = $stdout) ⇒ OutputFormatter
constructor
Initialize a new OutputFormatter.
-
#print_error(message, file) ⇒ Object
Prints an error message.
-
#print_filtered_list(dir = PProf::ProvisioningProfile::DEFAULT_DIR, filters = {}, list_options = { :mode => :table }) ⇒ Object
Prints the filtered list of Provisioning Profiles.
-
#print_info(profile, options = nil) ⇒ Object
Prints the description of a Provisioning Profile.
-
#print_list(dir = PProf::ProvisioningProfile::DEFAULT_DIR, options) { ... } ⇒ Object
Prints the filtered list of UUIDs or Paths only.
-
#print_table(dir = PProf::ProvisioningProfile::DEFAULT_DIR) { ... } ⇒ Object
Prints the filtered list as a table.
Constructor Details
#initialize(output = $stdout) ⇒ OutputFormatter
Initialize a new OutputFormatter
11 12 13 |
# File 'lib/pprof/output_formatter.rb', line 11 def initialize(output = $stdout) @output = output end |
Instance Method Details
#print_error(message, file) ⇒ Object
Prints an error message
48 49 50 |
# File 'lib/pprof/output_formatter.rb', line 48 def print_error(, file) @output.puts "\u{274c} #{file} - #{}" end |
#print_filtered_list(dir = PProf::ProvisioningProfile::DEFAULT_DIR, filters = {}, list_options = { :mode => :table }) ⇒ Object
Prints the filtered list of Provisioning Profiles
Convenience method. Calls self.print_list with a filter block build from a filter hash
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/pprof/output_formatter.rb', line 100 def print_filtered_list(dir = PProf::ProvisioningProfile::DEFAULT_DIR, filters = {}, = { :mode => :table }) filter_func = lambda 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[:team].nil? || p.team_name =~ filters[:team] || p.team_ids.any? { |id| id =~ filters[:team] }) && (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 case [:mode] when :table print_table(dir, &filter_func) else print_list(dir, , &filter_func) end end |
#print_info(profile, options = nil) ⇒ Object
Prints the description of a Provisioning Profile
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/pprof/output_formatter.rb', line 59 def print_info(profile, = nil) ||= { :info => true } if [: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 [:info] || [:certs] @output.puts "- #{profile.developer_certificates.count} Developer Certificates" profile.developer_certificates.each { |cert| @output.puts " - #{cert.subject}" } if [:certs] end if [:info] || [:devices] @output.puts "- #{(profile.provisioned_devices || []).count} Provisioned Devices" profile.provisioned_devices.each { |udid| @output.puts " - #{udid}" } if [:devices] @output.puts "- Provision all devices: #{profile.provisions_all_devices.inspect}" end end |
#print_list(dir = PProf::ProvisioningProfile::DEFAULT_DIR, options) { ... } ⇒ Object
Prints the filtered list of UUIDs or Paths only
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/pprof/output_formatter.rb', line 173 def print_list(dir = PProf::ProvisioningProfile::DEFAULT_DIR, ) errors = [] Dir[dir + '/*.mobileprovision'].each do |file| begin p = PProf::ProvisioningProfile.new(file) next if block_given? && !yield(p) @output.print [:mode] == :uuid ? p.uuid.chomp : file.chomp @output.print [:zero] ? "\0" : "\n" rescue Exception => e errors << { :message => e, :file => file } end end unless errors.empty? errors.each { |e| print_error(e[:message], e[:file]) } end end |
#print_table(dir = PProf::ProvisioningProfile::DEFAULT_DIR) { ... } ⇒ Object
Prints the filtered list as a table
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/pprof/output_formatter.rb', line 132 def print_table(dir = PProf::ProvisioningProfile::DEFAULT_DIR) count = 0 errors = [] 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| begin 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) rescue Exception => e errors << { :message => e, :file => file } end count += 1 end @output.puts table.separator @output.puts "#{count} Provisioning Profiles found." unless errors.empty? errors.each { |e| print_error(e[:message], e[:file]) } end end |