Class: Pindo::Pindoconfig

Inherits:
Object
  • Object
show all
Defined in:
lib/pindo/config/pindoconfig.rb

Defined Under Namespace

Modules: Mixin

Singleton collapse

Instance Attribute Summary collapse

Singleton collapse

Instance Method Summary collapse

Constructor Details

#initialize(enable_ustom_config = true) ⇒ Pindoconfig

Returns a new instance of Pindoconfig.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/pindo/config/pindoconfig.rb', line 14

def initialize(enable_ustom_config = true)
  
  # puts "initialize Pindoconfig"
  if !File.exist?(pindo_dir) 
    FileUtils.mkdir(pindo_dir)
  end



  @pindo_user_config_json = {}
  @pindo_user_config_json["pindo_common_config"] = "https://gitee.com/goodbuildtest/pindo_common_config.git"

  if File.exist?(pindo_common_configfile_fullname) 
    
    @pindo_common_config_json = {}
    begin
      @pindo_common_config_json = JSON.parse(File.read(pindo_common_configfile_fullname))  
    rescue => exception
      puts "Error !!! +++++++++++ load Pindo common config error !!!"
    end

    # 必须先覆盖给 @pindo_user_config_json , 后面pindo_env_configfile_fullname会使用到 @pindo_user_config_json
    if !@pindo_common_config_json.nil?
      @pindo_user_config_json = deep_copy_hash(des_hash:@pindo_user_config_json, src_hash:@pindo_common_config_json)
    end

  end

  env_name = pindo_user_env 
  temp_env_config_dir = nil

  if env_name == "dreamstudio_config" 
    temp_env_config_dir = "pindo_dreamstudio_config"
  elsif  env_name == "workhard_config" 
    temp_env_config_dir = "pindo_workhard_config"
  end

  if !temp_env_config_dir.nil? && File.exist?(File.join(pindo_dir, temp_env_config_dir))

      @pindo_env_config_json = {}

      file_name = pindo_env_configfile_fullname
      # puts "!!! +++++++++++  load Pindo env config !!!\n #{file_name}"
      @pindo_env_config_json = JSON.parse(File.read(file_name))  


      if !@pindo_env_config_json.nil?
        @pindo_user_config_json = deep_copy_hash(des_hash:@pindo_user_config_json, src_hash:@pindo_env_config_json)
      end
  end


end

Class Attribute Details

.instanceObject



441
442
443
# File 'lib/pindo/config/pindoconfig.rb', line 441

def self.instance
  @instance ||= new
end

Instance Attribute Details

#pindo_common_config_jsonObject

Returns the value of attribute pindo_common_config_json.



10
11
12
# File 'lib/pindo/config/pindoconfig.rb', line 10

def pindo_common_config_json
  @pindo_common_config_json
end

#pindo_env_config_jsonObject

Returns the value of attribute pindo_env_config_json.



11
12
13
# File 'lib/pindo/config/pindoconfig.rb', line 11

def pindo_env_config_json
  @pindo_env_config_json
end

#pindo_user_config_jsonObject

Returns the value of attribute pindo_user_config_json.



12
13
14
# File 'lib/pindo/config/pindoconfig.rb', line 12

def pindo_user_config_json
  @pindo_user_config_json
end

Class Method Details

.reload_instanceConfig

Returns the current config instance creating one if needed.

Returns:

  • (Config)

    the current config instance creating one if needed.



437
438
439
# File 'lib/pindo/config/pindoconfig.rb', line 437

def self.reload_instance
  @instance = new
end

Instance Method Details

#build_deploy_orgObject



352
353
354
355
356
357
358
# File 'lib/pindo/config/pindoconfig.rb', line 352

def build_deploy_org
  url = ''
  if !@pindo_user_config_json.nil? && !@pindo_user_config_json["gitee_repo_info"].nil?
    url =  @pindo_user_config_json["gitee_repo_info"]["appconfig_appstore_org"]
  end
  return url  
end

#build_test_orgObject



360
361
362
363
364
365
366
# File 'lib/pindo/config/pindoconfig.rb', line 360

def build_test_org
  url = ''
  if !@pindo_user_config_json.nil? && !@pindo_user_config_json["gitee_repo_info"].nil?
    url =  @pindo_user_config_json["gitee_repo_info"]["appconfig_test_org"]
  end
  return url  
end

#cert_key_passwordObject



284
285
286
287
288
289
290
# File 'lib/pindo/config/pindoconfig.rb', line 284

def cert_key_password
  cert_key_password = ''
  if !@pindo_user_config_json.nil? && !@pindo_user_config_json["develop_accout_info"].nil?
    cert_key_password =  @pindo_user_config_json["develop_accout_info"]["cert_key_password"]
  end
  return cert_key_password
end

#config_file_nameObject



192
193
194
# File 'lib/pindo/config/pindoconfig.rb', line 192

