dtk-client 0.10.2 → 0.10.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.license_header +15 -0
  4. data/LICENSE +202 -0
  5. data/README.md +25 -2
  6. data/Rakefile +17 -1
  7. data/bin/dtk +18 -1
  8. data/lib/cli/command/account/add_ssh_key.rb +40 -0
  9. data/lib/cli/command/account/delete_ssh_key.rb +43 -0
  10. data/lib/cli/command/account/list_ssh_keys.rb +31 -0
  11. data/lib/cli/command/account/register_catalog_user.rb +31 -0
  12. data/lib/cli/command/account/set_catalog_credentials.rb +31 -0
  13. data/lib/cli/command/account/set_password.rb +31 -0
  14. data/lib/cli/command/account.rb +31 -0
  15. data/lib/cli/command/mixin.rb +1 -1
  16. data/lib/cli/command/module/delete_from_remote.rb +36 -0
  17. data/lib/cli/command/module/install.rb +15 -5
  18. data/lib/cli/command/module/publish.rb +34 -0
  19. data/lib/cli/command/module/pull_dtkn.rb +35 -0
  20. data/lib/cli/command/module/push_dtkn.rb +34 -0
  21. data/lib/cli/command/module/stage.rb +1 -1
  22. data/lib/cli/command/module/uninstall.rb +13 -7
  23. data/lib/cli/command/module.rb +14 -1
  24. data/lib/cli/command/options.rb +2 -0
  25. data/lib/cli/command/service/converge.rb +1 -1
  26. data/lib/cli/command/service/delete.rb +1 -1
  27. data/lib/cli/command/service/exec.rb +5 -2
  28. data/lib/cli/command/service/exec_sync.rb +4 -1
  29. data/lib/cli/command/service/{list_dependent_modules.rb → list_dependencies.rb} +3 -3
  30. data/lib/cli/command/service/uninstall.rb +11 -4
  31. data/lib/cli/command/service.rb +1 -1
  32. data/lib/cli/command/token.rb +3 -0
  33. data/lib/cli/command.rb +1 -1
  34. data/lib/cli/context/attributes.rb +1 -1
  35. data/lib/cli/context/type/account.rb +42 -0
  36. data/lib/cli/context/type/module.rb +2 -1
  37. data/lib/cli/context/type/service.rb +2 -1
  38. data/lib/cli/context.rb +82 -12
  39. data/lib/cli/version.rb +18 -2
  40. data/lib/client/git_repo/adapter/git_gem.rb +62 -4
  41. data/lib/client/git_repo.rb +33 -2
  42. data/lib/client/load_source/component_info.rb +44 -0
  43. data/lib/client/load_source/service_info.rb +47 -0
  44. data/lib/client/load_source.rb +148 -0
  45. data/lib/client/{util/module_ref.rb → module_ref.rb} +19 -0
  46. data/lib/client/operation/account/add_ssh_key.rb +47 -0
  47. data/lib/client/operation/account/delete_ssh_key.rb +41 -0
  48. data/lib/client/operation/account/list_ssh_keys.rb +28 -0
  49. data/lib/client/operation/account/register_catalog_user.rb +49 -0
  50. data/lib/client/operation/account/set_catalog_credentials.rb +32 -0
  51. data/lib/client/operation/account/set_password.rb +59 -0
  52. data/lib/client/operation/account.rb +7 -4
  53. data/lib/client/operation/client_module_dir/git_repo/internal/dtkn.rb +83 -0
  54. data/lib/client/operation/client_module_dir/git_repo/internal.rb +328 -0
  55. data/lib/client/operation/client_module_dir/git_repo.rb +73 -249
  56. data/lib/client/operation/client_module_dir.rb +2 -2
  57. data/lib/client/operation/module/clone_module.rb +41 -25
  58. data/lib/client/operation/module/delete_from_remote.rb +79 -0
  59. data/lib/client/operation/module/install/common_module.rb +10 -21
  60. data/lib/client/operation/module/install/dependent_modules/component_dependency_tree/cache.rb +47 -0
  61. data/lib/client/operation/module/install/dependent_modules/component_dependency_tree/resolve_modules.rb +69 -0
  62. data/lib/client/operation/module/install/dependent_modules/component_dependency_tree.rb +143 -0
  63. data/lib/client/operation/module/install/dependent_modules/component_module.rb +103 -0
  64. data/lib/client/operation/module/install/dependent_modules/prompt_helper.rb +54 -0
  65. data/lib/client/operation/module/install/dependent_modules.rb +65 -0
  66. data/lib/client/operation/module/install/mixin.rb +42 -0
  67. data/lib/client/operation/module/install/module_ref.rb +48 -0
  68. data/lib/client/operation/module/install/print_helper.rb +129 -0
  69. data/lib/client/operation/module/install.rb +68 -25
  70. data/lib/client/operation/module/install_from_catalog.rb +23 -32
  71. data/lib/client/operation/module/list.rb +4 -1
  72. data/lib/client/operation/module/publish.rb +78 -0
  73. data/lib/client/operation/module/pull_dtkn.rb +76 -0
  74. data/lib/client/operation/module/push.rb +16 -2
  75. data/lib/client/operation/module/push_dtkn/convert_source/component_info.rb +42 -0
  76. data/lib/client/operation/module/push_dtkn/convert_source/service_info.rb +47 -0
  77. data/lib/client/operation/module/push_dtkn/convert_source.rb +155 -0
  78. data/lib/client/operation/module/push_dtkn.rb +79 -0
  79. data/lib/client/operation/module/stage.rb +3 -2
  80. data/lib/client/operation/module/uninstall.rb +36 -0
  81. data/lib/client/operation/module.rb +23 -4
  82. data/lib/client/operation/service/converge.rb +3 -2
  83. data/lib/client/operation/service/delete.rb +2 -1
  84. data/lib/client/operation/service/destroy.rb +1 -1
  85. data/lib/client/operation/service/exec.rb +4 -0
  86. data/lib/client/operation/service/{list_dependent_modules.rb → list_dependencies.rb} +1 -1
  87. data/lib/client/operation/service/stage.rb +1 -1
  88. data/lib/client/operation/service/uninstall.rb +3 -3
  89. data/lib/client/operation/service.rb +1 -1
  90. data/lib/client/service_and_component_info/transform_from/info/component.rb +57 -0
  91. data/lib/client/service_and_component_info/transform_from/info/service.rb +53 -0
  92. data/lib/client/service_and_component_info/transform_from/info.rb +84 -0
  93. data/lib/client/service_and_component_info/transform_from.rb +47 -0
  94. data/lib/client/service_and_component_info/transform_to/info/component.rb +53 -0
  95. data/lib/client/service_and_component_info/transform_to/info/service.rb +49 -0
  96. data/lib/client/service_and_component_info/transform_to/info.rb +111 -0
  97. data/lib/client/service_and_component_info/transform_to.rb +49 -0
  98. data/lib/client/service_and_component_info.rb +26 -0
  99. data/lib/client/util/console.rb +22 -0
  100. data/lib/client/util/interactive_wizard.rb +90 -0
  101. data/lib/client/util.rb +18 -2
  102. data/lib/dtk_client.rb +5 -2
  103. metadata +63 -15
  104. data/lib/client/content_generator.rb +0 -189
  105. data/lib/client/operation/module/install/external_module.rb +0 -205
