Class: Sigh::LocalManage
- Inherits:
-
Object
- Object
- Sigh::LocalManage
- Defined in:
- lib/sigh/local_manage.rb
Constant Summary collapse
- LIST =
"list"
- CLEANUP =
"cleanup"
Class Method Summary collapse
- .cleanup_profiles(expired = false, pattern = nil, force = nil) ⇒ Object
- .get_inputs(options, _args) ⇒ Object
- .install_profile(profile) ⇒ Object
- .list_profiles ⇒ Object
- .load_profiles ⇒ Object
- .profile_info(profile) ⇒ Object
- .start(options, args) ⇒ Object
Class Method Details
.cleanup_profiles(expired = false, pattern = nil, force = nil) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/sigh/local_manage.rb', line 95 def self.cleanup_profiles(expired = false, pattern = nil, force = nil) now = DateTime.now profiles = load_profiles.select { |profile| (expired && profile["ExpirationDate"] < now) || (!pattern.nil? && profile["Name"] =~ pattern) } UI. "The following provisioning profiles are either expired or matches your pattern:" profiles.each do |profile| UI. profile["Name"].red end delete = force unless delete if Helper.ci? UI.user_error! "On a CI server, cleanup cannot be used without the --force option" else delete = agree("Delete these provisioning profiles #{profiles.length}? (y/n) ", true) end end if delete profiles.each do |profile| File.delete profile["Path"] end UI.success "\n\nDeleted #{profiles.length} profiles" end end |
.get_inputs(options, _args) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/sigh/local_manage.rb', line 36 def self.get_inputs(, _args) clean_expired = .clean_expired clean_pattern = /#{.clean_pattern}/ if .clean_pattern force = .force command = (!clean_expired.nil? || !clean_pattern.nil?) ? CLEANUP : LIST return command, clean_expired, clean_pattern, force end |
.install_profile(profile) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/sigh/local_manage.rb', line 15 def self.install_profile(profile) UI. "Installing provisioning profile..." profile_path = File.("~") + "/Library/MobileDevice/Provisioning Profiles/" profile_filename = ENV["SIGH_UDID"] + ".mobileprovision" destination = profile_path + profile_filename # If the directory doesn't exist, make it first unless File.directory?(profile_path) FileUtils.mkdir_p(profile_path) end # copy to Xcode provisioning profile directory FileUtils.copy profile, destination if File.exist? destination UI.success "Profile installed at \"#{destination}\"" else UI.user_error!("Failed installation of provisioning profile at location: #{destination}") end end |
.list_profiles ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/sigh/local_manage.rb', line 44 def self.list_profiles profiles = load_profiles now = DateTime.now soon = (Date.today + 30).to_datetime profiles_valid = profiles.select { |profile| profile["ExpirationDate"] > now && profile["ExpirationDate"] > soon } if profiles_valid.count > 0 UI. "Provisioning profiles installed" UI. "Valid:" profiles_valid.each do |profile| UI. profile_info(profile).green end end profiles_soon = profiles.select { |profile| profile["ExpirationDate"] > now && profile["ExpirationDate"] < soon } if profiles_soon.count > 0 UI. "" UI. "Expiring within 30 days:" profiles_soon.each do |profile| UI. profile_info(profile).yellow end end profiles_expired = profiles.select { |profile| profile["ExpirationDate"] < now } if profiles_expired.count > 0 UI. "" UI. "Expired:" profiles_expired.each do |profile| UI. profile_info(profile).red end end UI. "" UI. "Summary" UI. "#{profiles.count} installed profiles" UI. "#{profiles_expired.count} are expired".red if profiles_expired.count > 0 UI. "#{profiles_soon.count} are valid but will expire within 30 days".yellow UI. "#{profiles_valid.count} are valid".green UI. "You can remove all expired profiles using `sigh manage -e`" if profiles_expired.count > 0 end |
.load_profiles ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/sigh/local_manage.rb', line 122 def self.load_profiles UI. "Loading Provisioning profiles from ~/Library/MobileDevice/Provisioning Profiles/" profiles_path = File.("~") + "/Library/MobileDevice/Provisioning Profiles/*.mobileprovision" profile_paths = Dir[profiles_path] profiles = [] profile_paths.each do |profile_path| profile = Plist.parse_xml(`security cms -D -i '#{profile_path}'`) profile['Path'] = profile_path profiles << profile end profiles = profiles.sort_by { |profile| profile["Name"].downcase } return profiles end |
.profile_info(profile) ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/sigh/local_manage.rb', line 87 def self.profile_info(profile) if $verbose "#{profile['Name']} - #{File.basename profile['Path']}" else profile['Name'] end end |
.start(options, args) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/sigh/local_manage.rb', line 6 def self.start(, args) command, clean_expired, clean_pattern, force = get_inputs(, args) if command == LIST list_profiles elsif command == CLEANUP cleanup_profiles(clean_expired, clean_pattern, force) end end |