def config_file_name
  return "pindo_config.json"
end

#configure_with(values_by_key) ⇒ void

This method returns an undefined value.

Sets the values of the attributes with the given hash.

Parameters:

  • values_by_key (Hash{String,Symbol => Object})

    The values of the attributes grouped by key.



126
127
128
129
130
131
132
133
# File 'lib/pindo/config/pindoconfig.rb', line 126

def configure_with(values_by_key)

  return unless values_by_key
  values_by_key.each do |key, value|
    instance_variable_set("@#{key}", value)
  end

end

#crash_bundle_idObject



343
344
345
346
347
348
349
# File 'lib/pindo/config/pindoconfig.rb', line 343

def crash_bundle_id
  url = ''
  if !@pindo_user_config_json.nil? && !@pindo_user_config_json["develop_accout_info"].nil?
    url =  @pindo_user_config_json["develop_accout_info"]["crash_bundle_id"]
  end
  return url  
end

#deep_copy_hash(des_hash: nil, src_hash: nil) ⇒ Object



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
# File 'lib/pindo/config/pindoconfig.rb', line 69

def deep_copy_hash(des_hash:nil, src_hash:nil)

  res_hash = {}
  des_hash = des_hash || {}
  src_hash = src_hash || {}

  if !des_hash.nil? && (des_hash.kind_of? Hash)
    des_hash.each do |key, value|
        if !value.nil? && (value.kind_of? Hash)
          res_hash[key] = deep_copy_hash(des_hash:nil, src_hash:value)
        else
          res_hash[key] = value
        end
      end
  end

  if !src_hash.nil? && (src_hash.kind_of? Hash)
    src_hash.each do |key, value|
        if !value.nil? && (value.kind_of? Hash)
          res_hash[key] = deep_copy_hash(des_hash:nil, src_hash:value)
        else
          res_hash[key] = value
        end
      end
  end

  return res_hash
end

#demo_apple_idObject



327
328
329
330
331
332
333
# File 'lib/pindo/config/pindoconfig.rb', line 327

def demo_apple_id
  url = ''
  if !@pindo_user_config_json.nil? && !@pindo_user_config_json["develop_accout_info"].nil?
    url =  @pindo_user_config_json["develop_accout_info"]["demo_apple_id"]
  end
  return url      
end

#demo_bundle_idObject



335
336
337
338
339
340
341
# File 'lib/pindo/config/pindoconfig.rb', line 335

def demo_bundle_id
  url = ''
  if !@pindo_user_config_json.nil? && !@pindo_user_config_json["develop_accout_info"].nil?
    url =  @pindo_user_config_json["develop_accout_info"]["demo_bundle_id"]
  end
  return url   
end

#deploy_cert_decrypt_passwordObject



300
301
302
303
304
305
306
# File 'lib/pindo/config/pindoconfig.rb', line 300

def deploy_cert_decrypt_password
  pass = ''
  if !@pindo_user_config_json.nil? && !@pindo_user_config_json["develop_accout_info"].nil?
    pass =  @pindo_user_config_json["develop_accout_info"]["deploy_cert_decrypt_password"]
  end
  return pass
end

#deploy_cert_giturlObject



292
293
294
295
296
297
298
# File 'lib/pindo/config/pindoconfig.rb', line 292

def deploy_cert_giturl
  url = ''
  if !@pindo_user_config_json.nil? && !@pindo_user_config_json["develop_accout_info"].nil?
    url =  @pindo_user_config_json["develop_accout_info"]["deploy_cert_giturl"]
  end
  return url
end

#deploy_clang_giturlObject



242
243
244
245
246
247
248
249
# File 'lib/pindo/config/pindoconfig.rb', line 242

def deploy_clang_giturl
  url = ''
  if !@pindo_user_config_json.nil? && !@pindo_user_config_json["custome_build_system"].nil? then
    url =  @pindo_user_config_json["custome_build_system"]["deploy_clang_giturl"]
  end
  return url

end

#deploy_flutter_giturlObject



276
277
278
279
280
281
282
# File 'lib/pindo/config/pindoconfig.rb', line 276

def deploy_flutter_giturl
  url = ''
  if !@pindo_user_config_json.nil? && !@pindo_user_config_json["custome_build_system"].nil?
    url =  @pindo_user_config_json["custome_build_system"]["deploy_flutter_giturl"]
  end
  return url
end

#deploy_quark_giturlObject



260
261
262
263
264
265
266
# File 'lib/pindo/config/pindoconfig.rb', line 260

def deploy_quark_giturl
  url = ''
  if !@pindo_user_config_json.nil? && !@pindo_user_config_json["custome_build_system"].nil?
    url =  @pindo_user_config_json["custome_build_system"]["deploy_quark_giturl"]
  end
  return url
end

#deploy_swark_giturlObject