@@ -19,6 +19,8 @@ module DTK::Client
19
19
  class Operation::ClientModuleDir
20
20
  # Operations for managing module folders that are git repos
21
21
  class GitRepo < self
22
+ require_relative('git_repo/internal')
23
+
22
24
  def self.commit_and_push_to_service_repo(args)
23
25
  wrap_operation(args) do |args|
24
26
  response_data_hash(:head_sha => Internal.commit_and_push_to_service_repo(args))
@@ -53,12 +55,56 @@ module DTK::Client
53
55
  end
54
56
  end
55
57
 
56
- def self.create_add_remote_and_pull(args)
58
+ def self.create_empty_repo?(args)
59
+ wrap_operation(args) do |args|
60
+ repo_dir = args.required(:repo_dir)
61
+ Internal.create_empty_git_repo?(repo_dir)
62
+ response_data_hash
63
+ end
64
+ end
65
+
66
+ def self.create_repo_with_empty_commit(args)
67
+ wrap_operation(args) do |args|
68
+ repo_dir = args.required(:repo_dir)
69
+ commit_msg = args[:commit_msg]
70
+ repo = Internal.create_empty_git_repo?(repo_dir)
71
+ response_data_hash(:head_sha => Internal.empty_commit(repo, commit_msg))
72
+ end
73
+ end
74
+
75
+ def self.fetch_dtkn_remote(args)
76
+ wrap_operation(args) do |args|
77
+ repo_with_remote = repo_with_dtkn_remote(args)
78
+
79
+ repo_with_remote.fetch
80
+ response_data_hash
81
+ end
82
+ end
83
+
84
+ def self.merge_from_dtkn_remote(args)
57
85
  wrap_operation(args) do |args|
