dtk-client 0.6.7 → 0.6.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YzJhNmY1YjNmMTQxNzRhMzI0NmZjOGYxYjczM2EwNDc3NjdiYTAxMg==
4
+ ZTNhNzQ0NThlZmEwYTM4MTBjY2VmYWRkMjM1MTNiOTk1NGFiNWEwYQ==
5
5
  data.tar.gz: !binary |-
6
- YWZiMDcxNWJkYmEwMzI3NGIyMzMwY2FmZWQ4OTk1NWVmZmUzYWY5ZQ==
6
+ NTlmMzU3OTZmYTdkNjVhMWVlYThiNWE5YmVlOGE1NDQxNGJlYjhlZA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MWZlMTBiYTUwMGIwZjU5MzU0ZjNlNWY0NGVkMjcwOWZlNDk0ODU1YTM5ZWIy
10
- NjY2NDQzOTBjMjFjNmQwM2U4YjQwMGFmMjU1OTVmYThiNzQ5MDZiZDg4MjY5
11
- OTdkNDUwODBmMGUwZWZkMjA3Yjg4NzU1ZTI2OTdiM2NkOWZmYjg=
9
+ OTc0YjFhOTUzOGVmMmViMjNiMzY4MzcyZWFkMTA4M2NhY2YyZDgyMThhMThm
10
+ MjJlMzVlNWU4NTI3YWNjODI5YmJhMzE1YjE3ZGVhODc4NjAzZmFhZTI1OTE4
11
+ ZDEwMzQzMDJlM2M3MmY3YmQ4MjUwZjQ5OTY0ZGVlZGQ1OGZlNDk=
12
12
  data.tar.gz: !binary |-
13
- MzUzOTVmMzhlYzg2MzcwMGVmMWZmY2M2NDg1ODhlNGQ4NWMwNWIzMTJlZTQ4
14
- NTNmZWRlZWU4YmI5ZTExMGQwYmE3ZGU4ZDc3NGI3ZDgzMzNmZWQyODZhMThi
15
- M2M1Yjg0YmYxNmFjNTkxNDUwNWQ5ZDhjOWZmZGQzZDY5MDAwYTQ=
13
+ ZjIwY2M4NWFiYmUwOWUwNDU5MGQ4ODBmNWQ1NDgwZjA3MDcyM2NjOTY3OGVi
14
+ YTVmOGIyMmI3YmY4OWUxNDI0OTQyODY4M2VmZmE3YTQzNzgwYzBkNDZjZDNi
15
+ OWUyMzkzYTYyMWY5NTIyMTE1YjkyNjRiNzM0MmUwZDg0ZWVhNzE=
@@ -28,7 +28,14 @@ module DTK; module Client; class CommandHelper
28
28
 
29
29
  target_repo_dir = local_repo_dir(type,full_name,version,opts)
30
30
  if File.exists?(target_repo_dir)
31
- raise ErrorUsage.new("Directory '#{target_repo_dir}' is not empty; it must be deleted or removed before retrying the command")
31
+ # if local copy of module exists then move that module to backups location
32
+ if opts[:backup_if_exist]
33
+ backup_dir = backup_dir(type, full_name)
34
+ FileUtils.mv(target_repo_dir, backup_dir)
35
+ puts "Backup of existing module directory moved to '#{backup_dir}'"
36
+ else
37
+ raise ErrorUsage.new("Directory '#{target_repo_dir}' is not empty; it must be deleted or removed before retrying the command", :log_error => false)
38
+ end
32
39
  end
33
40
 
34
41
  begin
@@ -44,7 +51,7 @@ module DTK; module Client; class CommandHelper
44
51
 
45
52
  DtkLogger.instance.error_pp(e.message, e.backtrace)
46
53
 
47
- raise ErrorUsage.new(error_msg,:log_error=>false)
54
+ raise ErrorUsage.new(error_msg, :log_error => false)
48
55
  end
49
56
  {"module_directory" => target_repo_dir}
50
57
  end
@@ -84,6 +91,14 @@ module DTK; module Client; class CommandHelper
84
91
  end
85
92
  end
86
93
 
