Class: Pindo::Command::Utils::Device

Inherits:
Pindo::Command::Utils show all
Defined in:
lib/pindo/command/utils/device.rb

Defined Under Namespace

Classes: DeviceItem

Constant Summary

Constants inherited from Pindo::Command

DEFAULT_OPTIONS, DEFAULT_ROOT_OPTIONS

Instance Attribute Summary

Attributes inherited from Pindo::Command

#args_help_flag

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Pindo::Command

run

Methods included from Funlog::Mixin

#pindo_log_instance

Methods included from Pindoconfig::Mixin

#pindo_single_config

Methods included from Githelper

#add_branch, #add_tag, #add_tag_with_check, #clone_clang_repo, #clone_devclang_repo, #clone_pindo_common_config_repo, #clone_pindo_env_config_repo, #clong_buildconfig_repo, #get_repo_base_name, #getcode_to_dir, #git_addpush_repo, #git_latest_commit_id, #local_branch_exists?, #local_tag_exists?, #prepare_gitenv, #process_need_add_files, #remote_branch_exists?, #remote_tag_exists?, #remove_branch, #remove_tag

Methods included from Executable

capture_command, #executable, execute_command, which, which!

Constructor Details

#initialize(argv) ⇒ Device

Returns a new instance of Device.



41
42
43
44
45
# File 'lib/pindo/command/utils/device.rb', line 41

def initialize(argv)
    
    super(argv)
    @additional_args = argv.remainder!
end

Class Method Details

.optionsObject



35
36
37
38
39
# File 'lib/pindo/command/utils/device.rb', line 35

def self.options
  [
        
  ].concat(super)
end

Instance Method Details

#fetch_deviceObject



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
92
93
94
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/pindo/command/utils/device.rb', line 65

def fetch_device


    devices = Spaceship::Portal.device.all(include_disabled: true).select do |device|
        device.enabled?
    end
    mac_disabled_devices = Spaceship::Portal.device.all(mac: true, include_disabled: true).select do |device|
        device.enabled?
    end

    my_total_devices = {}

    devices.each do |item|
        device_item =  DeviceItem.new
        device_item.name = item.name
        device_item.name = device_item.name.downcase
        device_item.udid = item.udid
        device_item.platform = item.platform
        device_item.device_model = item.model
        device_item.device_type = item.device_type

        device_item.device_description = ""
        my_total_devices[item.udid] = device_item
    end

    mac_disabled_devices.each do |item|
        # puts item
        device_item =  DeviceItem.new
        device_item.name = item.name
        device_item.name = device_item.name.downcase
        device_item.udid = item.udid
        device_item.platform = item.platform
        device_item.device_model = item.model
        device_item.device_type = item.device_type
        device_item.device_description = ""
        my_total_devices[item.udid] = device_item
    end



    use_devices =  read_user_csv()

    use_devices.each do |key, item|
        if !my_total_devices[key].nil?

            if !item.device_description.nil?
                my_total_devices[key].device_description = item.device_description
            end
            if my_total_devices[key].device_description.nil? || my_total_devices[key].device_description.eql?("")
                my_total_devices[key].device_description = item.name.to_s.downcase
            end

            if my_total_devices[key].device_model.nil? || my_total_devices[key].device_model.eql?("")
                my_total_devices[key].device_model = item.device_model

            end
            if my_total_devices[key].device_model.nil? || my_total_devices[key].device_model.eql?("")
                my_total_devices[key].device_model = item.name.to_s.downcase
            end
        end
    end




    pgyer_devices =  read_apppgyer_csv()
    pgyer_devices.each do |key, item|
        if !my_total_devices[key].nil?

            if !item.device_description.nil?
                my_total_devices[key].device_description = item.device_description
            end
        end
    end


    # my_total_devices =  read_user_csv()


    write_appstore_text(devices:my_total_devices)
    # write_user_csv(devices:my_total_devices)
    write_apppgyer_csv(devices:my_total_devices)

end

#loginObject



60
61
62
63
# File 'lib/pindo/command/utils/device.rb', line 60

def 
    Spaceship::Portal.(pindo_single_config.demo_apple_id)
    Spaceship::Portal.select_team