58
- repo_dir = args.required(:repo_dir)
59
- repo_url = args.required(:repo_url)
60
86
  remote_branch = args.required(:remote_branch)
61
- response_data_hash(:head_sha => Internal.create_add_remote_and_pull(repo_dir, repo_url, remote_branch))
87
+ no_commit = args[:no_commit]
88
+ repo_with_remote = repo_with_dtkn_remote(args)
89
+
90
+ response_data_hash(:head_sha => repo_with_remote.merge_from_remote(remote_branch, :no_commit => no_commit))
91
+ end
92
+ end
93
+
94
+ def self.checkout_branch__return_repo(args)
95
+ wrap_operation(args) do |args|
96
+ repo_dir = args.required(:repo_dir)
97
+ local_branch = args.required(:local_branch)
98
+ response_data_hash(:repo => Internal.checkout_branch__return_repo(repo_dir, local_branch))
99
+ end
100
+ end
101
+
102
+ def self.stage_and_commit(args)
103
+ wrap_operation(args) do |args|
104
+ repo_dir = args.required(:repo_dir)
105
+ local_branch_type = args.required(:local_branch_type)
106
+ commit_msg = args[:commit_msg]
107
+ response_data_hash(:head_sha => Internal.stage_and_commit(repo_dir, local_branch_type, :commit_msg => commit_msg))
62
108
  end
63
109
  end
64
110
 
@@ -74,6 +120,12 @@ module DTK::Client
74
120
  end
75
121
  end
76
122
 
123
+ def self.modified_with_diff(args)
124
+ wrap_operation(args) do |args|
125
+ response_data_hash(:modified => Internal.modified(args, :with_diffs => true))
126
+ end
127
+ end
128
+
77
129
  def self.init_and_push_from_existing_repo(args)
78
130
  wrap_operation(args) do |args|
79
131
  repo_dir = args.required(:repo_dir)
@@ -107,259 +159,31 @@ module DTK::Client
107
159
  end
108
160
  end
109
161
 