94
+ def get_remote_diffs(type, module_name, version, opts={})
95
+ Response.wrap_helper_actions() do
96
+ repo_dir = local_repo_dir(type,module_name,version)
97
+ repo = create(repo_dir,opts[:local_branch])
98
+ get_remote_diffs_aux(repo,opts)
99
+ end
100
+ end
101
+
87
102
  # opts can have the following keys
88
103
  #
89
104
  # :remote_repo
@@ -245,10 +260,14 @@ module DTK; module Client; class CommandHelper
245
260
  new(repo.diff_summary(local_branch,remote_reference))
246
261
  end
247
262
 
248
- def self.diff_remote(repo,ref1)
249
- new(repo.diff(ref1).ret_summary())
263
+ def self.diff_remote(repo,local_branch,remote_reference)
264
+ new(repo.diff_remote_summary(local_branch,remote_reference))
250
265
  end
251
266
 
267
+ # def self.diff_remote(repo,ref1)
268
+ # new(repo.diff(ref1).ret_summary())
269
+ # end
270
+
252
271
  def any_diffs?
253
272
  changes = false
254
273
  self.each do |k,v|
@@ -353,6 +372,37 @@ module DTK; module Client; class CommandHelper
353
372
  {"diffs" => diffs, "commit_sha" => commit_sha, "repo_obj" => repo, "status" => repo.local_summary() }
354
373
  end
355
374
 
375
+ def get_remote_diffs_aux(repo,opts={})
376
+ diffs = DiffSummary.new()
377
+ #add any file that is untracked
378
+
379
+ # repo.stage_changes()
380
+ if opts[:remote_repo] and opts[:remote_repo_url]
381
+ repo.add_remote(opts[:remote_repo],opts[:remote_repo_url])
382
+ end
383
+
384
+ unless opts[:no_fetch]
385
+ repo.fetch(remote(opts[:remote_repo]))
386
+ end
387
+
388
+ local_branch = repo.local_branch_name
389
+ remote_branch_ref = remote_branch_ref(local_branch, opts)
390
+
391
+ commit_shas = Hash.new
392
+ merge_rel = repo.merge_relationship(:remote_branch, remote_branch_ref, :ret_commit_shas => commit_shas)
393
+ commit_sha = nil
394
+
395
+ if merge_rel == :equal
396
+ commit_sha = commit_shas[:other_sha]
397
+ elsif merge_rel == :no_remote_ref
398
+ diffs = DiffSummary.new_version(repo)
399
+ commit_sha = commit_shas[:local_sha]
400
+ end
401
+
402
+ diffs = DiffSummary.diff_remote(repo,local_branch, remote_branch_ref)
403
+ { "diffs" => (diffs[:diffs]||"").to_s, "status" => repo.local_summary() }
404
+ end
405
+
356
406
  def pull_repo_changes_aux(repo,opts={})
357
407
  diffs = DiffSummary.new()
358
408
 
@@ -417,7 +467,8 @@ module DTK; module Client; class CommandHelper
417
467
  "#{remote(opts[:remote_repo])}/#{opts[:remote_branch]||opts[:local_branch]||local_branch}"
418
468
  end
419
469
 
420
- def modules_dir(type,module_name,version=nil,opts={})
470
+ def modules_dir(type, module_name, version=nil, opts={})
471
+ type = type.to_sym
421
472
  if assembly_module = opts[:assembly_module]
422
473
  OsUtil.module_location_parts(type,module_name,version,opts)[0]
423
474
  elsif type == :component_module
@@ -435,6 +486,16 @@ module DTK; module Client; class CommandHelper
435
486
  OsUtil.module_location(type,full_module_name,version,opts)
436
487
  end
437
488
 
489
+ def backup_dir(type, full_module_name, opts={})
490
+ namespace, name = full_module_name.split(':', 2)
491
+ module_type = type.split('_').first
492
+ backups_dir = OsUtil.backups_location()
493
+
494
+ # create backups dir if deleted for some reason
495
+ FileUtils::mkdir_p(backups_dir) unless File.directory?(backups_dir)
496
+ "#{backups_dir}/#{module_type}-#{namespace}-#{name}-#{Time.now.to_i}"
497
+ end
498
+
438
499
  def adapter_class()
