dtk-shell 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (191) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +5 -0
  3. data/Gemfile_dev +13 -0
  4. data/README.md +121 -0
  5. data/bin/dtk-execute +32 -0
  6. data/bin/dtk-run +92 -0
  7. data/bin/dtk-shell +31 -0
  8. data/dtk-shell.gemspec +50 -0
  9. data/lib/auxiliary.rb +61 -0
  10. data/lib/bundler_monkey_patch.rb +26 -0
  11. data/lib/client.rb +58 -0
  12. data/lib/command_helper.rb +33 -0
  13. data/lib/command_helpers/git_repo.rb +589 -0
  14. data/lib/command_helpers/git_repo/merge.rb +153 -0
  15. data/lib/command_helpers/jenkins_client.rb +106 -0
  16. data/lib/command_helpers/jenkins_client/config_xml.rb +288 -0
  17. data/lib/command_helpers/service_importer.rb +251 -0
  18. data/lib/command_helpers/service_link.rb +33 -0
  19. data/lib/command_helpers/test_module_creator.rb +69 -0
  20. data/lib/command_helpers/test_module_templates/dtk.model.yaml.eruby +10 -0
  21. data/lib/command_helpers/test_module_templates/spec_helper.rb.eruby +10 -0
  22. data/lib/command_helpers/test_module_templates/temp_component_spec.rb.eruby +5 -0
  23. data/lib/commands.rb +57 -0
  24. data/lib/commands/common/thor/access_control.rb +133 -0
  25. data/lib/commands/common/thor/action_result_handler.rb +74 -0
  26. data/lib/commands/common/thor/assembly_template.rb +92 -0
  27. data/lib/commands/common/thor/assembly_workspace.rb +1801 -0
  28. data/lib/commands/common/thor/base_command_helper.rb +59 -0
  29. data/lib/commands/common/thor/clone.rb +82 -0
  30. data/lib/commands/common/thor/common.rb +88 -0
  31. data/lib/commands/common/thor/common_base.rb +49 -0
  32. data/lib/commands/common/thor/create_target.rb +70 -0
  33. data/lib/commands/common/thor/edit.rb +255 -0
  34. data/lib/commands/common/thor/inventory_parser.rb +98 -0
  35. data/lib/commands/common/thor/list_diffs.rb +128 -0
  36. data/lib/commands/common/thor/module.rb +1011 -0
  37. data/lib/commands/common/thor/module/import.rb +210 -0
  38. data/lib/commands/common/thor/node.rb +53 -0
  39. data/lib/commands/common/thor/poller.rb +65 -0
  40. data/lib/commands/common/thor/pull_clone_changes.rb +28 -0
  41. data/lib/commands/common/thor/pull_from_remote.rb +152 -0
  42. data/lib/commands/common/thor/puppet_forge.rb +72 -0
  43. data/lib/commands/common/thor/purge_clone.rb +101 -0
  44. data/lib/commands/common/thor/push_clone_changes.rb +162 -0
  45. data/lib/commands/common/thor/push_to_remote.rb +94 -0
  46. data/lib/commands/common/thor/remotes.rb +71 -0
  47. data/lib/commands/common/thor/reparse.rb +40 -0
  48. data/lib/commands/common/thor/set_required_attributes.rb +46 -0
  49. data/lib/commands/thor/account.rb +239 -0
  50. data/lib/commands/thor/assembly.rb +356 -0
  51. data/lib/commands/thor/attribute.rb +79 -0
  52. data/lib/commands/thor/component.rb +70 -0
  53. data/lib/commands/thor/component_module.rb +501 -0
  54. data/lib/commands/thor/component_template.rb +174 -0
  55. data/lib/commands/thor/dependency.rb +34 -0
  56. data/lib/commands/thor/developer.rb +144 -0
  57. data/lib/commands/thor/dtk.rb +152 -0
  58. data/lib/commands/thor/library.rb +125 -0
  59. data/lib/commands/thor/node.rb +504 -0
  60. data/lib/commands/thor/node_template.rb +94 -0
  61. data/lib/commands/thor/project.rb +34 -0
  62. data/lib/commands/thor/provider.rb +233 -0
  63. data/lib/commands/thor/remotes.rb +49 -0
  64. data/lib/commands/thor/service.rb +941 -0
  65. data/lib/commands/thor/service_module.rb +914 -0
  66. data/lib/commands/thor/state_change.rb +25 -0
  67. data/lib/commands/thor/target.rb +250 -0
  68. data/lib/commands/thor/task.rb +116 -0
  69. data/lib/commands/thor/test_module.rb +310 -0
  70. data/lib/commands/thor/utils.rb +21 -0
  71. data/lib/commands/thor/workspace.rb +685 -0
  72. data/lib/config/cacert.pem +3785 -0
  73. data/lib/config/client.conf.header +20 -0
  74. data/lib/config/configuration.rb +99 -0
  75. data/lib/config/default.conf +16 -0
  76. data/lib/config/disk_cacher.rb +80 -0
  77. data/lib/configurator.rb +176 -0
  78. data/lib/context_router.rb +44 -0
  79. data/lib/core.rb +497 -0
  80. data/lib/domain/git_adapter.rb +412 -0
  81. data/lib/domain/git_error_handler.rb +64 -0
  82. data/lib/domain/response.rb +285 -0
  83. data/lib/domain/response/error_handler.rb +86 -0
  84. data/lib/dtk-shell/version.rb +20 -0
  85. data/lib/dtk_constants.rb +40 -0
  86. data/lib/dtk_error.rb +114 -0
  87. data/lib/dtk_logger.rb +126 -0
  88. data/lib/dtk_shell.rb +31 -0
  89. data/lib/error.rb +85 -0
  90. data/lib/execute.rb +29 -0
  91. data/lib/execute/cli_pure/cli_rerouter.rb +102 -0
  92. data/lib/execute/command.rb +40 -0
  93. data/lib/execute/command/api_call.rb +60 -0
  94. data/lib/execute/command/api_call/map.rb +60 -0
  95. data/lib/execute/command/api_call/service.rb +91 -0
  96. data/lib/execute/command/api_call/translation_term.rb +119 -0
  97. data/lib/execute/command/rest_call.rb +37 -0
  98. data/lib/execute/command_processor.rb +30 -0
  99. data/lib/execute/command_processor/rest_call.rb +59 -0
  100. data/lib/execute/error_usage.rb +21 -0
  101. data/lib/execute/execute_context.rb +86 -0
  102. data/lib/execute/execute_context/result_store.rb +37 -0
  103. data/lib/execute/script.rb +64 -0
  104. data/lib/execute/script/add_tenant.rb +121 -0
  105. data/lib/git-logs/git.log +0 -0
  106. data/lib/parser/adapters/option_parser.rb +70 -0
  107. data/lib/parser/adapters/thor.rb +555 -0
  108. data/lib/parser/adapters/thor/common_option_defs.rb +40 -0
  109. data/lib/require_first.rb +104 -0
  110. data/lib/search_hash.rb +44 -0
  111. data/lib/shell.rb +261 -0
  112. data/lib/shell/context.rb +1065 -0
  113. data/lib/shell/context_aux.rb +46 -0
  114. data/lib/shell/domain/active_context.rb +186 -0
  115. data/lib/shell/domain/context_entity.rb +89 -0
  116. data/lib/shell/domain/context_params.rb +223 -0
  117. data/lib/shell/domain/override_tasks.rb +88 -0
  118. data/lib/shell/domain/shadow_entity.rb +76 -0
  119. data/lib/shell/header_shell.rb +44 -0
  120. data/lib/shell/help_monkey_patch.rb +283 -0
  121. data/lib/shell/interactive_wizard.rb +225 -0
  122. data/lib/shell/message_queue.rb +63 -0
  123. data/lib/shell/parse_monkey_patch.rb +39 -0
  124. data/lib/shell/status_monitor.rb +124 -0
  125. data/lib/task_status.rb +83 -0
  126. data/lib/task_status/refresh_mode.rb +77 -0
  127. data/lib/task_status/snapshot_mode.rb +28 -0
  128. data/lib/task_status/stream_mode.rb +48 -0
  129. data/lib/task_status/stream_mode/element.rb +101 -0
  130. data/lib/task_status/stream_mode/element/format.rb +101 -0
  131. data/lib/task_status/stream_mode/element/hierarchical_task.rb +100 -0
  132. data/lib/task_status/stream_mode/element/hierarchical_task/result.rb +72 -0
  133. data/lib/task_status/stream_mode/element/hierarchical_task/result/action.rb +93 -0
  134. data/lib/task_status/stream_mode/element/hierarchical_task/result/components.rb +26 -0
  135. data/lib/task_status/stream_mode/element/hierarchical_task/result/node_level.rb +26 -0
  136. data/lib/task_status/stream_mode/element/hierarchical_task/steps.rb +34 -0
  137. data/lib/task_status/stream_mode/element/hierarchical_task/steps/action.rb +53 -0
  138. data/lib/task_status/stream_mode/element/hierarchical_task/steps/components.rb +53 -0
  139. data/lib/task_status/stream_mode/element/hierarchical_task/steps/node_level.rb +42 -0
  140. data/lib/task_status/stream_mode/element/no_results.rb +26 -0
  141. data/lib/task_status/stream_mode/element/render.rb +59 -0
  142. data/lib/task_status/stream_mode/element/stage.rb +84 -0
  143. data/lib/task_status/stream_mode/element/stage/render.rb +76 -0
  144. data/lib/task_status/stream_mode/element/task_end.rb +35 -0
  145. data/lib/task_status/stream_mode/element/task_start.rb +37 -0
  146. data/lib/util/common_util.rb +37 -0
  147. data/lib/util/console.rb +235 -0
  148. data/lib/util/dtk_puppet.rb +65 -0
  149. data/lib/util/module_util.rb +66 -0
  150. data/lib/util/os_util.rb +385 -0
  151. data/lib/util/permission_util.rb +31 -0
  152. data/lib/util/remote_dependency_util.rb +84 -0
  153. data/lib/util/ssh_util.rb +94 -0
  154. data/lib/view_processor.rb +129 -0
  155. data/lib/view_processor/augmented_simple_list.rb +44 -0
  156. data/lib/view_processor/hash_pretty_print.rb +123 -0
  157. data/lib/view_processor/simple_list.rb +156 -0
  158. data/lib/view_processor/table_print.rb +309 -0
  159. data/lib/violation.rb +86 -0
  160. data/lib/violation/attribute.rb +76 -0
  161. data/lib/violation/fix.rb +26 -0
  162. data/lib/violation/fix/result.rb +73 -0
  163. data/lib/violation/fix/result/error.rb +34 -0
  164. data/lib/violation/fix/set_attribute.rb +41 -0
  165. data/lib/violation/sub_classes.rb +60 -0
  166. data/puppet/manifests/init.pp +72 -0
  167. data/puppet/manifests/params.pp +16 -0
  168. data/puppet/r8meta.puppet.yml +35 -0
  169. data/puppet/templates/bash_profile.erb +2 -0
  170. data/puppet/templates/client.conf.erb +1 -0
  171. data/puppet/templates/dtkclient.erb +2 -0
  172. data/spec/component_module_spec.rb +34 -0
  173. data/spec/dependency_spec.rb +6 -0
  174. data/spec/dtk_shell_spec.rb +13 -0
  175. data/spec/dtk_spec.rb +33 -0
  176. data/spec/lib/spec_helper.rb +10 -0
  177. data/spec/lib/spec_thor.rb +108 -0
  178. data/spec/node_template_spec.rb +24 -0
  179. data/spec/project_spec.rb +6 -0
  180. data/spec/repo_spec.rb +7 -0
  181. data/spec/response_spec.rb +52 -0
  182. data/spec/service_module_spec.rb +38 -0
  183. data/spec/service_spec.rb +50 -0
  184. data/spec/state_change_spec.rb +7 -0
  185. data/spec/table_print_spec.rb +48 -0
  186. data/spec/target_spec.rb +57 -0
  187. data/spec/task_spec.rb +28 -0
  188. data/views/assembly/augmented_simple_list.rb +12 -0
  189. data/views/assembly_template/augmented_simple_list.rb +12 -0
  190. data/views/list_task/augmented_simple_list.rb +12 -0
  191. metadata +421 -0
