dtk-client 0.9.1 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (310) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -0
  3. data/Gemfile +1 -3
  4. data/README.md +2 -121
  5. data/Rakefile +44 -0
  6. data/bin/dtk +10 -88
  7. data/dtk-client.gemspec +21 -44
  8. data/examples/simple/dtk.module.yaml +32 -0
  9. data/{lib/git-logs/git.log → examples/simple/test/README.md} +0 -0
  10. data/examples/spark/dtk.module.yaml +120 -0
  11. data/examples/with_repo_content/deploy/puppet/manifests/hostname.pp +54 -0
  12. data/examples/with_repo_content/dtk.module.yaml +49 -0
  13. data/examples/with_repo_content/test/README.txt +0 -0
  14. data/features/dtk.feature +8 -0
  15. data/features/step_definitions/dtk_steps.rb +6 -0
  16. data/features/support/env.rb +15 -0
  17. data/lib/cli/command/mixin.rb +101 -0
  18. data/lib/cli/command/module/clone.rb +42 -0
  19. data/lib/cli/command/module/install.rb +52 -0
  20. data/lib/cli/command/module/list.rb +31 -0
  21. data/lib/cli/command/module/list_assemblies.rb +39 -0
  22. data/lib/cli/command/module/push.rb +34 -0
  23. data/lib/cli/command/module/uninstall.rb +46 -0
  24. data/lib/cli/command/module.rb +33 -0
  25. data/lib/cli/command/options.rb +33 -0
  26. data/lib/cli/command/service/cancel_task.rb +33 -0
  27. data/lib/cli/command/service/converge.rb +37 -0
  28. data/lib/{parser/adapters/thor/common_option_defs.rb → cli/command/service/create_workspace.rb} +13 -17
  29. data/lib/cli/command/service/destroy.rb +47 -0
  30. data/lib/cli/command/service/edit.rb +47 -0
  31. data/lib/cli/command/service/exec.rb +42 -0
  32. data/lib/cli/command/service/exec_sync.rb +53 -0
  33. data/lib/cli/command/service/list.rb +30 -0
  34. data/lib/cli/command/service/list_actions.rb +39 -0
  35. data/lib/cli/command/service/list_attributes.rb +44 -0
  36. data/lib/cli/command/service/list_component_links.rb +33 -0
  37. data/lib/cli/command/service/list_components.rb +39 -0
  38. data/lib/cli/command/service/list_dependent_modules.rb +33 -0
  39. data/lib/cli/command/service/list_nodes.rb +33 -0
  40. data/lib/cli/command/service/list_violations.rb +33 -0
  41. data/lib/cli/command/service/pull.rb +32 -0
  42. data/lib/cli/command/service/push.rb +37 -0
  43. data/lib/{shell/parse_monkey_patch.rb → cli/command/service/set_default_target.rb} +9 -17
  44. data/lib/cli/command/service/set_required_attributes.rb +32 -0
  45. data/lib/cli/command/service/ssh.rb +42 -0
  46. data/lib/cli/command/service/stage.rb +55 -0
  47. data/lib/cli/command/service/start.rb +33 -0
  48. data/lib/{shell/context_aux.rb → cli/command/service/stop.rb} +10 -23
  49. data/lib/cli/command/service/task_status.rb +39 -0
  50. data/lib/cli/command/service.rb +55 -0
  51. data/lib/{commands.rb → cli/command/subcommand.rb} +22 -25
  52. data/lib/{bundler_monkey_patch.rb → cli/command/token/arg.rb} +6 -6
  53. data/lib/cli/command/token/class_mixin.rb +96 -0
  54. data/lib/cli/command/token/flag.rb +42 -0
  55. data/lib/{execute/command/rest_call.rb → cli/command/token/mixin.rb} +23 -14
  56. data/lib/cli/command/token/switch.rb +35 -0
  57. data/lib/cli/command/token.rb +76 -0
  58. data/lib/cli/command.rb +46 -0
  59. data/lib/cli/context/attributes.rb +50 -0
  60. data/lib/cli/context/type/module.rb +34 -0
  61. data/lib/{commands/thor/state_change.rb → cli/context/type/service.rb} +11 -5
  62. data/lib/cli/context/type/top.rb +32 -0
  63. data/lib/cli/context/type.rb +42 -0
  64. data/lib/cli/context.rb +174 -0
  65. data/lib/cli/directory_parser/file_system.rb +105 -0
  66. data/lib/{execute/command.rb → cli/directory_parser.rb} +14 -17
  67. data/lib/{execute.rb → cli/file_obj.rb} +13 -9
  68. data/lib/cli/processor/plugin/gli.rb +70 -0
  69. data/lib/cli/processor.rb +60 -0
  70. data/lib/cli/runner/dtkn_access.rb +75 -0
  71. data/lib/cli/runner.rb +58 -0
  72. data/lib/cli/version.rb +8 -0
  73. data/lib/{config → client/config}/cacert.pem +0 -0
  74. data/lib/client/config/default.conf +20 -0
  75. data/lib/client/config.rb +106 -0
  76. data/lib/client/configurator.rb +182 -0
  77. data/lib/client/conn.rb +197 -0
  78. data/lib/client/content_generator.rb +127 -0
  79. data/lib/client/error/subclasses.rb +105 -0
  80. data/lib/client/error.rb +98 -0
  81. data/lib/client/git_repo/adapter/git_gem/error_handler.rb +70 -0
  82. data/lib/client/git_repo/adapter/git_gem.rb +179 -0
  83. data/lib/client/git_repo.rb +122 -0
  84. data/lib/client/logger.rb +136 -0
  85. data/lib/client/operation/account.rb +66 -0
  86. data/lib/client/operation/client_module_dir/git_repo.rb +286 -0
  87. data/lib/client/operation/client_module_dir.rb +138 -0
  88. data/lib/client/operation/module/clone_module.rb +52 -0
  89. data/lib/client/operation/module/install/common_module.rb +58 -0
  90. data/lib/client/operation/module/install/external_module.rb +122 -0
  91. data/lib/client/operation/module/install.rb +91 -0
  92. data/lib/client/operation/module/install_from_catalog.rb +76 -0
  93. data/lib/client/operation/module/list.rb +34 -0
  94. data/lib/client/operation/module/list_assemblies.rb +35 -0
  95. data/lib/client/operation/module/push.rb +62 -0
  96. data/lib/client/operation/module/uninstall.rb +44 -0
  97. data/lib/client/operation/module.rb +58 -0
  98. data/lib/{commands/common/thor/reparse.rb → client/operation/module_service_common.rb} +27 -16
  99. data/lib/client/operation/service/cancel_task.rb +29 -0
  100. data/lib/client/operation/service/commit_and_push.rb +128 -0
  101. data/lib/client/operation/service/converge.rb +50 -0
  102. data/lib/{util/common_util.rb → client/operation/service/create_workspace.rb} +13 -13
  103. data/lib/client/operation/service/destroy.rb +42 -0
  104. data/lib/client/operation/service/edit.rb +54 -0
  105. data/lib/client/operation/service/exec.rb +73 -0
  106. data/lib/client/operation/service/list.rb +32 -0
  107. data/lib/client/operation/service/list_actions.rb +34 -0
  108. data/lib/{commands/thor/dependency.rb → client/operation/service/list_attributes.rb} +16 -12
  109. data/lib/client/operation/service/list_component_links.rb +29 -0
  110. data/lib/{commands/common/thor/pull_clone_changes.rb → client/operation/service/list_components.rb} +13 -7
  111. data/lib/client/operation/service/list_dependent_modules.rb +29 -0
  112. data/lib/client/operation/service/list_nodes.rb +29 -0
  113. data/lib/{commands/thor/project.rb → client/operation/service/list_violations.rb} +8 -13
  114. data/lib/client/operation/service/pull.rb +37 -0
  115. data/lib/client/operation/service/set_default_target.rb +31 -0
  116. data/lib/client/operation/service/set_required_attributes.rb +41 -0
  117. data/lib/client/operation/service/ssh.rb +118 -0
  118. data/lib/client/operation/service/stage.rb +54 -0
  119. data/lib/client/operation/service/start.rb +29 -0
  120. data/lib/client/operation/service/stop.rb +30 -0
  121. data/lib/{task_status → client/operation/service/task_status}/refresh_mode.rb +15 -25
  122. data/lib/{task_status → client/operation/service/task_status}/snapshot_mode.rb +4 -5
  123. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/format.rb +1 -1
  124. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/result/action.rb +1 -1
  125. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/result/components.rb +1 -1
  126. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/result/node_level.rb +1 -1
  127. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/result.rb +4 -4
  128. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/steps/action.rb +1 -1
  129. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/steps/components.rb +1 -1
  130. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/steps/node_level.rb +1 -1
  131. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/steps.rb +4 -4
  132. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task.rb +3 -3
  133. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/no_results.rb +1 -1
  134. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/render.rb +1 -1
  135. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/stage/render.rb +1 -1
  136. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/stage.rb +3 -3
  137. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/task_end.rb +1 -1
  138. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/task_start.rb +1 -1
  139. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element.rb +13 -13
  140. data/lib/{task_status → client/operation/service/task_status}/stream_mode.rb +5 -9
  141. data/lib/client/operation/service/task_status.rb +77 -0
  142. data/lib/client/operation/service.rb +54 -0
  143. data/lib/client/operation.rb +67 -0
  144. data/lib/client/operation_args.rb +40 -0
  145. data/lib/{execute/execute_context/result_store.rb → client/render/view/simple.rb} +15 -14
  146. data/lib/client/render/view/table/processor.rb +248 -0
  147. data/lib/client/render/view/table.rb +75 -0
  148. data/lib/client/render.rb +113 -0
  149. data/lib/client/response/error_handler.rb +97 -0
  150. data/lib/client/response/render_helper.rb +78 -0
  151. data/lib/client/response/subclasses.rb +62 -0
  152. data/lib/client/response.rb +83 -0
  153. data/lib/client/session.rb +62 -0
  154. data/lib/client/util/auxiliary.rb +34 -0
  155. data/lib/client/util/console.rb +81 -0
  156. data/lib/client/util/disk_cacher.rb +66 -0
  157. data/lib/client/util/dtk_path.rb +28 -0
  158. data/lib/{search_hash.rb → client/util/hash_with_optional_keys.rb} +29 -21
  159. data/lib/client/util/interactive_wizard.rb +84 -0
  160. data/lib/client/util/module_ref.rb +92 -0
  161. data/lib/client/util/os_util/print.rb +121 -0
  162. data/lib/client/util/os_util.rb +122 -0
  163. data/lib/{commands/thor/utils.rb → client/util/post_body.rb} +1 -1
  164. data/lib/{execute/error_usage.rb → client/util/query_string_hash.rb} +2 -2
  165. data/lib/client/util/remote_dependency.rb +67 -0
  166. data/lib/client/util/ssh_util.rb +89 -0
  167. data/lib/client/util/validation.rb +28 -0
  168. data/lib/client/util.rb +18 -0
  169. data/lib/{util/permission_util.rb → dtk_cli.rb} +10 -9
  170. data/lib/dtk_client.rb +18 -14
  171. data/test/default_test.rb +14 -0
  172. data/test/test_helper.rb +9 -0
  173. metadata +196 -307
  174. data/Gemfile_dev +0 -13
  175. data/bin/dtk-execute +0 -32
  176. data/bin/dtk-shell +0 -31
  177. data/lib/auxiliary.rb +0 -61
  178. data/lib/client.rb +0 -58
  179. data/lib/command_helper.rb +0 -33
  180. data/lib/command_helpers/git_repo/merge.rb +0 -153
  181. data/lib/command_helpers/git_repo.rb +0 -589
  182. data/lib/command_helpers/jenkins_client/config_xml.rb +0 -288
  183. data/lib/command_helpers/jenkins_client.rb +0 -106
  184. data/lib/command_helpers/service_importer.rb +0 -251
  185. data/lib/command_helpers/service_link.rb +0 -33
  186. data/lib/command_helpers/test_module_creator.rb +0 -69
  187. data/lib/command_helpers/test_module_templates/dtk.model.yaml.eruby +0 -10
  188. data/lib/command_helpers/test_module_templates/spec_helper.rb.eruby +0 -10
  189. data/lib/command_helpers/test_module_templates/temp_component_spec.rb.eruby +0 -5
  190. data/lib/commands/common/thor/access_control.rb +0 -133
  191. data/lib/commands/common/thor/action_result_handler.rb +0 -74
  192. data/lib/commands/common/thor/assembly_template.rb +0 -92
  193. data/lib/commands/common/thor/assembly_workspace.rb +0 -1638
  194. data/lib/commands/common/thor/base_command_helper.rb +0 -59
  195. data/lib/commands/common/thor/clone.rb +0 -82
  196. data/lib/commands/common/thor/common.rb +0 -88
  197. data/lib/commands/common/thor/common_base.rb +0 -49
  198. data/lib/commands/common/thor/create_target.rb +0 -70
  199. data/lib/commands/common/thor/edit.rb +0 -255
  200. data/lib/commands/common/thor/inventory_parser.rb +0 -98
  201. data/lib/commands/common/thor/list_diffs.rb +0 -128
  202. data/lib/commands/common/thor/module/import.rb +0 -215
  203. data/lib/commands/common/thor/module.rb +0 -1011
  204. data/lib/commands/common/thor/node.rb +0 -53
  205. data/lib/commands/common/thor/poller.rb +0 -65
  206. data/lib/commands/common/thor/pull_from_remote.rb +0 -152
  207. data/lib/commands/common/thor/puppet_forge.rb +0 -72
  208. data/lib/commands/common/thor/purge_clone.rb +0 -101
  209. data/lib/commands/common/thor/push_clone_changes.rb +0 -162
  210. data/lib/commands/common/thor/push_to_remote.rb +0 -94
  211. data/lib/commands/common/thor/remotes.rb +0 -71
  212. data/lib/commands/common/thor/set_required_attributes.rb +0 -46
  213. data/lib/commands/thor/account.rb +0 -239
  214. data/lib/commands/thor/assembly.rb +0 -361
  215. data/lib/commands/thor/attribute.rb +0 -79
  216. data/lib/commands/thor/component.rb +0 -70
  217. data/lib/commands/thor/component_module.rb +0 -501
  218. data/lib/commands/thor/component_template.rb +0 -174
  219. data/lib/commands/thor/developer.rb +0 -144
  220. data/lib/commands/thor/dtk.rb +0 -152
  221. data/lib/commands/thor/library.rb +0 -125
  222. data/lib/commands/thor/node.rb +0 -504
  223. data/lib/commands/thor/node_group.rb +0 -203
  224. data/lib/commands/thor/node_template.rb +0 -94
  225. data/lib/commands/thor/provider.rb +0 -233
  226. data/lib/commands/thor/remotes.rb +0 -49
  227. data/lib/commands/thor/service.rb +0 -932
  228. data/lib/commands/thor/service_module.rb +0 -900
  229. data/lib/commands/thor/target.rb +0 -250
  230. data/lib/commands/thor/task.rb +0 -116
  231. data/lib/commands/thor/test_module.rb +0 -310
  232. data/lib/commands/thor/workspace.rb +0 -698
  233. data/lib/config/client.conf.header +0 -20
  234. data/lib/config/configuration.rb +0 -99
  235. data/lib/config/default.conf +0 -16
  236. data/lib/config/disk_cacher.rb +0 -80
  237. data/lib/configurator.rb +0 -176
  238. data/lib/context_router.rb +0 -44
  239. data/lib/core.rb +0 -489
  240. data/lib/domain/git_adapter.rb +0 -412
  241. data/lib/domain/git_error_handler.rb +0 -64
  242. data/lib/domain/response/error_handler.rb +0 -86
  243. data/lib/domain/response.rb +0 -285
  244. data/lib/dtk-client/version.rb +0 -20
  245. data/lib/dtk_constants.rb +0 -40
  246. data/lib/dtk_error.rb +0 -114
  247. data/lib/dtk_logger.rb +0 -113
  248. data/lib/error.rb +0 -85
  249. data/lib/execute/cli_pure/cli_rerouter.rb +0 -102
  250. data/lib/execute/command/api_call/map.rb +0 -60
  251. data/lib/execute/command/api_call/service.rb +0 -91
  252. data/lib/execute/command/api_call/translation_term.rb +0 -119
  253. data/lib/execute/command/api_call.rb +0 -60
  254. data/lib/execute/command_processor/rest_call.rb +0 -59
  255. data/lib/execute/command_processor.rb +0 -30
  256. data/lib/execute/execute_context.rb +0 -86
  257. data/lib/execute/script/add_tenant.rb +0 -121
  258. data/lib/execute/script.rb +0 -64
  259. data/lib/parser/adapters/option_parser.rb +0 -70
  260. data/lib/parser/adapters/thor.rb +0 -555
  261. data/lib/require_first.rb +0 -104
  262. data/lib/shell/context.rb +0 -1064
  263. data/lib/shell/domain/active_context.rb +0 -186
  264. data/lib/shell/domain/context_entity.rb +0 -89
  265. data/lib/shell/domain/context_params.rb +0 -223
  266. data/lib/shell/domain/override_tasks.rb +0 -88
  267. data/lib/shell/domain/shadow_entity.rb +0 -76
  268. data/lib/shell/header_shell.rb +0 -44
  269. data/lib/shell/help_monkey_patch.rb +0 -283
  270. data/lib/shell/interactive_wizard.rb +0 -256
  271. data/lib/shell/message_queue.rb +0 -63
  272. data/lib/shell/status_monitor.rb +0 -124
  273. data/lib/shell.rb +0 -261
  274. data/lib/task_status.rb +0 -83
  275. data/lib/util/console.rb +0 -235
  276. data/lib/util/dtk_puppet.rb +0 -65
  277. data/lib/util/module_util.rb +0 -66
  278. data/lib/util/os_util.rb +0 -385
  279. data/lib/util/remote_dependency_util.rb +0 -84
  280. data/lib/util/ssh_util.rb +0 -94
  281. data/lib/view_processor/augmented_simple_list.rb +0 -44
  282. data/lib/view_processor/hash_pretty_print.rb +0 -123
  283. data/lib/view_processor/simple_list.rb +0 -156
  284. data/lib/view_processor/table_print.rb +0 -309
  285. data/lib/view_processor.rb +0 -129
  286. data/puppet/manifests/init.pp +0 -72
  287. data/puppet/manifests/params.pp +0 -16
  288. data/puppet/r8meta.puppet.yml +0 -35
  289. data/puppet/templates/bash_profile.erb +0 -2
  290. data/puppet/templates/client.conf.erb +0 -1
  291. data/puppet/templates/dtkclient.erb +0 -2
  292. data/spec/component_module_spec.rb +0 -34
  293. data/spec/dependency_spec.rb +0 -6
  294. data/spec/dtk_shell_spec.rb +0 -13
  295. data/spec/dtk_spec.rb +0 -33
  296. data/spec/lib/spec_helper.rb +0 -10
  297. data/spec/lib/spec_thor.rb +0 -108
  298. data/spec/node_template_spec.rb +0 -24
  299. data/spec/project_spec.rb +0 -6
  300. data/spec/repo_spec.rb +0 -7
  301. data/spec/response_spec.rb +0 -52
  302. data/spec/service_module_spec.rb +0 -38
  303. data/spec/service_spec.rb +0 -50
  304. data/spec/state_change_spec.rb +0 -7
  305. data/spec/table_print_spec.rb +0 -48
  306. data/spec/target_spec.rb +0 -57
  307. data/spec/task_spec.rb +0 -28
  308. data/views/assembly/augmented_simple_list.rb +0 -12
  309. data/views/assembly_template/augmented_simple_list.rb +0 -12
  310. data/views/list_task/augmented_simple_list.rb +0 -12