110
- private
111
-
112
- def self.response_data_hash(hash)
113
- hash.inject({}) { |h, (k, v)| h.merge(k.to_s => v) }
114
- end
115
-
116
- # All Internal methods do not have wrap_operation and can only be accessed by a method that wraps it
117
- class Internal < self
118
- # Git Params for dtk server
119
- module Dtk_Server
120
- GIT_REMOTE = 'dtk-server'
121
- end
122
- # Git params for dtkn
123
- module Dtkn
124
- GIT_REMOTE = 'dtkn'
125
- LOCAL_BRANCH = 'master'
126
- end
127
-
128
- # returns head_sha
129
- def self.commit_and_push_to_service_repo(args)
130
- branch = args.required(:branch)
131
- remote_branch = args[:remote_branch] || branch
132
- service_instance = args.required(:service_instance)
133
- commit_message = args[:commit_message]
134
-
135
- repo_dir = ret_base_path(:service, service_instance)
136
- repo = git_repo.new(repo_dir, :branch => branch)
137
- repo.stage_and_commit
138
- # TODO: want to switch over to using Dtk_Server::GIT_REMOTE rather than 'origin'
139
- dtk_server_remote = 'origin'
140
- repo.push(dtk_server_remote, remote_branch)
141
- repo.head_commit_sha
142
- end
143
-
144
- def self.clone_service_repo(args)
145
- repo_url = args.required(:repo_url)
146
- branch = args.required(:branch)
147
- service_instance = args.required(:service_instance)
148
- remove_existing = args[:remove_existing]
149
- repo_dir = args[:repo_dir]
150
-
151
- target_repo_dir = create_service_dir(service_instance, :remove_existing => remove_existing, :path => repo_dir)
152
- begin
153
- git_repo.clone(repo_url, target_repo_dir, branch)
154
- rescue => e
155
- #cleanup by deleting directory
156
-
157
- FileUtils.rm_rf(target_repo_dir) if File.directory?(target_repo_dir)
158
- # Log error details
159
- Logger.instance.error_pp(e.message, e.backtrace)
160
-
161
- # User-friendly error
162
- raise Error::Usage, "Clone to directory '#{target_repo_dir}' failed"
163
- end
164
- target_repo_dir
165
- end
166
-
167
- def self.clone_module_repo(args)
168
- module_type = args.required(:module_type)
169
- repo_url = args.required(:repo_url)
170
- branch = args.required(:branch)
171
- module_name = args.required(:module_name)
172
- remove_existing = args[:remove_existing]
173
- repo_dir = args[:repo_dir]
174
-
175
- target_repo_dir = create_module_dir(module_type, module_name, :remove_existing => remove_existing, :path => repo_dir)
176
- begin
177
- git_repo.clone(repo_url, target_repo_dir, branch)
178
- rescue => e
179
- FileUtils.rm_rf(target_repo_dir) if File.directory?(target_repo_dir)
180
- Logger.instance.error_pp(e.message, e.backtrace)
181
-
182
- raise Error::Usage, "Clone to directory '#{target_repo_dir}' failed"
183
- end
184
-
185
- target_repo_dir
186
- end
187
-
188
- def self.fetch_merge_and_push(args)
189
- repo_dir = args.required(:repo_dir)
190
- repo_url = args.required(:repo_url)
191
- remote_branch = args.required(:branch)
192
-
193
- head_sha =
194
- if git_repo.is_git_repo?(repo_dir)
195
- init_and_push_from_existing_repo(repo_dir, repo_url, remote_branch)
196
- else
197
- create_repo_from_remote_and_push(repo_dir, repo_url, remote_branch)
198
- end
199
-
200
- head_sha
201
- end
202
-
203
- def self.modified(args)
204
- repo_url = args.required(:path)
205
- branch = args.required(:branch)
206
- repo = git_repo.new(repo_url, :branch => branch)
207
-
208
- changed = repo.changed?
209
- repo.print_status if changed
210
- changed
211
- end
212
-
213
- def self.create_add_remote_and_push(repo_dir, repo_url, remote_branch)
214
- repo = git_repo.new(repo_dir)
215
- add_remote_and_push(repo, repo_url, remote_branch)
216
- repo.head_commit_sha
217
- end
218
-
219
- def self.create_add_remote_and_pull(repo_dir, repo_url, remote_branch)
220
- repo = create_repo_from_dtkn_remote(repo_dir, repo_url, remote_branch)
221
- add_dtkn_remote_and_pull(repo, repo_url, remote_branch)
222
- repo.head_commit_sha
223
- end
224
-
225
- def self.init_and_push_from_existing_repo(repo_dir, repo_url, remote_branch)
226
- repo = git_repo.new(repo_dir)
227
-
228
- if repo.is_there_remote?(Dtk_Server::GIT_REMOTE)
229
- push_when_there_is_dtk_remote(repo, repo_dir, repo_url, remote_branch)
230
- else
231
- add_remote_and_push(repo, repo_url, remote_branch)
232
- end
233
-
234
- repo.head_commit_sha
235
- end
236
-
237
- def self.pull_from_remote(args)
238
- repo_url = args.required(:repo_url)
239
- remote_branch = args.required(:branch)
240
- repo_dir = args.required(:repo_dir)
241
-
242
- repo = git_repo.new(repo_dir, :branch => remote_branch)
243
- repo.pull(repo.remotes.first, remote_branch)
244
- end
245
-
246
- # returns the repo
247
- def self.pull_from_service_repo(args)
248
- repo_url = args.required(:repo_url)
249
- remote_branch = args.required(:branch)
250
- service_instance = args.required(:service_instance)
251
-
252
- repo_dir = ret_base_path(:service, service_instance)
253
- repo = git_repo.new(repo_dir, :branch => remote_branch)
254
-
255
- repo.pull(repo.remotes.first, remote_branch)
256
- repo
257
- end
258
-
259
- def self.push_when_there_is_dtk_remote(repo, repo_dir, repo_url, remote_branch)
260
- # if there is only one remote and it is dtk-server; remove .git and initialize and push as new repo to dtk-server remote
261
- # else if multiple remotes and dtk-server being one of them; remove dtk-server; add new dtk-server remote and push
262
- if repo.remotes.size == 1
263
- git_repo.unlink_local_clone?(repo_dir)
264
- create_repo_from_remote_and_push(repo_dir, repo_url, remote_branch)
265
- else
266
- repo.remove_remote(Dtk_Server::GIT_REMOTE)
267
- add_remote_and_push(repo, repo_url, remote_branch)
268
- end
269
- end
270
-
271
- def self.create_repo_from_server_remote(repo_dir, repo_url, remote_branch)
272
- repo = git_repo.new(repo_dir, :branch => Dtkn::LOCAL_BRANCH)
273
- repo.checkout(Dtkn::LOCAL_BRANCH, :new_branch => true)
274
- repo.add_remote(Dtk_Server::GIT_REMOTE, repo_url)
275
- repo
276
- end
277
-
278
- def self.create_repo_from_dtkn_remote(repo_dir, repo_url, remote_branch)
279
- repo = git_repo.new(repo_dir, :branch => Dtkn::LOCAL_BRANCH)
280
- repo.checkout(Dtkn::LOCAL_BRANCH, :new_branch => true)
281
- repo.stage_and_commit
282
- repo.add_remote(Dtkn::GIT_REMOTE, repo_url)
283
- repo
284
- end
285
-
286
- def self.create_repo_from_remote_and_push(repo_dir, repo_url, remote_branch)
287
- repo = create_repo_from_server_remote(repo_dir, repo_url, remote_branch)
288
- # repo = git_repo.new(repo_dir, :branch => Dtkn::LOCAL_BRANCH)
289
- # repo.checkout(Dtkn::LOCAL_BRANCH, :new_branch => true)
290
- # repo.add_remote(Dtk_Server::GIT_REMOTE, repo_url)
291
- repo.stage_and_commit
292
- repo.push(Dtk_Server::GIT_REMOTE, remote_branch, { :force => true })
293
- repo.head_commit_sha
294
- end
295
-
296
- def self.add_remote_and_push(repo, repo_url, remote_branch)
297
- repo.add_remote(Dtk_Server::GIT_REMOTE, repo_url)
298
- repo.stage_and_commit
299
- repo.push(Dtk_Server::GIT_REMOTE, remote_branch, { :force => true })
300
- end
301
-
302
- def self.add_dtkn_remote_and_pull(repo, repo_url, remote_branch)
303
- repo.add_remote(Dtkn::GIT_REMOTE, repo_url)
304
- repo.pull(Dtkn::GIT_REMOTE, remote_branch)
305
- end
306
-
307
- def self.add_service_repo_file(args)
308
- branch = args.required(:branch)
309
- service_instance = args.required(:service_instance)
310
- path = args.required(:path)
311
- content = args.required(:content)
312
- checkout_branch(service_instance, branch) do
313
- File.open(qualified_path(service_instance, path), 'w') { |f| f.write(content) }
314
- end
315
- end
316
-
317
- # returns content if file exists
318
- def self.get_service_repo_file_content(args)
319
- branch = args.required(:branch)
320
- service_instance = args.required(:service_instance)
321
- path = args.required(:path)
322
- checkout_branch(service_instance, branch) do
323
- qualified_path = qualified_path(service_instance, path)
324
- if File.exists?(qualified_path)
325
- File.open(qualified_path, 'r').read
326
- end
327
- end
162
+ def self.all_branches(args)
163
+ wrap_operation(args) do |args|
164
+ response_data_hash(:branches => Internal.all_branches(args))
328
165
  end
