Class: Sigh::LocalManage
- Inherits:
-
Object
- Object
- Sigh::LocalManage
- Defined in:
- sigh/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
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'sigh/lib/sigh/local_manage.rb', line 101 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 = UI.confirm("Delete these provisioning profiles #{profiles.length}?") 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
42 43 44 45 46 47 48 |
# File 'sigh/lib/sigh/local_manage.rb', line 42 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
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'sigh/lib/sigh/local_manage.rb', line 20 def self.install_profile(profile) UI.("Installing provisioning profile...") profile_path = File.("~") + "/Library/MobileDevice/Provisioning Profiles/" uuid = ENV["SIGH_UUID"] || ENV["SIGH_UDID"] profile_filename = uuid + ".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
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 86 87 88 89 90 91 |
# File 'sigh/lib/sigh/local_manage.rb', line 50 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 `fastlane sigh manage -e`") if profiles_expired.count > 0 end |
.load_profiles ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'sigh/lib/sigh/local_manage.rb', line 128 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}' 2> /dev/null`) # /dev/null: https://github.com/fastlane/fastlane/issues/6387 profile['Path'] = profile_path profiles << profile end profiles = profiles.sort_by { |profile| profile["Name"].downcase } return profiles end |
.profile_info(profile) ⇒ Object
93 94 95 96 97 98 99 |
# File 'sigh/lib/sigh/local_manage.rb', line 93 def self.profile_info(profile) if FastlaneCore::Globals.verbose? "#{profile['Name']} - #{File.basename(profile['Path'])}" else profile['Name'] end end |
.start(options, args) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'sigh/lib/sigh/local_manage.rb', line 11 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 |