@@ -0,0 +1,72 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module DTK::Client
19
+ module PuppetForgeMixin
20
+
21
+ NAME_REGEX = /\w*\-\w/
22
+
23
+ def puppet_forge_install_aux(context_params, pf_module_name, module_name, namespace, version, module_type)
24
+ post_body_hash = {
25
+ :puppetf_module_name => pf_module_name,
26
+ :module_name? => module_name,
27
+ :module_version? => version,
28
+ :module_namespace? => namespace
29
+ }
30
+
31
+ raise DtkError, "Puppet forge module name should be in format NAMESPACE-MODULENAME" unless pf_module_name.match(NAME_REGEX)
32
+
33
+ response = poller_response do
34
+ post rest_url("component_module/install_puppet_forge_modules"), PostBody.new(post_body_hash)
35
+ end
36
+
37
+ return response unless response.ok?
38
+
39
+
40
+ installed_modules = response.data(:installed_modules)
41
+
42
+ print_modules(response.data(:found_modules), 'using')
43
+ print_modules(installed_modules, 'installed')
44
+
45
+ main_module = response.data(:main_module)
46
+
47
+ unless installed_modules.empty?
48
+ # clone_deps = Console.confirmation_prompt("\nDo you want to clone newly installed dependencies?")
49
+ # if clone_deps
50
+ installed_modules.each do |im|
51
+ clone_aux(im['type'], im['id'], im['version'], true, true, {:backup_if_exist => true})
52
+ end
53
+ # end
54
+ end
55
+
56
+ clone_aux(main_module['type'], main_module['id'], main_module['version'], true, true, {:print_imported => true, :backup_if_exist => true})
57
+ nil
58
+ end
59
+
60
+ private
61
+
62
+ def print_modules(modules, action_name)
63
+ modules.each do |target_module|
64
+ module_name = full_module_name(target_module)
65
+ module_type = target_module['type']
66
+
67
+ print "#{action_name.capitalize} dependency #{module_type.gsub('_',' ')} '#{module_name}'\n"
68
+ end
69
+ end
70
+
71
+ end
72
+ end
@@ -0,0 +1,101 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module DTK::Client
19
+ module PurgeCloneMixin
20
+ def purge_clone_aux(module_type, opts = {})
21
+ module_name = opts[:module_name]
22
+ version = opts[:version]
23
+ opts_module_loc = (opts[:assembly_module] ? {:assembly_module => opts[:assembly_module]} : Hash.new)
24
+ module_location = OsUtil.module_location(module_type, module_name, version, opts_module_loc)
25
+ dirs_to_delete = [module_location]
26
+ if opts[:delete_all_versions]
27
+ dirs_to_delete += OsUtil.module_version_locations(module_type, module_name, version, opts)
28
+ elsif opts[:all_except_base]
29
+ dirs_to_delete = OsUtil.module_version_locations(module_type, module_name, version, opts)
30
+ end
31
+ response = Response::Ok.new()
32
+ pwd = Dir.getwd()
33
+ dirs_to_delete.each do |dir|
34
+ if File.directory?(dir)
35
+ if ((pwd == dir) || (pwd.include?("#{dir}/")))
36
+ OsUtil.print("Local directory '#{dir}' is not deleted because it is your current working directory.", :yellow)
37
+ else
38
+ FileUtils.rm_rf(dir)
39
+ end
40
+ end
41
+ end
42
+ response
43
+ end
44
+
45
+ def check_if_unsaved_cmp_module_changes(assembly_or_workspace_id, opts={})
46
+ unsaved_modules = []
47
+ post_body = {
48
+ :assembly_id => assembly_or_workspace_id,
49
+ :subtype => 'instance'
50
+ }
51
+ response = post rest_url("assembly/get_component_modules"), post_body
52
+
53
+ if response.ok?
54
+ response.data.each do |cmp_mod|
55
+ branch_relationship = cmp_mod['branch_relationship']||''
56
+ unsaved_modules << "#{cmp_mod['namespace_name']}:#{cmp_mod['display_name']}" if (cmp_mod['local_copy_diff'] && branch_relationship.eql?('local_ahead'))
57
+ end
58
+ end
59
+
60
+ unsaved_modules
61
+ end
62
+
63
+ def check_if_unsaved_assembly_changes(assembly_or_workspace_id, assembly_name, opts={})
64
+ post_body = {
65
+ :assembly_id => assembly_or_workspace_id,
66
+ :module_type => 'service_module',
67
+ :modification_type => 'workflow'
68
+ }
69
+ response = post rest_url("assembly/prepare_for_edit_module"), post_body
70
+ return unless response.ok?
71
+ assembly_name,service_module_id,service_module_name,version,repo_url,branch,branch_head_sha,edit_file = response.data(:assembly_name,:module_id,:full_module_name,:version,:repo_url,:workspace_branch,:branch_head_sha,:edit_file)
72
+
73
+ edit_opts = {
74
+ :automatically_clone => true,
75
+ :assembly_module => {
76
+ :assembly_name => assembly_name,
77
+ :version => version
78
+ },
79
+ :workspace_branch_info => {
80
+ :repo_url => repo_url,
81
+ :branch => branch,
82
+ :module_name => service_module_name
83
+ },
84
+ :commit_sha => branch_head_sha,
85
+ :pull_if_needed => true,
86
+ :modification_type => :workflow,
87
+ :edit_file => edit_file
88
+ }
89
+
90
+ version = nil #TODO: version associated with assembly is passed in edit_opts, which is a little confusing
91
+ module_location = OsUtil.module_location(:service_module,service_module_name,version,edit_opts)
92
+ return unless File.directory?(module_location)
93
+
94
+ grit_adapter = Helper(:git_repo).create(module_location)
95
+ return unless grit_adapter.repo_exists?
96
+
97
+ grit_adapter.changed?
98
+ end
99
+
100
+ end
101
+ end
@@ -0,0 +1,162 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ dtk_require_common_commands('thor/common')
19
+ dtk_require_from_base('command_helpers/service_importer')
20
+
21
+ module DTK::Client
22
+ module PushCloneChangesMixin
23
+ include CommonMixin
24
+ ##
25
+ #
26
+ # module_type: will be :component_module or :service_module
27
+ def push_clone_changes_aux(module_type, module_id, version, commit_msg, internal_trigger=false, opts={})
28
+ module_name, module_namespace, repo_url, branch, not_ok_response = workspace_branch_info(module_type, module_id, version, opts)
29
+ return not_ok_response if not_ok_response
30
+
31
+ full_module_name = ModuleUtil.resolve_name(module_name, module_namespace)
32
+ module_location = OsUtil.module_location(module_type, full_module_name, version, opts)
33
+
34
+ unless File.directory?(module_location)
35
+ return if opts[:skip_cloning]
36
+ if opts[:force_clone] || Console.confirmation_prompt("Push not possible, module '#{module_name}#{version && "-#{version}"}' has not been cloned. Would you like to clone module now"+'?')
37
+ clone_aux(module_type, module_id, version, true, true, opts)
38
+ else
39
+ return
40
+ end
41
+ end
42
+
43
+ push_opts = opts.merge(:commit_msg => commit_msg, :local_branch => branch, :where => 'server')
44
+ response = Helper(:git_repo).push_changes(module_type, full_module_name, version, push_opts)
45
+ return response unless response.ok?
46
+
47
+ json_diffs = (response.data(:diffs).empty? ? {} : JSON.generate(response.data(:diffs)))
48
+ commit_sha = response.data(:commit_sha)
49
+ repo_obj = response.data(:repo_obj)
50
+ json_diffs = JSON.generate(response.data(:diffs))
51
+ post_body = get_workspace_branch_info_post_body(module_type, module_id, version, opts).merge(:json_diffs => json_diffs, :commit_sha => commit_sha)
52
+
53
+ post_body.merge!(:modification_type => opts[:modification_type]) if opts[:modification_type]
54
+ post_body.merge!(:force_parse => true) if options['force-parse'] || opts[:force_parse]
55
+ post_body.merge!(:update_from_includes => true) if opts[:update_from_includes]
56
+ post_body.merge!(:service_instance_module => true) if opts[:service_instance_module]
57
+ post_body.merge!(:current_branch_sha => opts[:current_branch_sha]) if opts[:current_branch_sha]
58
+ post_body.merge!(:force => opts[:force]) if opts[:force]
59
+ post_body.merge!(:task_action => opts[:task_action]) if opts[:task_action]
60
+ post_body.merge!(:generate_docs => true) if opts[:generate_docs]
61
+ post_body.merge!(:use_impl_id => opts[:use_impl_id]) if opts[:use_impl_id]
62
+
63
+ if opts[:set_parsed_false]
64
+ post_body.merge!(:set_parsed_false => true)
65
+ post_body.merge!(:force_parse => true)
66
+ end
67
+
68
+ response = post(rest_url("#{module_type}/update_model_from_clone"), post_body)
69
+ return response unless response.ok?
70
+
71
+ external_dependencies = response.data(:external_dependencies)
72
+ dsl_parse_error = response.data(:dsl_parse_error)
73
+ dsl_updated_info = response.data(:dsl_updated_info)
74
+ dsl_created_info = response.data(:dsl_created_info)
75
+ component_module_refs = response.data(:component_module_refs)
76
+
77
+ ret = Response::Ok.new()
78
+
79
+ # check if any errors
80
+ if dsl_parse_error
81
+ if parsed_external_dependencies = dsl_parse_error['external_dependencies']
82
+ external_dependencies = parsed_external_dependencies
83
+ else
84
+ err_msg_opts = { :module_type => module_type }
85
+ err_msg_opts.merge!(:command => opts[:command]) if opts[:command]
86
+ if err_message = ServiceImporter.error_message(module_name, dsl_parse_error, err_msg_opts)
87
+ DTK::Client::OsUtil.print(err_message, :red)
88
+ ret = Response::NoOp.new()
89
+ end
90
+ end
91
+ end
92
+
93
+ has_code_been_pulled = false
94
+
95
+ # check if server pushed anything that needs to be pulled
96
+
97
+ # we need to pull latest code in case docs where generated
98
+ OsUtil.print("Pulling generated documentation on your local repository ...", :yellow) if opts[:generate_docs]
99
+
100
+ if dsl_updated_info and !dsl_updated_info.empty?
101
+ if msg = dsl_updated_info["msg"]
102
+ DTK::Client::OsUtil.print(msg,:yellow)
103
+ end
104
+ new_commit_sha = dsl_updated_info[:commit_sha]
105
+ unless new_commit_sha and new_commit_sha == commit_sha
106
+ opts_pull = opts.merge(:local_branch => branch,:namespace => module_namespace)
107
+ resp = Helper(:git_repo).pull_changes(module_type, module_name, opts_pull)
108
+ has_code_been_pulled = true
109
+ return resp unless resp.ok?
110
+ end
111
+ end
112
+
113
+ # unless DSL was updated we pull latest code due to changes on documentation
114
+ if opts[:generate_docs] && !has_code_been_pulled
115
+ opts_pull = opts.merge(:local_branch => branch,:namespace => module_namespace)
116
+ resp = Helper(:git_repo).pull_changes(module_type, module_name, opts_pull)
117
+ return resp unless resp.ok?
118
+ end
119
+
120
+ if opts[:print_dependencies] || !internal_trigger
121
+ if external_dependencies
122
+ ambiguous = external_dependencies["ambiguous"]||[]
123
+ amb_sorted = ambiguous.map { |k,v| "#{k.split('/').last} (#{v.join(', ')})" }
124
+ inconsistent = external_dependencies["inconsistent"]||[]
125
+ possibly_missing = external_dependencies["possibly_missing"]||[]
126
+ OsUtil.print("There are inconsistent module dependencies: #{inconsistent.join(', ')}", :red) unless inconsistent.empty?
127
+ OsUtil.print("There are missing module dependencies: #{possibly_missing.join(', ')}", :yellow) unless possibly_missing.empty?
128
+ OsUtil.print("There are ambiguous module dependencies: '#{amb_sorted.join(', ')}'. One of the namespaces should be selected by editing the module_refs file", :yellow) if ambiguous && !ambiguous.empty?
129
+ end
130
+ end
131
+
132
+ # check if server sent any file that should be added
133
+ if dsl_created_info and !dsl_created_info.empty?
134
+ path = dsl_created_info["path"]
135
+ content = dsl_created_info["content"]
136
+ if path and content
137
+ msg = "A #{path} file has been created for you, located at #{repo_obj.repo_dir}"
138
+ response = Helper(:git_repo).add_file(repo_obj,path,content,msg)
139
+ return response unless response.ok?
140
+ end
141
+ end
142
+
143
+ unless (component_module_refs||{}).empty?
144
+ print_using_dependencies(component_module_refs)
145
+ end
146
+
147
+ ret
148
+ end
149
+
150
+ private
151
+
152
+ def print_using_dependencies(component_refs)
153
+ # TODO: This just prints out dircetly included modules
154
+ unless component_refs.empty?
155
+ puts 'Using component modules:'
156
+ component_refs.values.map { |r| "#{r['namespace_info']}:#{r['module_name']}" }.sort.each do |name|
157
+ puts " #{name}"
158
+ end
159
+ end
160
+ end
161
+ end
162
+ end
@@ -0,0 +1,94 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ dtk_require_common_commands('thor/common')
19
+ dtk_require("../../../domain/git_adapter")
20
+
21
+
22
+ module DTK::Client
23
+ module PushToRemoteMixin
24
+
25
+ NO_PUSH_CHANGES_MSG = "There are no changes to push"
26
+
27
+ def push_to_git_remote_aux(full_module_name, module_type, version, opts, force = false)
28
+ opts.merge!(:force => force)
29
+
30
+ response = Helper(:git_repo).push_changes(module_type, full_module_name, version, opts)
31
+
32
+ return response unless response.ok?
33
+ if response.data(:diffs) && !response.data(:diffs)[:are_there_changes]
34
+ raise DtkError, NO_PUSH_CHANGES_MSG
35
+ end
36
+
37
+ Response::Ok.new()
38
+ end
39
+
40
+ def push_to_git_remote_location_aux(full_module_name, module_type, version, opts, force = false)
41
+ opts.merge!(:force => force)
42
+
43
+ # staging dir which will be removed
44
+ temp_stage_dir = OsUtil.temp_git_remote_location()
45
+ content_dir = File::join(temp_stage_dir, opts[:remote_repo_location])
46
+
47
+ begin
48
+ # clone desired repo
49
+ ::DTK::Client::GitAdapter.clone(opts[:remote_repo_url], temp_stage_dir, opts[:remote_branch])
50
+ # make sure that content dir exist
51
+ FileUtils.mkdir_p(content_dir)
52
+ # copy content of module to new dir (overriding everything in process)
53
+ module_location = OsUtil.module_location(module_type, full_module_name, version)
54
+ FileUtils.cp_r(File.join(module_location, '/.'), content_dir)
55
+ # remove git folder
56
+ FileUtils.rm_rf(File.join(content_dir, '.git'))
57
+ # now we push it
58
+ opts.merge!(:override_repo_dir_location => temp_stage_dir)
59
+ response = Helper(:git_repo).push_changes(module_type, full_module_name, version, opts)
60
+ return response unless response.ok?
61
+
62
+ if response.data(:diffs) && !response.data(:diffs)[:are_there_changes]
63
+ raise DtkError, NO_PUSH_CHANGES_MSG
64
+ end
65
+
66
+ Response::Ok.new()
67
+ ensure
68
+ FileUtils.rm_rf(temp_stage_dir)
69
+ end
70
+ end
71
+
72
+ def push_to_remote_aux(remote_module_info, module_type, force = false)
73
+ full_module_name = remote_module_info.data(:full_module_name)
74
+ version = remote_module_info.data(:version)
75
+
76
+ opts = {
77
+ :remote_repo_url => remote_module_info.data(:remote_repo_url),
78
+ :remote_repo => remote_module_info.data(:remote_repo),
79
+ :remote_branch => remote_module_info.data(:remote_branch),
80
+ :local_branch => remote_module_info.data(:workspace_branch),
81
+ :where => 'catalog',
82
+ :force => force
83
+ }
84
+ response = Helper(:git_repo).push_changes(module_type, full_module_name, version, opts)
85
+ return response unless response.ok?
86
+ if response.data(:diffs) && !response.data(:diffs)[:are_there_changes]
87
+ raise DtkError, NO_PUSH_CHANGES_MSG
88
+ end
89
+
90
+ Response::Ok.new()
91
+ end
92
+
93
+ end
94
+ end
@@ -0,0 +1,71 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ module DTK::Client
20
+ module RemotesMixin
21
+
22
+ def remote_remove_aux(context_params)
23
+ module_id, remote_name = context_params.retrieve_arguments([::DTK::Client::ModuleMixin::REQ_MODULE_ID,:option_1!], method_argument_names)
24
+ module_type = get_module_type(context_params)
25
+
26
+ unless options.force
27
+ return unless Console.confirmation_prompt("Are you sure you want to remove '#{remote_name}'?")
28
+ end
29
+
30
+ post_body = {
31
+ "#{module_type}_id".to_sym => module_id,
32
+ :remote_name => remote_name
33
+ }
34
+
35
+ response = post rest_url("#{module_type}/remove_git_remote"), post_body
36
+ return response unless response.ok?
37
+ OsUtil.print("Successfully removed remote '#{remote_name}'", :green)
38
+ nil
39
+ end
40
+
41
+ def remote_add_aux(context_params)
42
+ module_id, remote_name, remote_url = context_params.retrieve_arguments([::DTK::Client::ModuleMixin::REQ_MODULE_ID,:option_1!,:option_2!], method_argument_names)
43
+ module_type = get_module_type(context_params)
44
+
45
+ post_body = {
46
+ "#{module_type}_id".to_sym => module_id,
47
+ :remote_name => remote_name,
48
+ :remote_url => remote_url
49
+ }
50
+
51
+ response = post rest_url("#{module_type}/add_git_remote"), post_body
52
+ return response unless response.ok?
53
+ OsUtil.print("Successfully added remote '#{remote_name}'", :green)
54
+ nil
55
+ end
56
+
57
+ def remote_list_aux(context_params)
58
+ module_id = context_params.retrieve_arguments([::DTK::Client::ModuleMixin::REQ_MODULE_ID], method_argument_names)
59
+ module_type = get_module_type(context_params)
60
+
61
+ post_body = {
62
+ "#{module_type}_id".to_sym => module_id
63
+ }
64
+
65
+ response = post rest_url("#{module_type}/info_git_remote"), post_body
66
+ response.render_table(:remotes)
67
+ end
68
+
69
+
70
+ end
71
+ end