166
+ end
329
167
 
330
- def self.git_repo
331
- ::DTK::Client::GitRepo
168
+ def self.current_branch(args)
169
+ wrap_operation(args) do |args|
170
+ response_data_hash(:branch => Internal.current_branch(args))
332
171
  end
172
+ end
333
173
 
334
- private
335
174
 
336
- # relative_path is relative to top-leel repo directory
337
- def self.qualified_path(service_instance, relative_path)
338
- repo_dir = ret_base_path(:service, service_instance)
339
- "#{repo_dir}/#{relative_path}"
340
- end
175
+ private
341
176
 
342
- CHECKOUT_LOCK = Mutex.new
343
- def self.checkout_branch(service_instance, branch, &body)
344
- ret = nil
345
- CHECKOUT_LOCK.synchronize do
346
- repo = git_repo.new(ret_base_path(:service, service_instance), :branch => branch)
347
- current_branch = repo.current_branch.name
348
- if current_branch == branch
349
- ret = yield
350
- else
351
- begin
352
- repo.checkout(branch)
353
- ret = yield
354
- ensure
355
- repo.checkout(current_branch)
356
- end
357
- end
358
- end
359
- ret
360
- end
177
+ def self.repo_with_dtkn_remote(args)
178
+ info_type = args.required(:info_type)
179
+ repo_dir = args.required(:repo_dir)
180
+ Internal::Dtkn.repo_with_remote(info_type, repo_dir, add_remote: args[:add_remote])
181
+ end
361
182
 