268
269
270
271
272
273
274
# File 'lib/pindo/config/pindoconfig.rb', line 268

def deploy_swark_giturl
  url = ''
  if !@pindo_user_config_json.nil? && !@pindo_user_config_json["custome_build_system"].nil?
    url =  @pindo_user_config_json["custome_build_system"]["deploy_swark_giturl"]
  end
  return url
end

#dev_cert_decrypt_passwordObject



319
320
321
322
323
324
325
# File 'lib/pindo/config/pindoconfig.rb', line 319

def dev_cert_decrypt_password
  pass = ''
  if !@pindo_user_config_json.nil? && !@pindo_user_config_json["develop_accout_info"].nil?
    pass =  @pindo_user_config_json["develop_accout_info"]["dev_cert_decrypt_password"]
  end
  return pass
end

#dev_cert_giturlObject



310
311
312
313
314
315
316
# File 'lib/pindo/config/pindoconfig.rb', line 310

def dev_cert_giturl
  url = ''
  if !@pindo_user_config_json.nil? && !@pindo_user_config_json["develop_accout_info"].nil?
    url =  @pindo_user_config_json["develop_accout_info"]["dev_cert_giturl"]
  end
  return url
end

#dev_clang_giturlObject



251
252
253
254
255
256
257
258
# File 'lib/pindo/config/pindoconfig.rb', line 251

def dev_clang_giturl
  url = ''
  if !@pindo_user_config_json.nil? && !@pindo_user_config_json["custome_build_system"].nil?
    url =  @pindo_user_config_json["custome_build_system"]["dev_clang_giturl"]
  end
  return url

end

#get_cert_infoObject



220
221
222
# File 'lib/pindo/config/pindoconfig.rb', line 220

def get_cert_info()
  return @set_cert_info 
end

#get_pgyerapps_info_listObject



409
410
411
# File 'lib/pindo/config/pindoconfig.rb', line 409

def get_pgyerapps_info_list
    return @app_info_list
end

#git_base_url_fullnameObject



401
402
403
# File 'lib/pindo/config/pindoconfig.rb', line 401

def git_base_url_fullname
  return @git_base_url_fullname ||= File.join(pindo_env_configdir,  "git_base_url.json")
end

#gitee_api_keyObject



368
369
370
371
372
373
374
# File 'lib/pindo/config/pindoconfig.rb', line 368

def gitee_api_key
  api_key = ''
  if !@pindo_user_config_json.nil? && !@pindo_user_config_json["gitee_repo_info"].nil?
    api_key =  @pindo_user_config_json["gitee_repo_info"]["gitee_api_key"]
  end
  return api_key  
end

#pgyer_api_keyObject



377
378
379
380
381
382
383
# File 'lib/pindo/config/pindoconfig.rb', line 377

def pgyer_api_key
  api_key = ''
  if !@pindo_user_config_json.nil? && !@pindo_user_config_json["pgyer_accout_info"].nil?
    api_key =  @pindo_user_config_json["pgyer_accout_info"]["pgyer_api_key"]
  end
  return api_key  
end

#pgyer_user_keyObject



385
386
387
388
389
390
391
# File 'lib/pindo/config/pindoconfig.rb', line 385

def pgyer_user_key
  api_key = ''
  if !@pindo_user_config_json.nil? && !@pindo_user_config_json["pgyer_accout_info"].nil?
    api_key =  @pindo_user_config_json["pgyer_accout_info"]["pgyer_user_key"]
  end
  return api_key  
end

#pindo_common_config_giturlObject



224
225
226
227
228
229
230
# File 'lib/pindo/config/pindoconfig.rb', line 224

def pindo_common_config_giturl
  url = ''  
  if !@pindo_user_config_json.nil?
    url =  @pindo_user_config_json["pindo_common_config"]  
  end
  return url
end

#pindo_common_configdirObject



196
197
198
# File 'lib/pindo/config/pindoconfig.rb', line 196

def pindo_common_configdir
  return @pindo_common_configdir ||= File.join(pindo_dir, "pindo_common_config")
end

#pindo_common_configfile_fullnameObject



200
201
202
# File 'lib/pindo/config/pindoconfig.rb', line 200

def pindo_common_configfile_fullname
  return @pindo_common_configfile_fullname ||= File.join(pindo_common_configdir, config_file_name)
end

#pindo_dirObject



188
189
190
# File 'lib/pindo/config/pindoconfig.rb', line 188

def pindo_dir
  return @pindo_dir ||= File.expand_path(ENV['PINDO_DIR'] || '~/.pindo')
end

#pindo_env_config_dirnameObject



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/pindo/config/pindoconfig.rb', line 168