439
500
  Common::GritAdapter::FileAccess
440
501
  end
@@ -8,10 +8,13 @@ dtk_require_common_commands('thor/task_status')
8
8
  dtk_require_common_commands('thor/set_required_params')
9
9
  dtk_require_common_commands('thor/edit')
10
10
  dtk_require_common_commands('thor/purge_clone')
11
+ dtk_require_common_commands('thor/list_diffs')
11
12
  LOG_SLEEP_TIME_W = DTK::Configuration.get(:tail_log_frequency)
12
13
 
13
14
  module DTK::Client
14
15
  module AssemblyWorkspaceMixin
16
+ include ListDiffsMixin
17
+
15
18
  REQ_ASSEMBLY_OR_WS_ID = [:service_id!, :workspace_id!]
16
19
 
17
20
  def get_name(assembly_or_workspace_id)
@@ -139,14 +142,9 @@ module DTK::Client
139
142
 
140
143
  def edit_module_aux(context_params)
141
144
  assembly_or_workspace_id, component_module_name = context_params.retrieve_arguments([REQ_ASSEMBLY_OR_WS_ID,:option_1!],method_argument_names)
142
- post_body = {
143
- :assembly_id => assembly_or_workspace_id,
144
- :module_name => component_module_name,
145
- :module_type => 'component_module'
146
- }
147
- response = post rest_url("assembly/prepare_for_edit_module"), post_body
148
- return response unless response.ok?
149
145
 
146
+ response = prepare_for_edit_module(assembly_or_workspace_id, component_module_name)
147
+ return response unless response.ok?
150
148
 
151
149
  assembly_name,component_module_id,version,repo_url,branch,commit_sha,full_module_name = response.data(:assembly_name,:module_id,:version,:repo_url,:workspace_branch,:branch_head_sha,:full_module_name)
152
150
  component_module_name = full_module_name if full_module_name
@@ -170,6 +168,24 @@ module DTK::Client
170
168
  edit_aux(:component_module,component_module_id,component_module_name,version,edit_opts)
171
169
  end
172
170
 
171
+ def list_remote_module_diffs(context_params)
172
+ assembly_or_workspace_id, component_module_name = context_params.retrieve_arguments([REQ_ASSEMBLY_OR_WS_ID,:option_1!],method_argument_names)
173
+ response = prepare_for_edit_module(assembly_or_workspace_id, component_module_name)
174
+ return response unless response.ok?
175
+
176
+ assembly_name,component_module_id,workspace_branch,commit_sha,module_branch_idh,repo_id = response.data(:assembly_name,:module_id,:workspace_branch,:branch_head_sha,:module_branch_idh,:repo_id)
177
+ list_component_module_diffs(component_module_id, assembly_name, workspace_branch, commit_sha, module_branch_idh['guid'], repo_id)
178
+ end
179
+
180
+ def prepare_for_edit_module(assembly_or_workspace_id, component_module_name)
181
+ post_body = {
182
+ :assembly_id => assembly_or_workspace_id,
183
+ :module_name => component_module_name,
184
+ :module_type => 'component_module'
185
+ }
186
+ response = post rest_url("assembly/prepare_for_edit_module"), post_body
187
+ end
188
+
173
189
  def edit_workflow_aux(context_params)
174
190
  assembly_or_workspace_id = context_params.retrieve_arguments([REQ_ASSEMBLY_OR_WS_ID],method_argument_names)