183
+ def self.response_data_hash(hash = {})
184
+ hash.inject({}) { |h, (k, v)| h.merge(k.to_s => v) }
362
185
  end
186
+
363
187
  end
364
188
  end
365
189
  end
@@ -106,8 +106,8 @@ module DTK::Client
106
106
  "#{OsUtil.current_dir}/#{name.gsub(':','/')}"
107
107
  end
108
108
 
109
- def self.purge_service_instance_dir(dir_path)
110
- FileUtils.rm_rf(dir_path)
109
+ def self.rm_f(path)
110
+ FileUtils.rm_rf(path)
111
111
  end
112
112
 
113
113
  def self.delete_directory_content(path)
@@ -18,37 +18,53 @@
18
18
  module DTK::Client
19
19
  class Operation::Module
20
20
  class CloneModule < self
21
+ attr_reader :module_ref, :target_repo_dir, :module_name, :version
22
+ def initialize(module_name, module_ref, target_directory)
23
+ @module_name = module_name
24
+ @module_ref = module_ref
25
+ @target_repo_dir = target_directory || ClientModuleDir.ret_path_with_current_dir(module_name)
26
+ @version = module_ref.version
27
+ end
28
+ private :initialize
29
+
21
30
  def self.execute(args = Args.new)
22
31
  wrap_operation(args) do |args|
23
32
  module_ref = args.required(:module_ref)
24
33
  module_name = args.required(:module_name)
25
34
  target_directory = args[:target_directory]