end

#read_apppgyer_csvObject



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/pindo/command/utils/device.rb', line 208

def read_apppgyer_csv()

    devices = {}


    device_file = File.join(Dir.pwd, "pgyer_devices_list.csv");
    if File.exist?(device_file)
        line_num=0
        CSV.foreach(device_file, headers:false) do |row|
            if line_num > 0 
                device_item =  DeviceItem.new
                device_item.device_model = row[0] 
                device_item.udid = row[1] 
                device_item.device_type = row[2] 
                device_item.name = row[3] 
                device_item.device_description = row[4] 
                devices[device_item.udid] = device_item
            end
            line_num += 1
        end
    end


    return devices

end

#read_user_csvObject



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/pindo/command/utils/device.rb', line 249

def read_user_csv()

    devices = {}

    device_file = File.join(Dir.pwd, "user_devices_list.csv");

    if File.exist?(device_file)
        puts 1111
        line_num=0
        CSV.foreach(device_file, headers:false) do |row|
            if line_num > 0 
                device_item =  DeviceItem.new
                device_item.name = row[0] 
                device_item.udid = row[1] 
                device_item.device_type = row[2] 
                device_item.device_model = row[3] 
                device_item.device_description = row[4] 
                devices[device_item.udid] = device_item
            end
            line_num += 1
        end
    end
    # puts devices
    return devices

end

#runObject



51
52
53
54
55
56
57
# File 'lib/pindo/command/utils/device.rb', line 51

def run

    
    fetch_device
   
    
end

#validate!Object



47
48
49
# File 'lib/pindo/command/utils/device.rb', line 47

def validate!
    super
end

#write_apppgyer_csv(devices: nil) ⇒ Object



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/pindo/command/utils/device.rb', line 179

def write_apppgyer_csv(devices:nil)

    device_file = File.join(Dir.pwd, "new_pgyer_devices_list.csv");

    devices.each do |key, item|
        if item.device_type.to_s.eql?("ipad")
            item.device_type = "iPad"
        elsif item.device_type.to_s.eql?("iphone")
            item.device_type = "iPhone"
        elsif item.device_type.to_s.eql?("watch")
            item.device_type = "Apple Watch"
        elsif item.device_type.to_s.eql?("appleSiliconMac")
            item.device_type = "Mac"
        elsif item.device_type.to_s.eql?("mac")
            item.device_type = "Mac"
        end
    end


    CSV.open(device_file, "wb") do |csv|
      csv << ["型号", "udid", "设备类型", "设备名称", "备注", "udid来源", "添加时间"]
      
        devices.each do |key, device|
            csv << [device.device_model,device.udid,device.device_type,device.name ,device.device_description]
        end
    end
end

#write_appstore_text(devices: nil) ⇒ Object



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/pindo/command/utils/device.rb', line 150

def write_appstore_text(devices:nil)

    device_file = File.join(Dir.pwd, "new_devices_list.txt");

    str_text = String.new
    str_text = "DEVICE ID\tDEVICE NAME\tDEVICE PLATFORM\n"
    devices.each do |key, device|
        if device.platform.nil? || !(device.platform.to_s.eql?("ios") || device.platform.to_s.eql?("mac"))
            if device.device_type.to_s.downcase!.eql?("mac")
                device.platform = "mac"
            else
                device.platform = "ios"
            end
        end
        str = String.new
        str = str + device.udid
        str = str +  "\t"
        str = str + device.name 
        str = str +  "\t"
        str = str + device.platform
        str = str + "\n"
        str_text = str_text + str
    end

    File.open(device_file, "w") do |f|
        f.write(str_text)
    end
end

#write_user_csv(devices: nil) ⇒ Object



236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/pindo/command/utils/device.rb', line 236

def write_user_csv(devices:nil)

    device_file = File.join(Dir.pwd, "new_user_devices_list.csv");

    CSV.open(device_file, "wb") do |csv|
      csv << ["设备名称", "udid", "设备类型", "型号", "备注"]
      
        devices.each do |key, device|
            csv << [device.name,device.udid,device.device_type,device.device_model ,device.device_description]
        end
    end
end