def pindo_env_config_dirname
    env_config_dirname = nil

    begin
      url = pindo_env_config_giturl
      temp_url = String.new(url)
      index = temp_url.rindex('/') 
      temp_url = temp_url.slice(index + 1, temp_url.length) 
      env_config_dirname = temp_url.gsub!(/\.git/, "")

    rescue => err
        puts err
        raise Informative, "pindo配置错误 !!!\n \n 请运行pindo setup 更新pindo配置 \n"
    end

  return env_config_dirname

end

#pindo_env_config_giturlObject



232
233
234
235
236
237
238
239
# File 'lib/pindo/config/pindoconfig.rb', line 232

def pindo_env_config_giturl
  env = pindo_user_env();
  url = nil
  if !env.nil? && env != "" && !@pindo_user_config_json.nil? && !@pindo_user_config_json["pindo_config_env"].nil? then
    url =  @pindo_user_config_json["pindo_config_env"][env]
  end
  return url
end

#pindo_env_configdirObject



204
205
206
# File 'lib/pindo/config/pindoconfig.rb', line 204

def pindo_env_configdir
  return File.join(pindo_dir, pindo_env_config_dirname)
end

#pindo_env_configfile_fullnameObject



208
209
210
# File 'lib/pindo/config/pindoconfig.rb', line 208

def pindo_env_configfile_fullname
  return File.join(pindo_env_configdir, config_file_name)
end

#pindo_user_envObject



156
157
158
159
160
161
162
163
164
165
166
# File 'lib/pindo/config/pindoconfig.rb', line 156

def pindo_user_env

  pindo_env_file = File.join(pindo_dir, '.pindo_env')
  if File.exist?(pindo_env_file)
    pindo_env_file_json = JSON.parse(File.read(pindo_env_file))
    if pindo_env_file_json && pindo_env_file_json['pindo_env'] && pindo_env_file_json['pindo_env'] != "" then
      @pindo_user_env = pindo_env_file_json['pindo_env']
    end
  end
  return @pindo_user_env
end

#pod_repo_dictObject



393
394
395
396
397
398
399
# File 'lib/pindo/config/pindoconfig.rb', line 393

def pod_repo_dict
  repo_array = ''
  if !@pindo_user_config_json.nil?
    repo_array = @pindo_user_config_json["podindex_repo_dict"]
  end
  return repo_array  
end

#set_cert_info(dict: nil) ⇒ Object

————————————————————————-# ————————————————————————-#



216
217
218
# File 'lib/pindo/config/pindoconfig.rb', line 216

def set_cert_info(dict:nil)
  return @set_cert_info = dict
end

#set_pgyerapps_info_list(app_info_list: nil) ⇒ Object



405
406
407
# File 'lib/pindo/config/pindoconfig.rb', line 405

def set_pgyerapps_info_list(app_info_list:nil)
    @app_info_list = app_info_list
end

#tgate_base_urlObject



414
415
416
417
418
419
420
# File 'lib/pindo/config/pindoconfig.rb', line 414

def tgate_base_url
  tgate_base_url = ''
  if !@pindo_user_config_json.nil? && !@pindo_user_config_json["tgate_base_url"].nil?
    tgate_base_url =  @pindo_user_config_json["tgate_base_url"]
  end
  return tgate_base_url
end

#tgate_req_configObject



422
423
424
425
426
427
428
# File 'lib/pindo/config/pindoconfig.rb', line 422

def tgate_req_config
  tgate_req_config = nil
  if !@pindo_user_config_json.nil? && !@pindo_user_config_json["tgate_req_config"].nil?
    tgate_req_config =  @pindo_user_config_json["tgate_req_config"]
  end
  return tgate_req_config
end

#update_pindo_env(env_name: nil) ⇒ Object

————————————————————————-# ————————————————————————-#



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/pindo/config/pindoconfig.rb', line 138

def update_pindo_env(env_name:nil)
  if !env_name.nil? then
    @pindo_user_env = env_name
    pindo_env_file = File.join(pindo_dir, '.pindo_env')
    pindo_env_json = {}
    pindo_env_json['pindo_env'] = @pindo_user_env

    if !File.exist?(pindo_dir)
        FileUtils.mkdir(pindo_dir)
    end

    File.open(pindo_env_file, "w") do |f|
      f.write(JSON.pretty_generate(pindo_env_json))
    end
  end
  return @pindo_user_env
end

#with_changes(changes) { ... } ⇒ Object

Applies the given changes to the config for the duration of the given block.

Parameters:

  • changes (Hash<#to_sym,Object>)

    the changes to merge temporarily with the current config

Yields:

  • is called while the changes are applied



107
108
109
110
111
112
113
114
115
116
117
# File 'lib/pindo/config/pindoconfig.rb', line 107

def with_changes(changes)
  old = {}
  changes.keys.each do |key|
    key = key.to_sym
    old[key] = send(key) if respond_to?(key)
  end
  configure_with(changes)
  yield if block_given?
ensure
  configure_with(old)
end