26
-
27
- opts = {
28
- :namespace => module_ref.namespace,
29
- :version => module_ref.version
30
- }
31
-
32
- unless module_info = module_exists?(module_ref, :type => :common_module)
33
- raise Error::Usage, "DTK module '#{DTK::Common::PrettyPrintForm.module_ref(module_ref.module_name, opts)}' does not exist on server."
34
- end
35
-
36
- branch = module_info.required(:branch, :name)
37
- repo_url = module_info.required(:repo, :url)
38
- repo_name = module_info.required(:repo, :name)
39
-
40
- clone_args = {
41
- :module_type => :common_module,
42
- :repo_url => module_info.required(:repo, :url),
43
- :branch => module_info.required(:branch, :name),
44
- :module_name => module_name,
45
- :repo_dir => target_directory || ClientModuleDir.ret_path_with_current_dir(module_name)
46
- # :remove_existing => remove_existing
47
- }
48
-
49
- ret = ClientModuleDir::GitRepo.clone_module_repo(clone_args)
50
- OsUtil.print_info("DTK module '#{DTK::Common::PrettyPrintForm.module_ref(module_ref.module_name, opts)}' has been successfully cloned into '#{ret.required(:target_repo_dir)}'")
35
+ new(module_name, module_ref, target_directory).clone_module
36
+ end
37
+ end
38
+
39
+ def clone_module
40
+ opts = {
41
+ :namespace => module_ref.namespace,
42
+ :version => version
43
+ }
44
+
45
+ unless module_info = module_version_exists?(module_ref, :type => :common_module, :remote_info => true, :rsa_pub_key => SSHUtil.rsa_pub_key_content)
46
+ raise Error::Usage, "DTK module '#{DTK::Common::PrettyPrintForm.module_ref(module_ref.module_name, opts)}' does not exist on server."
51
47
  end
48
+
49
+ branch = module_info.required(:branch, :name)
50
+ repo_url = module_info.required(:repo, :url)
51
+ repo_name = module_info.required(:repo, :name)
52
+
53
+ clone_args = {
54
+ :module_type => :common_module,
55
+ :repo_url => module_info.required(:repo, :url),
56
+ :branch => module_info.required(:branch, :name),
57
+ :module_name => module_name,
58
+ :repo_dir => target_repo_dir
59
+ }
60
+
61
+ ret = ClientModuleDir::GitRepo.clone_module_repo(clone_args)
62
+
63
+ if module_info.data(:component_info) || module_info.data(:service_info)
64
+ LoadSource.fetch_from_remote(module_info, self)
65
+ end
66
+
67
+ OsUtil.print_info("DTK module '#{DTK::Common::PrettyPrintForm.module_ref(module_ref.module_name, opts)}' has been successfully cloned into '#{ret.required(:target_repo_dir)}'")
52
68
  end
53
69
  end
54
70
  end
@@ -0,0 +1,79 @@
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
+ class Operation::Module
20
+ class DeleteFromRemote < self
21
+ attr_reader :module_ref
22
+
23
+ def initialize(catalog, module_ref)
24
+ @catalog = catalog
25
+ @module_ref = module_ref
26
+ end
27
+ private :initialize
28
+
29
+ def self.execute(args = Args.new)
30
+ wrap_operation(args) do |args|
31
+ module_ref = args.required(:module_ref)
32
+ new('dtkn', module_ref).delete_from_remote(:skip_prompt => args[:skip_prompt])
33
+ end
34
+ end
35
+
36
+ def delete_from_remote(opts = {})
37
+ query_string_hash = QueryStringHash.new(
38
+ :module_name => module_ref.module_name,
39
+ :namespace => module_ref.namespace,
40
+ :rsa_pub_key => SSHUtil.rsa_pub_key_content,
41
+ )
42
+
43
+ unless version = module_ref.version
44
+ remotes = Operation::Module.list_remotes({})
45
+
46
+ selected_module = remotes.data.find{ |vr| vr['display_name'].eql?("#{module_ref.namespace}/#{module_ref.module_name}") }
47
+ raise Error::Usage, "Module '#{module_ref.namespace}/#{module_ref.module_name}' does not exist on repo manager!" unless selected_module
48
+
49
+ versions = selected_module['versions']
50
+ versions.map! { |v| v == 'base' ? 'master' : v }
51
+
52
+ if versions.size > 1
53
+ ret_version = Console.version_prompt(versions, "Select which module version to delete: ", { :add_all => true })
54
+ return unless ret_version
55
+ version = ret_version
56
+ else
57
+ version = versions.first
58
+ end
59
+ end
60
+
61
+ query_string_hash.merge!(:version => version)
62
+ query_string_hash.merge!(:versions => versions) if version.eql?('all')
63
+
64
+ unless opts[:skip_prompt]
65
+ module_ref_opts = { :namespace => module_ref.namespace }
66
+ module_ref_opts.merge!(:version => version) unless version.eql?('all')
67
+ return unless Console.prompt_yes_no("Are you sure you want to delete module '#{DTK::Common::PrettyPrintForm.module_ref(module_ref.module_name, module_ref_opts)}' from repo manager?", :add_options => true)
68
+ end
69
+
70
+ rest_post "#{BaseRoute}/delete_from_remote", query_string_hash
71
+
72
+ nil
73
+ end
74
+
75
+ end
76
+ end
77
+ end
78
+
79
+
@@ -20,36 +20,25 @@ module DTK::Client
20
20
  class CommonModule < self