175
191
  post_body = {
@@ -9,7 +9,7 @@ module DTK::Client
9
9
  # This will change behaviour of method
10
10
  # module_type: will be :component_module or :service_module
11
11
 
12
- def clone_aux(module_type, module_id,version,internal_trigger,omit_output=false,opts={})
12
+ def clone_aux(module_type, module_id,version,internal_trigger=false,omit_output=false,opts={})
13
13
  module_name,module_namespace,repo_url,branch,not_ok_response = workspace_branch_info(module_type,module_id,version,opts)
14
14
  full_module_name = ModuleUtil.resolve_name(module_name, module_namespace)
15
15
 
@@ -19,8 +19,10 @@ module DTK::Client
19
19
 
20
20
  if response.ok?
21
21
  puts "Module '#{full_module_name}' has been successfully cloned!" unless omit_output
22
+ # when puppet forge import, print successfully imported instead of cloned
23
+ DTK::Client::OsUtil.print("Module '#{full_module_name}' has been successfully imported!", :yellow) if omit_output && opts[:print_imported]
22
24
  unless internal_trigger
23
- if Console.confirmation_prompt("Would you like to edit cloned module now?")
25
+ if Console.confirmation_prompt("Would you like to edit module now?")
24
26
  context_params_for_module = create_context_for_module(full_module_name, module_type)
25
27
  return edit(context_params_for_module)
26
28
  # if module_type.to_s.eql?("service_module")
@@ -13,14 +13,14 @@ module DTK::Client
13
13
 
14
14
  ##
15
15
  #
16
- # module_type: will be one of
16
+ # module_type: will be one of
17
17
  # :component_module
18
- # :service_module
18
+ # :service_module
19
19
  def edit_aux(module_type,module_id,module_name,version,opts={})
20
20
  module_location = OsUtil.module_location(module_type,module_name,version,opts)
21
21
 
22
22
  pull_if_needed = opts[:pull_if_needed]
23
- # check if there is repository cloned
23
+ # check if there is repository cloned
24
24
  unless File.directory?(module_location)
25
25
  if opts[:automatically_clone] or Console.confirmation_prompt("Edit not possible, module '#{module_name}#{version && "-#{version}"}' has not been cloned. Would you like to clone module now"+'?')
26
26
  internal_trigger = true
@@ -43,7 +43,7 @@ module DTK::Client
43
43
  grit_adapter = Helper(:git_repo).create(module_location)
44
44
  if edit_info = opts[:edit_file]
45
45
  #TODO: cleanup so dont need :base_file_name
46
- file_to_edit =
46
+ file_to_edit =
47
47
  if edit_info.kind_of?(String)
48
48
  edit_info
49
49
  else #edit_info.kind_of?(Hash) and has key :base_file_name
@@ -76,7 +76,7 @@ module DTK::Client
76
76
 
77
77
  # if there is no auto commit ask for confirmation
78
78
  unless auto_commit
79
- confirm_msg =
79
+ confirm_msg =
80
80
  if file_to_edit
81
81
  "Would you like to commit changes to the file?"
82
82
  else
@@ -85,7 +85,7 @@ module DTK::Client
85
85
  confirmed_ok = Console.confirmation_prompt(confirm_msg)
86
86
  end
87
87
  if (auto_commit || confirmed_ok)
88
- if auto_commit
88
+ if auto_commit
89
89
  puts "[NOTICE] You are using auto-commit option, all changes you have made will be commited."
90
90
  end
91
91
  commit_msg = user_input("Commit message")
@@ -95,13 +95,14 @@ module DTK::Client
95
95
 
96
96
  internal_trigger=true
97
97
  reparse_aux(module_location)
98
+ opts.merge!(:force_parse => true, :update_from_includes => true, :print_dependencies => true)
98
99
  response = push_clone_changes_aux(module_type,module_id,version,commit_msg,internal_trigger,opts)
99
-
100
+
100
101
  # if error return
101
102
  return response unless response.ok?
102
103
  end
103
104
 
104
- #TODO: temporary took out; wil put back in
105
+ #TODO: temporary took out; wil put back in
105
106
  #puts "DTK SHELL TIP: Adding the client configuration parameter <config param name>=true will have the client automatically commit each time you exit edit mode" unless auto_commit
106
107
  Response::Ok.new()
107
108
  end
@@ -139,7 +140,7 @@ module DTK::Client
139
140
  #processed_val can be false so explicitly checking against nil
140
141
  unless processed_val.nil?
141
142
  ret.merge!(k => processed_val)
142
- end
143
+ end
143
144
  end
144
145
  ret
145
146
  end
@@ -148,7 +149,7 @@ module DTK::Client
148
149
  ret = Array.new
149
150
  array.each do |a|
150
151
  # explicit nil not removed
151
- if a.nil?
152
+ if a.nil?
152
153
  ret << Response::Term.nil()
153
154
  else
154
155
  processed_val = post_process(a)
@@ -167,7 +168,7 @@ end
167
168
  =begin
168
169
  # TODO: probably deprecate
169
170
  def attribute_header()
170
- header_string =
171
+ header_string =
171
172
  "#############################\n#### REQUIRED ATTRIBUTES\n#############################\n#\n"
172
173
  end
173
174
  # TODO: probably deprecate
@@ -179,15 +180,15 @@ end
179
180
  first_iteration_keys, first_iteration_values = [], []
180
181
  second_iteration_keys, second_iteration_values = [], []
181
182
  required_attributes = []
182
-
183
+
183
184
  attribute_pairs = YAML.load(attributes)
184
-
185
+
185
186
  attribute_pairs.each do |k,v|
186
187
  first_iteration_keys << k
187
188
 
188
189
  #prepare required attributes for editor display
189
190
  if v.eql?("*REQUIRED*")
190
- required_attributes << k
191
+ required_attributes << k
191
192
  attribute_pairs[k] = nil
192
193
  v = nil
193
194
  end
@@ -225,7 +226,7 @@ end
225
226
  edited_keys = second_iteration_keys.select{|k| !first_iteration_keys.include?(k)}
226
227
  raise DtkValidationError, "You have changed key(s) '#{edited_keys}'. We do not support key editing yet!"
227
228
  end
228
-
229
+
229
230
  raise DtkValidationError, "No attribute changes have been made." if ((first_iteration_keys == second_iteration_keys) && (first_iteration_values == second_iteration_values))
230
231
  edited
231
232
  else
@@ -26,35 +26,61 @@ module DTK::Client
26
26
  }
27
27
  version = response.data(:version)
28
28
 
29
- response = Helper(:git_repo).get_diffs(module_type,module_name,version,opts)
29
+ # response = Helper(:git_repo).get_diffs(module_type,module_name,version,opts)
30
+ response = Helper(:git_repo).get_remote_diffs(module_type,module_name,version,opts)
30
31
  return response unless response.ok?
31
32
 
32
- added, deleted, modified = print_diffs(response.data(remote ? :diffs : :status), remote)
33
+ added, deleted, modified = print_diffs(response.data(:status), remote)
34
+ diffs = response.data(:diffs)
33
35
 
34
- raise DTK::Client::DtkValidationError, "There is no changes in current workspace!" if(added.empty? && deleted.empty? && modified.empty?)
36
+ raise DTK::Client::DtkValidationError, "There are no changes in current workspace!" if(added.empty? && deleted.empty? && modified.empty? && diffs.empty?)
37
+ puts "#{diffs}" unless (diffs||"").empty?
35
38
 
36
39
  unless added.empty?
37
- puts "ADDED:"
40
+ puts "\nNew file(s):"
38
41
  added.each do |a|
39
42
  puts "\t #{a.inspect}"
40
43
  end
41
44
  end
42
45
 
43
46
  unless deleted.empty?
44
- puts "DELETED:"
47
+ puts "\nDeleted file(s):"
45
48
  deleted.each do |d|
46
49
  puts "\t #{d.inspect}"
47
50
  end
48
51
  end
49
-
50
- unless modified.empty?
51
- puts "MODIFIED:"
52
- modified.each do |m|
53
- puts "\t #{m.inspect}"
54
- end
55
- end
56
52
  end
57
53
 
54
+ def list_remote_diffs_aux(module_type, module_id)
55
+ id_field = "#{module_type}_id"
56
+
57
+ post_body = {
58
+ id_field => module_id
59
+ }
60
+
61
+ response = post(rest_url("#{module_type}/list_remote_diffs"),post_body)
62
+ return response unless response.ok?
63
+
64
+ raise DTK::Client::DtkValidationError, "There are no diffs between module on server and remote repo!" if response.data.empty?
65
+ response
66
+ end
67
+
68
+ def list_component_module_diffs(module_id, assembly_name, workspace_branch, commit_sha, module_branch_id, repo_id)
69
+ post_body = {
70
+ :module_id => module_id,
71
+ :assembly_name => assembly_name,
72
+ :workspace_branch => workspace_branch,
73
+ :module_branch_id => module_branch_id,
74
+ :repo_id => repo_id
75
+ }
76
+
77
+ response = post(rest_url("assembly/list_component_module_diffs"),post_body)
78
+ return response unless response.ok?
79
+
80
+ raise DTK::Client::DtkValidationError, "There are no diffs between module in service instance and base module!" if response.data.empty?
81
+ response
82
+ end
83
+
58
84
  def print_diffs(response, remote)
59
85
  added = []
60
86
  deleted = []
@@ -0,0 +1,249 @@
1
+ dtk_require_from_base("util/os_util")
2
+
3
+ # For Aldin: dont thing these are needed although this may be stylistic, which is fine; just putting here to make where the include
4
+ # include ReparseMixin
5
+ # ..
6
+ # are comming from
7
+ dtk_require_common_commands('thor/push_clone_changes')
8
+ dtk_require_common_commands('thor/reparse')
9
+ dtk_require_common_commands('thor/common')
10
+
11
+ dtk_require_from_base('commands')
12
+ dtk_require_from_base("command_helper")
13
+
14
+ module DTK::Client
15
+ class CommonModule
16
+ class Import < self
17
+ include CommandBase
18
+ include CommandHelperMixin
19
+ include PushCloneChangesMixin
20
+ include ReparseMixin
21
+
22
+ # For Rich: this is used for import-git
23
+ def from_git()
24
+ git_repo_url, module_name = retrieve_arguments([:option_1!, :option_2!])
25
+ namespace, local_module_name = get_namespace_and_name(module_name, ModuleUtil::NAMESPACE_SEPERATOR)
26
+
27
+ module_type = @command.get_module_type(@context_params)
28
+ thor_options = { :git_import => true}
29
+
30
+ unless namespace
31
+ namespace_response = post rest_url("namespace/default_namespace_name")
32
+ return namespace_response unless namespace_response.ok?
33
+
34
+ namespace = namespace_response.data
35
+ thor_options[:default_namespace] = namespace
36
+ end
37
+
38
+ opts = {
39
+ :namespace => namespace,
40
+ :branch => @options['branch']
41
+ }
42
+ response = Helper(:git_repo).create_clone_from_optional_branch(module_type.to_sym, local_module_name, git_repo_url, opts)
43
+ return response unless response.ok?
44
+
45
+ # Remove .git directory to rid of git pointing to user's github
46
+ FileUtils.rm_rf("#{response['data']['module_directory']}/.git")
47
+
48
+ @context_params.forward_options(thor_options)
49
+ create_response = from_git_or_file()
50
+
51
+ if create_response.ok?
52
+ module_name, module_namespace, repo_url, branch, not_ok_response = workspace_branch_info(module_type, create_response.data['module_id'], create_response.data['version'])
53
+ create_response = not_ok_response if not_ok_response
54
+ end
55
+
56
+ unless create_response.ok?
57
+ delete_dir = namespace.nil? ? local_module_name : "#{namespace}/#{local_module_name}"
58
+ full_module_name = create_response.data[:full_module_name]
59
+ local_module_name = full_module_name.nil? ? delete_dir : full_module_name
60
+
61
+ @command.delete_module_sub_aux(@context_params, local_module_name, :force_delete => true, :no_error_msg => true, :purge => true)
62
+ return create_response
63
+ end
64
+
65
+ opts_pull = {
66
+ :local_branch => branch,
67
+ :namespace => module_namespace
68
+ }
69
+ pull_response = Helper(:git_repo).pull_changes(module_type, module_name, opts_pull)
70
+ return pull_response unless pull_response.ok?
71
+
72
+ if external_dependencies = create_response.data(:external_dependencies)
73
+ print_external_dependencies(external_dependencies, 'in the git repo')
74
+ end
75
+
76
+ Response::Ok.new()
77
+ end
78
+
79
+ # For Rich: this is for import
80
+ def from_file()
81
+ module_type = @command.get_module_type(@context_params)
82
+ module_name = retrieve_arguments([:option_1!])
83
+ namespace, local_module_name = get_namespace_and_name(module_name, ModuleUtil::NAMESPACE_SEPERATOR)
84
+ opts = {}
85
+
86
+ response = from_git_or_file()
87
+ return response unless response.ok?
88
+
89
+ repo_obj = response.data['repo_obj']
90
+ module_final_dir = repo_obj.repo_dir
91
+ old_dir = response.data['old_dir']
92
+ new_module_name = response.data['new_module_name']
93
+
94
+ module_name, module_namespace, repo_url, branch, not_ok_response = workspace_branch_info(module_type, response.data['module_id'], response.data['version'])
95
+ return not_ok_response if not_ok_response
96
+
97
+ opts_pull = {
98
+ :local_branch => branch,
99
+ :namespace => module_namespace
100
+ }
101
+
102
+ dsl_updated_info = response.data(:dsl_updated_info)
103
+ dsl_created_info = response.data(:dsl_created_info)
104
+ external_dependencies = response.data(:external_dependencies)
105
+
106
+ dsl_updated_info = response.data(:dsl_updated_info)
107
+ if dsl_updated_info and !dsl_updated_info.empty?
108
+ new_commit_sha = dsl_updated_info[:commit_sha]
109
+ unless new_commit_sha and new_commit_sha == commit_sha
110
+ resp = Helper(:git_repo).pull_changes(module_type, module_name, opts_pull)
111
+ return resp unless resp.ok?
112
+ end
113
+ end
114
+
115
+ # For Aldin; wil update the server side to have dsl_created_info not have content when that is added on server side
116
+ # so setting acondition wrt to this and casing on this, i.e., whether need to commit file and then do push
117
+ # after we make sure working we can remove code that commits dsl file on client side
118
+ push_needed = false
119
+ if dsl_created_info and !dsl_created_info.empty?
120
+ path = dsl_created_info["path"]
121
+ msg = "A #{path} file has been created for you, located at #{module_final_dir}"
122
+ if content = dsl_created_info["content"]
123
+ resp = Helper(:git_repo).add_file(repo_obj, path, content, msg)
124
+ return resp unless resp.ok?
125
+ push_needed = true
126
+ end
127
+ end
128
+
129
+ ##### code that does push that can be removed once we always do commit of dsl on server side
130
+ if push_needed
131
+ if external_dependencies
132
+ ambiguous = external_dependencies['ambiguous']||[]
133
+ possibly_missing = external_dependencies["possibly_missing"]||[]
134
+ opts.merge!(:set_parsed_false => true, :skip_module_ref_update => true) unless ambiguous.empty? && possibly_missing.empty?
135
+ end
136
+
137
+ @context_params.add_context_to_params(local_module_name, module_type.to_s.gsub!(/\_/,'-').to_sym, response.data['module_id'])
138
+ response = push_module_aux(@context_params, true, opts)
139
+
140
+ unless response.ok?
141
+ # remove new directory and leave the old one if import without namespace failed
142
+ if old_dir and (old_dir != module_final_dir)
143
+ FileUtils.rm_rf(module_final_dir) unless namespace
144
+ end
145
+ return response
146
+ end
147
+ end
148
+ ##### end: code that does push
149
+
150
+ # remove source directory if no errors while importing
151
+ if old_dir and (old_dir != module_final_dir)
152
+ FileUtils.rm_rf(old_dir) unless namespace
153
+ end
154
+
155
+ if external_dependencies
156
+ print_external_dependencies(external_dependencies, 'dtk.model.yaml includes')
157
+ end
158
+
159
+ # if user do import from default directory (e.g. import ntp - without namespace) print message
160
+ DTK::Client::OsUtil.print("Module '#{new_module_name}' has been created and module directory moved to #{module_final_dir}",:yellow) unless namespace
161
+
162
+ Response::Ok.new()
163
+ end
164
+
165
+ # For Rich: common code for import-git and import
166
+ def from_git_or_file()
167
+ default_ns = @context_params.get_forwarded_options()[:default_namespace]
168
+ git_import = @context_params.get_forwarded_options()[:git_import]
169
+
170
+ name_option = git_import ? :option_2! : :option_1!
171
+ module_name = @context_params.retrieve_arguments([name_option])
172
+ module_type = @command.get_module_type(@context_params)
173
+ version = @options["version"]
174
+ create_response = {}
175
+
176
+ # extract namespace and module_name from full name (r8:maven will result in namespace = r8 & name = maven)
177
+ namespace, local_module_name = get_namespace_and_name(module_name, ModuleUtil::NAMESPACE_SEPERATOR)
178
+ namespace = default_ns if default_ns && namespace.nil?
179
+
180
+ # first check that there is a directory there and it is not already a git repo, and it ha appropriate content
181
+ response = Helper(:git_repo).check_local_dir_exists_with_content(module_type.to_sym, local_module_name, nil, namespace)
182
+ return response unless response.ok?
183
+
184
+ #check for yaml/json parsing errors before import
185
+ module_directory = response.data(:module_directory)
186
+ reparse_aux(module_directory)
187
+
188
+ # first make call to server to create an empty repo
189
+ post_body = {
190
+ :module_name => local_module_name,
191
+ :module_namespace => namespace
192
+ }
193
+ response = post(rest_url("#{module_type}/create"), post_body)
194
+ return response unless response.ok?
195
+
196
+ repo_url,repo_id,module_id,branch,new_module_name = response.data(:repo_url, :repo_id, :module_id, :workspace_branch, :full_module_name)
197
+ response = Helper(:git_repo).rename_and_initialize_clone_and_push(module_type.to_sym, local_module_name, new_module_name, branch, repo_url, module_directory)
198
+ return response unless (response && response.ok?)
199
+
200
+ repo_obj, commit_sha = response.data(:repo_obj, :commit_sha)
201
+ module_final_dir = repo_obj.repo_dir
202
+ old_dir = response.data[:old_dir]
203
+
204
+ post_body = {
205
+ :repo_id => repo_id,
206
+ :commit_sha => commit_sha,
207
+ :commit_dsl => true,
208
+ :scaffold_if_no_dsl => true,
209
+ "#{module_type}_id".to_sym => module_id
210
+ }
211
+ post_body.merge!(:git_import => true) if git_import
212
+ response = post(rest_url("#{module_type}/update_from_initial_create"), post_body)
213
+
214
+ unless response.ok?
215
+ response.set_data_hash({ :full_module_name => new_module_name })
216
+ # remove new directory and leave the old one if import without namespace failed
217
+ if old_dir and (old_dir != module_final_dir)
218
+ FileUtils.rm_rf(module_final_dir) unless (namespace && git_import)
219
+ end
220
+ return response
221
+ end
222
+
223
+ dsl_updated_info = response.data(:dsl_updated_info)
224
+ dsl_created_info = response.data(:dsl_created_info)
225
+ external_dependencies = response.data(:external_dependencies)
226
+ DTK::Client::OsUtil.print("A module_refs.yaml file has been created for you, located at #{module_final_dir}", :yellow) if dsl_updated_info && !dsl_updated_info.empty?
227
+ DTK::Client::OsUtil.print("A #{dsl_created_info["path"]} file has been created for you, located at #{module_final_dir}", :yellow) if dsl_created_info && !dsl_created_info.empty?
228
+
229
+ module_name, module_namespace, repo_url, branch, not_ok_response = workspace_branch_info(module_type, module_id, version)
230
+ return not_ok_response if not_ok_response
231
+
232
+ # For Rich: did not have time today, but should find better way to pass these arguments to from_git and from_file methods
233
+ # For Aldin: are all these values needed in teh calling fns. ANyways anotehr way to do it is to just set instance vars so from here
234
+ # @module_id = module_id
235
+ # then calling fn coudl just use @module_id
236
+ response.add_data_value!(:module_id, module_id)
237
+ response.add_data_value!(:version, version)
238
+ response.add_data_value!(:repo_obj, repo_obj)
239
+ response.add_data_value!(:old_dir, old_dir)
240
+ response.add_data_value!(:new_module_name, new_module_name)
241
+
242
+ response
243
+ end
244
+
245
+ private
246
+ # ... the methods that represent the basic steps of from_git and from_git_or_file
247
+ end
248
+ end
249
+ end