@@ -1,589 +0,0 @@
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
- # This code is predciated on assumption that they is only one local branch (with with documented exceptions)
19
- # so checkout branch is not done in most cases
20
- #TODO : make sure all functions that use local_repo_dir( inside pass in full_moudle_name, not just module_name
21
- require 'fileutils'
22
- dtk_require("../domain/git_adapter")
23
- dtk_require("../domain/git_error_handler")
24
-
25
- module DTK; module Client; class CommandHelper
26
- class GitRepo < self; class << self
27
- dtk_require('git_repo/merge')
28
-
29
- def create(repo_dir,branch=nil,opts={})
30
- GitAdapter.new(repo_dir, branch)
31
- end
32
-
33
- def create_clone_from_optional_branch(type, module_name, repo_url, opts={})
34
- branch = opts[:branch]
35
- version = opts[:version]
36
- namespace = opts[:namespace]
37
- create_clone_with_branch(type,module_name,repo_url,branch,version,namespace,{:track_remote_branch => true}.merge(opts))
38
- end
39
-
40
- # TODO: should we deprecate below for above, subsituting the body of below for above ?
41
- def create_clone_with_branch(type, module_name, repo_url, branch=nil, version=nil, module_namespace=nil, opts={})
42
- Response.wrap_helper_actions do
43
- full_name = module_namespace ? ModuleUtil.resolve_name(module_name, module_namespace) : module_name
44
-
45
- modules_dir = modules_dir(type,full_name,version,opts)
46
- FileUtils.mkdir_p(modules_dir) unless File.directory?(modules_dir)
47
-
48
- target_repo_dir = local_repo_dir(type,full_name,version,opts)
49
- if File.exists?(target_repo_dir)
50
- # if local copy of module exists then move that module to backups location
51
- if opts[:backup_if_exist]
52
- backup_dir = backup_dir(type, full_name)
53
- FileUtils.mv(target_repo_dir, backup_dir)
54
- puts "Backup of existing module directory moved to '#{backup_dir}'"
55
- else
56
- raise ErrorUsage.new("Directory '#{target_repo_dir}' is not empty; it must be deleted or removed before retrying the command", :log_error => false)
57
- end
58
- end
59
-
60
- begin
61
- opts_clone = (opts[:track_remote_branch] ? {:track_remote_branch => true} : {})
62
- GitAdapter.clone(repo_url, target_repo_dir, branch, opts_clone)
63
- rescue => e
64
- # Handling Git error messages with more user friendly messages
65
- e = GitErrorHandler.handle(e)
66
-
67
- #cleanup by deleting directory
68
- FileUtils.rm_rf(target_repo_dir) if File.directory?(target_repo_dir)
69
- error_msg = "Clone to directory (#{target_repo_dir}) failed"
70
-
71
- DtkLogger.instance.error_pp(e.message, e.backtrace)
72
-
73
- raise ErrorUsage.new(error_msg, :log_error => false)
74
- end
75
- {"module_directory" => target_repo_dir}
76
- end
77
- end
78
-
79
- #TODO: this does not push; may make that an option
80
- def add_file(repo_obj,path,content,msg=nil)
81
- Response.wrap_helper_actions() do
82
- ret = Hash.new
83
- repo_obj.add_file(path,content)
84
- ret["message"] = msg if msg
85
- ret
86
- end
87
- end
88
-
89
- # opts can have the following keys
90
- #
91
- # :remote_repo
92
- # :remote_branch
93
- # :remote_repo_url
94
- # :local_branch
95
- # :override_repo_dir_location
96
- # :no_fetch
97
- #
98
- def push_changes(type, full_module_name, version, opts={})
99
- Response.wrap_helper_actions() do
100
- repo_dir = opts[:override_repo_dir_location] ? opts[:override_repo_dir_location] : local_repo_dir(type, full_module_name, version, opts)
101
- repo = create(repo_dir, opts[:local_branch])
102
- push_repo_changes_aux(repo, opts)
103
- end
104
- end
105
-
106
- def get_diffs(type, module_name, version, opts={})
107
- Response.wrap_helper_actions() do
108
- repo_dir = local_repo_dir(type,module_name,version)
109
- repo = create(repo_dir,opts[:local_branch])
110
- get_diffs_aux(repo,opts)
111
- end
112
- end
113
-
114
- def get_remote_diffs(type, module_name, version, opts={})
115
- Response.wrap_helper_actions() do
116
- repo_dir = local_repo_dir(type,module_name,version)
117
- repo = create(repo_dir,opts[:local_branch])
118
- get_remote_diffs_aux(repo,opts)
119
- end
120
- end
121
-
122
- # opts can have the following keys
123
- #
124
- # :remote_repo
125
- # :remote_branch
126
- # :remote_repo_url
127
- # :local_branch
128
- # :version
129
- # :commit_sha
130
- # :full_module_name
131
- # :namespace
132
- # returns:
133
- # { :diffs => , :commit_sha => }
134
- def pull_changes(type,module_name,opts={})
135
- Response.wrap_helper_actions() do
136
- full_module_name = full_module_name(module_name,opts)
137
- repo_dir = local_repo_dir(type,full_module_name,opts[:version],opts)
138
- repo = create(repo_dir,opts[:local_branch])
139
- opts.merge!(:full_module_name => full_module_name)
140
- response = pull_repo_changes_aux(repo,opts)
141
- response
142
- end
143
- end
144
- def pull_changes?(type,module_name,opts={})
145
- if local_clone_dir_exists?(type,module_name,opts)
146
- pull_changes(type,module_name,opts)
147
- else
148
- Response.wrap_helper_actions()
149
- end
150
- end
151
-
152
- def hard_reset_branch_to_sha(type, module_name, opts={})
153
- Response.wrap_helper_actions() do
154
- full_module_name = full_module_name(module_name,opts)
155
- repo_dir = local_repo_dir(type, full_module_name, opts[:version], opts)
156
- repo = create(repo_dir, opts[:local_branch])
157
- current_branch_sha = opts[:current_branch_sha]
158
- repo.reset_hard(current_branch_sha)
159
- end
160
- end
161
-
162
- # opts can have the following keys
163
- #
164
- # :version
165
- # :full_module_name
166
- # :namespace
167
- def local_clone_dir_exists?(type,module_name,opts={})
168
- full_module_name = full_module_name(module_name,opts)
169
- ret = local_repo_dir(type, full_module_name, opts[:version], opts)
170
- File.directory?(ret) && ret
171
- end
172
-
173
- def full_module_name(module_name,opts)
174
- opts[:full_module_name] || ModuleUtil.resolve_name(module_name, opts[:namespace])
175
- end
176
- private :full_module_name
177
-
178
- def synchronize_clone(type,module_name,commit_sha,opts={})
179
- pull_changes?(type,module_name,{:commit_sha => commit_sha}.merge(opts))
180
- Response::Ok.new()
181
- end
182
-
183
- # if local clone exists remove its .git directory
184
- def unlink_local_clone?(type,module_name,version=nil)
185
- Response.wrap_helper_actions() do
186
- local_repo_dir = local_repo_dir(type,module_name,version)
187
- git_dir = "#{local_repo_dir}/.git"
188
- if File.directory?(git_dir)
189
- FileUtils.rm_rf(git_dir)
190
- end
191
- end
192
- end
193
-
194
- def check_local_dir_exists_with_content(type, module_name, version=nil, module_namespace=nil)
195
- full_module_name = ModuleUtil.join_name(module_name, module_namespace)
196
- Response.wrap_helper_actions() do
197
- ret = Hash.new
198
- local_repo_dir = local_repo_dir(type,full_module_name,version)
199
-
200
- unless File.directory?(local_repo_dir)
201
- raise ErrorUsage.new("The content for module (#{full_module_name}) should be put in directory (#{local_repo_dir})",:log_error=>false)
202
- end
203
-
204
- # transfered this part to initialize_client_clone_and_push because if we remove .git folder and
205
- # if create on server fails we will lose this .git folder and will not be able to push local changes to server
206
- # if File.directory?("#{local_repo_dir}/.git")
207
- # response = unlink_local_clone?(type,module_name,version)
208
- # unless response.ok?
209
- # # in case delete went wrong, we raise usage error
210
- # raise ErrorUsage.new("Directory (#{local_repo_dir} is set as a git repo; to continue it must be a non git repo; this can be handled by shell command 'rm -rf #{local_repo_dir}/.git'")
211
- # end
212
-
213
- # # we return to normal flow, since .git dir is removed
214
- # end
215
-
216
- if Dir["#{local_repo_dir}/*"].empty?
217
- raise ErrorUsage.new("Directory (#{local_repo_dir}) must have ths initial content for module (#{full_module_name})")
218
- end
219
- {"module_directory" => local_repo_dir}
220
- end
221
- end
222
-
223
- def cp_r_to_new_namespace(type, module_name, src_namespace, dest_namespace, version = nil)
224
- full_name_src = ModuleUtil.join_name(module_name, src_namespace)
225
- full_name_dest = ModuleUtil.join_name(module_name, dest_namespace)
226
-
227
- local_src_dir = local_repo_dir(type, full_name_src, version)
228
- local_dest_dir = local_repo_dir(type, full_name_dest, version)
229
-
230
- Response.wrap_helper_actions() do
231
- if File.directory?(local_src_dir) && !(Dir["#{local_src_dir}/*"].empty?)
232
- raise ErrorUsage.new("Directory (#{local_dest_dir}) already exist with content.",:log_error=>false) if File.directory?(local_dest_dir) && !(Dir["#{local_dest_dir}/*"].empty?)
233
-
234
- # create namespace directory if does not exist, and copy source to destination module directory
235
- namespace_dir = local_repo_dir(type, dest_namespace, version)
236
- FileUtils.mkdir_p(namespace_dir)
237
- FileUtils.cp_r(local_src_dir, local_dest_dir)
238
- else
239
- raise ErrorUsage.new("The content for module (#{full_name_src}) should be put in directory (#{local_src_dir})",:log_error=>false)
240
- end
241
- {"module_directory" => local_dest_dir}
242
- end
243
- end
244
-
245
- def create_new_version(type, src_branch, module_name, src_namespace, version, repo_url, opts = {})
246
- full_name_src = ModuleUtil.join_name(module_name, src_namespace)
247
- full_name_dest = "#{full_name_src}-#{version}"
248
-
249
- local_src_dir = local_repo_dir(type, full_name_src)
250
- local_dest_dir = local_repo_dir(type, full_name_dest)
251
- branch = "#{src_branch}-v#{version}"
252
- exist_already = false
253
-
254
- if File.directory?(local_src_dir) && !(Dir["#{local_src_dir}/*"].empty?)
255
- if File.directory?(local_dest_dir) && !(Dir["#{local_dest_dir}/*"].empty?)
256
- # raise ErrorUsage.new("Directory (#{local_dest_dir}) already exist with content.",:log_error=>false)
257
- exist_already = true
258
- else
259
- FileUtils.cp_r(local_src_dir, local_dest_dir)
260
- end
261
- else
262
- raise ErrorUsage.new("The content for module (#{full_name_src}) should be put in directory (#{local_src_dir})",:log_error=>false)
263
- end
264
-
265
- unless exist_already
266
- Response.wrap_helper_actions() do
267
- repo_dir = local_dest_dir
268
- remote_branch = local_branch = branch
269
- repo = create(repo_dir, branch, :no_initial_commit => true)
270
- repo.add_remote(remote(branch), repo_url)
271
- repo.checkout(branch, { :new_branch => true })
272
- repo.push_with_remote(remote(), remote_branch)
273
- repo.delete_branch(src_branch)
274
- repo.fetch()
275
- end
276
- end
277
-
278
- {'module_directory' => local_dest_dir, 'version' => version, 'branch' => branch, 'exist_already' => exist_already}
279
- end
280
-
281
- def rename_and_initialize_clone_and_push(type, module_name, new_module_name, branch, repo_url, local_repo_dir, version = nil)
282
- # check to see if the new dir has proper naming e.g. (~/dtk/component_modules/dtk::java)
283
- unless local_repo_dir.match(/\/#{new_module_name.gsub(ModuleUtil::NAMESPACE_SEPERATOR,'/')}$/)
284
- old_dir = local_repo_dir
285
- new_dir = local_repo_dir.gsub(/#{module_name}$/, new_module_name.split(ModuleUtil::NAMESPACE_SEPERATOR).join('/'))
286
-
287
- # creates directory if missing
288
- parent_path = new_dir.gsub(/(\/\w+)$/,'')
289
- FileUtils::mkdir_p(parent_path) unless File.directory?(parent_path)
290
- # raise ErrorUsage.new("Destination folder already exists '#{new_dir}', aborting initialization.") if File.directory?(new_dir)
291
- if File.directory?(new_dir)
292
- # return empty response if user does not want to overwrite current directory
293
- return unless Console.confirmation_prompt("Destination directory #{new_dir} exists already. Do you want to overwrite it with content from #{old_dir}"+'?')
294
- FileUtils.rm_rf(new_dir)
295
- end
296
- # FileUtils.mv(old_dir, new_dir)
297
- FileUtils.cp_r(old_dir, new_dir)
298
- else
299
- new_dir = local_repo_dir
300
- end
301
-
302
- # Continue push
303
- response = initialize_client_clone_and_push(type, new_module_name, branch, repo_url, new_dir, version)
304
- return response unless response.ok?
305
-
306
- response.data.merge!(:old_dir => old_dir)
307
- response
308
- end
309
-
310
- # makes repo_dir (determined from type and module_name) into a git dir, pulls, adds, content and then pushes
311
- def initialize_client_clone_and_push(type, module_name, branch, repo_url, local_repo_dir, version=nil)
312
- # moved this part from 'check_local_dir_exists_with_content' to this method since this only deletes .git folder
313
- # which can cause us problems if import fails
314
- if File.directory?("#{local_repo_dir}/.git")
315
- response = unlink_local_clone?(type,module_name,version)
316
- unless response.ok?
317
- # in case delete went wrong, we raise usage error
318
- raise DtkError.new("Directory (#{local_repo_dir} is set as a git repo; to continue it must be a non git repo; this can be handled by shell command 'rm -rf #{local_repo_dir}/.git'")
319
- end
320
- # we return to normal flow, since .git dir is removed
321
- end
322
-
323
- Response.wrap_helper_actions() do
324
- ret = Hash.new
325
- repo_dir = local_repo_dir(type,module_name)
326
-
327
- repo = create(repo_dir,branch,:init => true, :no_initial_commit => true)
328
- repo.add_remote(remote(),repo_url)
329
- remote_branch = local_branch = branch
330
-
331
- repo.pull_remote_to_local(remote_branch,local_branch,remote())
332
- repo.stage_changes()
333
- repo.commit("Adding files during initialization")
334
- repo.push_with_remote(remote(), remote_branch)
335
-
336
- commit_sha = repo.head_commit_sha()
337
- {"repo_obj" => repo,"commit_sha" => commit_sha}
338
- end
339
- end
340
-
341
- private
342
- # TODO: in common expose Common::GritAdapter at less nested level
343
- class DiffSummary < ::DTK::Common::SimpleHashObject
344
- def self.new_version(repo)
345
- new(repo.new_version())
346
- end
347
-
348
- def self.diff(repo,local_branch,remote_reference)
349
- new(repo.diff_summary(local_branch,remote_reference))
350
- end
351
-
352
- def self.diff_remote(repo,local_branch,remote_reference)
353
- new(repo.diff_remote_summary(local_branch,remote_reference))
354
- end
355
-
356
- # def self.diff_remote(repo,ref1)
357
- # new(repo.diff(ref1).ret_summary())
358
- # end
359
-
360
- def any_diffs?
361
- changes = false
362
- self.each do |k,v|
363
- unless v.empty?
364
- changes = true
365
- break
366
- end
367
- end
368
- changes
369
- end
370
- end
371
-
372
- #returns hash with keys
373
- #: diffs - hash with diffs
374
- # commit_sha - sha of currenet_commit
375
- def push_repo_changes_aux(repo, opts={})
376
- diffs = DiffSummary.new()
377
-
378
- # adding untracked files (newly added files)
379
- repo.stage_changes()
380
-
381
- # commit if there has been changes
382
- if repo.changed?
383
- repo.commit(opts[:commit_msg]||"Pushing changes from client") #TODO: make more descriptive
384
- end
385
-
386
- if opts[:remote_repo] and opts[:remote_repo_url]
387
- repo.add_remote(opts[:remote_repo],opts[:remote_repo_url])
388
- end
389
-
390
- unless opts[:no_fetch]
391
- repo.fetch(remote(opts[:remote_repo]))
392
- end
393
-
394
- local_branch = repo.local_branch_name
395
-
396
- remote_branch_ref = remote_branch_ref(local_branch, opts)
397
-
398
- #check if merge needed
399
- commit_shas = Hash.new
400
- merge_rel = repo.merge_relationship(:remote_branch,remote_branch_ref, :ret_commit_shas => commit_shas)
401
- commit_sha = nil
402
- diffs = DiffSummary.new_version(repo)
403
-
404
- if merge_rel == :equal
405
- commit_sha = commit_shas[:other_sha]
406
- elsif [:branchpoint,:local_behind].include?(merge_rel)
407
- if opts[:force]
408
- diffs = DiffSummary.diff(repo,local_branch, remote_branch_ref)
409
- if diffs.any_diffs?()
410
- repo.push(remote_branch_ref, {:force => opts[:force]})
411
- end
412
- commit_sha = repo.find_remote_sha(remote_branch_ref)
413
- else
414
- where = opts[:where] || 'server'
415
- msg = "Merge needed before module (#{pp_module(repo)}) can be pushed to #{where}. "
416
- if where.to_sym == :catalog
417
- msg << " Either a merge into the local module can be done with pull-dtkn command, followed by push-dtkn or force"
418
- else
419
- msg << "Force"
420
- end
421
- msg << " push can be used with the '--force' option, but this will overwrite remote contents"
422
- raise ErrorUsage.new(msg)
423
- end
424
- elsif merge_rel == :no_remote_ref
425
- repo.push(remote_branch_ref)
426
- commit_sha = commit_shas[:local_sha]
427
- elsif merge_rel == :local_ahead
428
- # see if any diffs between fetched remote and local branch
429
- # this has be done after commit
430
- diffs = DiffSummary.diff(repo,local_branch, remote_branch_ref)
431
-
432
- if diffs.any_diffs?()
433
- repo.push(remote_branch_ref, {:force => opts[:force]})
434
- end
435
-
436
- commit_sha = repo.find_remote_sha(remote_branch_ref)
437
- else
438
- raise Error.new("Unexpected merge_rel (#{merge_rel})")
439
- end
440
-
441
- {"diffs" => diffs, "commit_sha" => commit_sha, "repo_obj" => repo}
442
- end
443
-
444
- def get_diffs_aux(repo,opts={})
445
- diffs = DiffSummary.new()
446
- #add any file that is untracked
447
-
448
- # repo.stage_changes()
449
-
450
- if opts[:remote_repo] and opts[:remote_repo_url]
451
- repo.add_remote(opts[:remote_repo],opts[:remote_repo_url])
452
- end
453
-
454
- unless opts[:no_fetch]
455
- repo.fetch(remote(opts[:remote_repo]))
456
- end
457
-
458
- local_branch = repo.local_branch_name
459
-
460
- remote_branch_ref = remote_branch_ref(local_branch, opts)
461
-
462
- commit_shas = Hash.new
463
- merge_rel = repo.merge_relationship(:remote_branch,remote_branch_ref, :ret_commit_shas => commit_shas)
464
- commit_sha = nil
465
-
466
- if merge_rel == :equal
467
- commit_sha = commit_shas[:other_sha]
468
- elsif merge_rel == :no_remote_ref
469
- diffs = DiffSummary.new_version(repo)
470
- commit_sha = commit_shas[:local_sha]
471
- end
472
-
473
- # diffs = DiffSummary.diff_remote(repo,"remotes/#{remote_branch_ref}")
474
- diffs = DiffSummary.diff(repo,local_branch, remote_branch_ref)
475
- commit_sha = repo.find_remote_sha(remote_branch_ref)
476
-
477
- {"diffs" => diffs, "commit_sha" => commit_sha, "repo_obj" => repo, "status" => repo.local_summary() }
478
- end
479
-
480
- def get_remote_diffs_aux(repo,opts={})
481
- diffs = DiffSummary.new()
482
- #add any file that is untracked
483
-
484
- # repo.stage_changes()
485
- if opts[:remote_repo] and opts[:remote_repo_url]
486
- repo.add_remote(opts[:remote_repo],opts[:remote_repo_url])
487
- end
488
-
489
- unless opts[:no_fetch]
490
- repo.fetch(remote(opts[:remote_repo]))
491
- end
492
-
493
- local_branch = repo.local_branch_name
494
- remote_branch_ref = remote_branch_ref(local_branch, opts)
495
-
496
- commit_shas = Hash.new
497
- merge_rel = repo.merge_relationship(:remote_branch, remote_branch_ref, :ret_commit_shas => commit_shas)
498
- commit_sha = nil
499
-
500
- if merge_rel == :equal
501
- commit_sha = commit_shas[:other_sha]
502
- elsif merge_rel == :no_remote_ref
503
- diffs = DiffSummary.new_version(repo)
504
- commit_sha = commit_shas[:local_sha]
505
- end
506
-
507
- diffs = DiffSummary.diff_remote(repo,local_branch, remote_branch_ref)
508
- { "diffs" => (diffs[:diffs]||"").to_s, "status" => repo.local_summary() }
509
- end
510
-
511
-
512
- def diffs__no_diffs
513
- DiffSummary.new
514
- end
515
- def compute_diffs(repo, remote_branch_ref)
516
- DiffSummary.diff(repo, repo.local_branch_name, remote_branch_ref)
517
- end
518
- public :diffs__no_diffs, :compute_diffs
519
-
520
- def pull_repo_changes_aux(repo, opts = {})
521
- # TODO: cleanup use of hard_reset and force
522
- force = opts[:hard_reset] || opts[:force]
523
-
524
- # default commit in case it is needed
525
- if repo.changed?
526
- repo.stage_and_commit('Commit prior to pull from remote')
527
- end
528
-
529
- if commit_sha = opts[:commit_sha]
530
- # no op if at commit_sha
531
- return diffs__no_diffs if (commit_sha == repo.head_commit_sha()) && !force
532
- end
533
-
534
- if opts[:remote_repo] && opts[:remote_repo_url]
535
- repo.add_remote(opts[:remote_repo], opts[:remote_repo_url])
536
- end
537
-
538
- repo.fetch(remote(opts[:remote_repo]))
539
- remote_branch_ref = remote_branch_ref(repo.local_branch_name, opts)
540
- # TODO: cleanup use of hard_reset and force; Merge.merge just uses :force
541
- Merge.merge(repo, remote_branch_ref, opts.merge(:force => force))
542
- end
543
-
544
- def remote(remote_repo=nil)
545
- remote_repo||"origin"
546
- end
547
-
548
- def remote_branch_ref(local_branch,opts={})
549
- "#{remote(opts[:remote_repo])}/#{opts[:remote_branch]||opts[:local_branch]||local_branch}"
550
- end
551
-
552
- def modules_dir(type, module_name, version=nil, opts={})
553
- type = type.to_sym
554
- if assembly_module = opts[:assembly_module]
555
- OsUtil.module_location_parts(type,module_name,version,opts)[0]
556
- elsif type == :component_module
557
- OsUtil.component_clone_location()
558
- elsif type == :service_module
559
- OsUtil.service_clone_location()
560
- elsif type == :test_module
561
- OsUtil.test_clone_location()
562
- else
563
- raise Error.new("Unexpected module type (#{type})")
564
- end
565
- end
566
-
567
- def local_repo_dir(type,full_module_name,version=nil,opts={})
568
- OsUtil.module_location(type, full_module_name, version, opts)
569
- end
570
-
571
- def backup_dir(type, full_module_name, opts={})
572
- namespace, name = full_module_name.split(':', 2)
573
- module_type = type.split('_').first
574
- backups_dir = OsUtil.backups_location()
575
-
576
- # create backups dir if deleted for some reason
577
- FileUtils::mkdir_p(backups_dir) unless File.directory?(backups_dir)
578
- "#{backups_dir}/#{module_type}-#{namespace}-#{name}-#{Time.now.to_i}"
579
- end
580
-
581
- def adapter_class()
582
- Common::GritAdapter::FileAccess
583
- end
584
-
585
- def pp_module(repo)
586
- repo.repo_dir.gsub(Regexp.new("/$"),"").split("/").last
587
- end
588
- end; end
589
- end; end; end