21
21
  BaseRoute = 'modules'
22
22
 
23
- def self.install(module_ref, file_obj)
24
- post_body = PostBody.new(
23
+ # opts can have keys:
24
+ # :has_remote_repo
25
+ def self.install(module_ref, file_obj, opts = {})
26
+ common_post_body = PostBody.new(
25
27
  :module_name => module_ref.module_name,
26
28
  :namespace => module_ref.namespace,
27
29
  :version? => module_ref.version
28
30
  )
29
31
 
30
- response = rest_post("#{BaseRoute}/create_empty_module", post_body)
32
+ create_post_body = common_post_body.merge(:has_remote_repo? => opts[:has_remote_repo])
33
+ response = rest_post("#{BaseRoute}/create_empty_module", create_post_body)
31
34
 
32
35
  branch = response.required(:branch, :name)
33
36
  repo_url = response.required(:repo, :url)
34
- repo_name = response.required(:repo, :name)
35
37
 
36
- # making repo dir to be directory that directly holds the base file object file_obj
37
- repo_dir = file_obj.parent_dir
38
-
39
- args = {
40
- :repo_dir => repo_dir,
41
- :repo_url => repo_url,
42
- :branch => branch
43
- }
44
-
45
- git_response = ClientModuleDir::GitRepo.fetch_merge_and_push(args)
46
-
47
- post_body.merge!(
48
- :repo_name => repo_name,
49
- :commit_sha => git_response.data(:head_sha)
50
- )
51
-
52
- rest_post("#{BaseRoute}/update_from_repo", post_body)
38
+ repo_dir = file_obj.parent_dir # repo dir is directory that directly holds the base file object file_obj
39
+ git_response = ClientModuleDir::GitRepo.fetch_merge_and_push(:repo_dir => repo_dir, :repo_url => repo_url, :branch => branch)
40
+ commit_sha = git_response.data(:head_sha)
41
+ rest_post("#{BaseRoute}/update_from_repo", common_post_body.merge(:commit_sha => commit_sha))
53
42
  end
54
43
  end
55
44
  end
@@ -0,0 +1,47 @@
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
+ class Operation::Module::Install::DependentModules::ComponentDependencyTree
20
+ class Cache < ::Hash
21
+ # hash where key unqiuely determines module_refs and value is to hash with keys :module_ref and :dependencies
22
+ def initialize
23
+ super()
24
+ end
25
+
26
+ def add!(module_ref, dependencies)
27
+ self[index(module_ref)] ||= {:module_ref => module_ref, :dependencies => dependencies }
28
+ end
29
+
30
+ def lookup_dependencies?(module_ref)
31
+ (self[index(module_ref)] || {})[:dependencies]
32
+ end
33
+
34
+ def all_modules_refs
35
+ values.map { |hash| hash[:module_ref] }
36
+ end
37
+
38
+ private
39
+
40
+ def index(module_ref)
41
+ "#{module_ref.module_name}--#{module_ref.namespace}--#{module_ref.version}"
42
+ end
43
+
44
+ end
45
+ end
46
+ end
47
+