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
@@ -18,63 +18,105 @@
18
18
  module DTK::Client
19
19
  class Operation::Module
20
20
  class Install < self
21
- require_relative('install/external_module')
21
+ require_relative('install/mixin')
22
+ # mixin must go first
23
+ require_relative('install/print_helper')
24
+ require_relative('install/module_ref')
25
+ require_relative('install/dependent_modules')
22
26
  require_relative('install/common_module')
23
27
 
28
+ def initialize(file_obj, module_ref, has_remote_repo)
29
+ @file_obj = file_obj
30
+ @base_module_ref = module_ref
31
+ @parsed_module = file_obj.parse_content(:common_module_summary)
32
+ @has_remote_repo = has_remote_repo
33
+ @print_helper = PrintHelper.new(:module_ref => @base_module_ref, :source => has_remote_repo ? :remote : :local)
34
+ end
35
+ private :initialize
36
+
24
37
  def self.execute(args = Args.new)
25
38
  wrap_operation(args) do |args|
26
- if args[:flag]
39
+ module_ref = args.required(:module_ref)
40
+ base_dsl_file_obj = args.required(:base_dsl_file_obj)
41
+ has_directory_param = args[:has_directory_param]
42
+ skip_prompt = args[:skip_prompt]
43
+ has_remote_repo = args[:has_remote_repo]
44
+
45
+ if has_directory_param
27
46
  file_obj = args.required(:base_dsl_file_obj).raise_error_if_no_content_flag(:module_ref)
28
47
  else
29
48
  file_obj = args.required(:base_dsl_file_obj).raise_error_if_no_content
30
49
  end
31
50
 
32
- new(file_obj, args.required(:module_ref)).install(:skip_prompt => args[:skip_prompt])
51
+ new(file_obj, module_ref, has_remote_repo).install(:skip_prompt => skip_prompt)
33
52
  end
34
53
  end
35
-
54
+
55
+ # opts can have keys:
56
+ # :skip_prompt
36
57
  def install(opts = {})
37
58
  unless @base_module_ref
38
59
  raise Error::Usage, "No base module reference #{dsl_path_ref}"
39
60
  end
40
61
 
41
- if module_exists?(@base_module_ref, { :type => :common_module })
42
- raise Error::Usage, "Module #{@base_module_ref.print_form} exists already"
62
+ if module_version_exists?(@base_module_ref, { :type => :common_module })
63
+ raise Error::Usage, "Module '#{@base_module_ref.print_form}' exists already"
43
64
  end
44
65
 
45
66
  unless dependent_modules.empty?
46
- OsUtil.print_info('Auto-importing dependencies')
47
- ExternalModule.install_dependent_modules(dependent_modules, opts)
67
+ begin
68
+ DependentModules.install(@base_module_ref, dependent_modules, :skip_prompt => opts[:skip_prompt])
69
+ rescue TerminateInstall
70
+ @print_helper.print_terminated_installation
71
+ return nil
72
+ end
48
73
  end
49
74
 
50
- opts = {
51
- :namespace => @base_module_ref.namespace,
52
- :version => @base_module_ref.version
53
- }
54
- CommonModule.install(@base_module_ref, @file_obj)
55
- OsUtil.print_info("Successfully imported '#{DTK::Common::PrettyPrintForm.module_ref(@base_module_ref.module_name, opts)}'")
75
+ @print_helper.print_continuation_installing_base_module
76
+ CommonModule.install(@base_module_ref, @file_obj, :has_remote_repo => @has_remote_repo)
77
+ @print_helper.print_done_message
56
78
  nil
57
79
  end
58
80
 
59
- private
60
-
61
- def initialize(file_obj, module_ref)
62
- @file_obj = file_obj
63
- @base_module_ref = module_ref
64
- @parsed_module = file_obj.parse_content(:common_module_summary)
81
+ class TerminateInstall < ::Exception
65
82
  end
66
83
 
84
+ private
85
+
67
86
  def dependent_modules
68
87
  @dependent_modules ||= compute_dependent_modules
69
88
  end
70
89
 
71
90
  def compute_dependent_modules
72
- (@parsed_module.val(:DependentModules) || []).map do |parsed_module_ref|
73
- namespace = parsed_module_ref.req(:Namespace)
74
- module_name = parsed_module_ref.req(:ModuleName)
75
- version = parsed_module_ref.val(:ModuleVersion)
76
- ModuleRef.new(:namespace => namespace, :module_name => module_name, :version => version)
91
+ base_component_module_found = false
92
+ ret = (@parsed_module.val(:DependentModules) || []).map do |parsed_module_ref|
93
+ dep_module_name = parsed_module_ref.req(:ModuleName)
94
+ dep_namespace = parsed_module_ref.req(:Namespace)
95
+ dep_version = parsed_module_ref.val(:ModuleVersion)
96
+ if is_base_module = (dep_module_name == module_name)
97
+ # This is for legacy modules
98
+ base_component_module_found = true
99
+ end
100
+ ModuleRef.new(:namespace => dep_namespace, :module_name => dep_module_name, :version => dep_version, :is_base_module => is_base_module)
77
101
  end
102
+ unless base_component_module_found
103
+ if module_version_exists?(@base_module_ref, :type => :component_module)
104
+ ret << ModuleRef.new(:namespace => namespace, :module_name => module_name, :version => version, :is_base_module => true)
105
+ end
106
+ end
107
+ ret
108
+ end
109
+
110
+ def namespace
111
+ @base_module_ref.namespace
112
+ end
113
+
114
+ def module_name
115
+ @base_module_ref.module_name
116
+ end
117
+
118
+ def version
119
+ @base_module_ref.version
78
120
  end
79
121
 
80
122
  def components
@@ -89,6 +131,7 @@ module DTK::Client
89
131
  "in the dsl file"
90
132
  end
91
133
  end
134
+
92
135
  end
93
136
  end
94
137
  end
@@ -18,6 +18,16 @@
18
18
  module DTK::Client
19
19
  class Operation::Module
20
20
  class InstallFromCatalog < self
21
+ attr_reader :version, :module_ref, :target_repo_dir
22
+ def initialize(catalog, module_ref, directory_path, version)
23
+ @catalog = catalog
24
+ @module_ref = module_ref
25
+ @directory_path = directory_path
26
+ @target_repo_dir = ClientModuleDir.create_module_dir_from_path(directory_path || OsUtil.current_dir)
27
+ @version = version # if nil wil be dynamically updated along with version attribute of @module_ref
28
+ end
29
+ private :initialize
30
+
21
31
  def self.execute(args = Args.new)
22
32
  wrap_operation(args) do |args|
23
33
  module_ref = args.required(:module_ref)
@@ -25,55 +35,36 @@ module DTK::Client
25
35
  directory_path = args[:directory_path]
26
36
 
27
37
  # will create different classes for different catalog types when we add support for them
28
- new('dtkn', module_ref, directory_path, version).install
38
+ new('dtkn', module_ref, directory_path, version).install_from_catalog
29
39
  end
30
40
  end
31
41
 
32
- def install
33
- if module_exists?(@module_ref, :type => :common_module)
34
- raise Error::Usage, "Module #{@module_ref.print_form} exists already"
35
- end
36
-
37
- target_repo_dir = ClientModuleDir.create_module_dir_from_path(@directory_path || OsUtil.current_dir)
38
-
42
+ def install_from_catalog
39
43
  query_string_hash = QueryStringHash.new(
40
44
  :module_name => @module_ref.module_name,
41
45
  :namespace => @module_ref.namespace,
42
46
  :rsa_pub_key => SSHUtil.rsa_pub_key_content,
43
47
  :version? => @version
44
48
  )
45
- module_info = rest_get "#{BaseRoute}/remote_module_info", query_string_hash
46
49
 
47
- # unless version is explicitly provided, use latest version instead of master
50
+ remote_module_info = rest_get "#{BaseRoute}/remote_module_info", query_string_hash
51
+
48
52
  unless @version
49
- @version = module_info.required(:latest_version)
53
+ @version = remote_module_info.required(:version)
54
+ @module_ref.version = @version
50
55
  end
51
56
 
52
- git_repo_args = {
53
- :repo_dir => target_repo_dir,
54
- :repo_url => module_info.required(:remote_repo_url),
55
- :remote_branch => (@version && !@version.eql?('master')) ? "v#{@version}" : 'master'
56
- }
57
- ClientModuleDir::GitRepo.create_add_remote_and_pull(git_repo_args)
58
-
59
- module_content_hash = ContentGenerator.new(target_repo_dir, @module_ref, @version).generate_module_content
57
+ if module_version_exists?(@module_ref, :type => :common_module)
58
+ raise Error::Usage, "Module '#{@module_ref.print_form}' exists already"
59
+ end
60
60
 
61
- # delete old files
62
- Operation::ClientModuleDir.delete_directory_content(target_repo_dir)
61
+ create_repo_opts = { :repo_dir => @target_repo_dir, :commit_msg => "DTK client initialize" }
62
+ Operation::ClientModuleDir::GitRepo.create_repo_with_empty_commit(create_repo_opts)
63
+ LoadSource.fetch_transform_and_merge(remote_module_info, self)
63
64
 
64
- # generate dtk.module.yaml file from parsed assemblies and module_refs
65
- Operation::ClientModuleDir.create_file_with_content("#{target_repo_dir}/dtk.module.yaml", self.class.hash_to_yaml(module_content_hash))
66
- {:target_repo_dir => target_repo_dir}
65
+ {:target_repo_dir => @target_repo_dir}
67
66
  end
68
-
69
- private
70
67
 
71
- def initialize(catalog, module_ref, directory_path, version)
72
- @catalog = catalog
73
- @module_ref = module_ref
74
- @directory_path = directory_path
75
- @version = version
76
- end
77
68
  end
78
69
  end
79
70
  end
@@ -22,7 +22,10 @@ module DTK::Client
22
22
  wrap_operation(args) do |_args|
23
23
  # defaults
24
24
  query_string_hash = QueryStringHash.new(
25
- :detail_to_include => ['remotes', 'versions']
25
+ :detail_to_include => [
26
+ 'remotes',
27
+ 'versions'
28
+ ]
26
29
  )
27
30
  rest_get("#{BaseRoute}/list", query_string_hash)
28
31
  end.set_render_as_table!
@@ -0,0 +1,78 @@
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 Publish < self
21
+ attr_reader :module_ref, :target_repo_dir, :version
22
+ def initialize(catalog, module_ref, directory_path)
23
+ @catalog = catalog
24
+ @module_ref = module_ref
25
+ @target_repo_dir = directory_path || module_ref.client_dir_path
26
+ @version = module_ref.version
27
+ end
28
+ private :initialize
29
+
30
+ def self.execute(args = Args.new)
31
+ wrap_operation(args) do |args|
32
+ module_ref = args.required(:module_ref)
33
+ directory_path = args[:directory_path]
34
+ new('dtkn', module_ref, directory_path).publish
35
+ end
36
+ end
37
+
38
+ def publish
39
+ unless module_version_exists?(module_ref, :type => :common_module)
40
+ raise Error::Usage, "Module #{module_ref.print_form} does not exist on server"
41
+ end
42
+
43
+ error_msg = "To allow publish to go through, invoke 'dtk push' to push the changes to server before invoking publish again"
44
+ GitRepo.modified_with_diff?(target_repo_dir, { :error_msg => error_msg })
45
+
46
+ post_body = PostBody.new(
47
+ :module_name => module_ref.module_name,
48
+ :namespace => module_ref.namespace,
49
+ :version => @version,
50
+ :rsa_pub_key => SSHUtil.rsa_pub_key_content
51
+ )
52
+
53
+ response = rest_post "#{BaseRoute}/publish_to_remote", post_body
54
+
55
+ query_string_hash = QueryStringHash.new(
56
+ :module_name => module_ref.module_name,
57
+ :namespace => module_ref.namespace,
58
+ :rsa_pub_key => SSHUtil.rsa_pub_key_content,
59
+ :version? => @version
60
+ )
61
+ remote_module_info = rest_get "#{BaseRoute}/remote_module_info", query_string_hash
62
+
63
+ unless @version
64
+ @version = remote_module_info.required(:version)
65
+ @module_ref.version = @version
66
+ end
67
+
68
+ # this is temporary until we implement push-dtkn from server instead of from client
69
+ # this part will fetch remote branches from repo manager after publish from server is finished
70
+ LoadSource.fetch_from_remote(remote_module_info, self)
71
+
72
+ nil
73
+ end
74
+ end
75
+ end
76
+ end
77
+
78
+
@@ -0,0 +1,76 @@
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 PullDtkn < self
21
+ attr_reader :version, :module_ref, :target_repo_dir, :base_dsl_file_obj
22
+ def initialize(catalog, module_ref, directory_path, version, base_dsl_file_obj)
23
+ @catalog = catalog
24
+ @module_ref = module_ref
25
+ @directory_path = directory_path
26
+ @target_repo_dir = directory_path || base_dsl_file_obj.parent_dir
27
+ @version = version # if nil wil be dynamically updated
28
+ @base_dsl_file_obj = base_dsl_file_obj
29
+ end
30
+ private :initialize
31
+
32
+ def self.execute(args = Args.new)
33
+ wrap_operation(args) do |args|
34
+ module_ref = args.required(:module_ref)
35
+ version = args[:version] || module_ref.version
36
+ base_dsl_file_obj = args[:base_dsl_file_obj]
37
+ directory_path = args[:directory_path]
38
+ new('dtkn', module_ref, directory_path, version, base_dsl_file_obj).pull_dtkn
39
+ end
40
+ end
41
+
42
+ def pull_dtkn
43
+ # TODO: DTK-2765: not sure if we need module to exist on server to do push-dtkn
44
+ unless module_version_exists?(@module_ref, :type => :common_module)
45
+ raise Error::Usage, "Module #{@module_ref.print_form} does not exist on server"
46
+ end
47
+
48
+ if ref_version = @version || module_ref.version
49
+ raise Error::Usage, "You are not allowed to pull module version '#{ref_version}'!" unless ref_version.eql?('master')
50
+ end
51
+
52
+ error_msg = "To allow pull-dtkn to go through, invoke 'dtk push' to push the changes to server before invoking pull-dtkn again"
53
+ GitRepo.modified_with_diff?(@target_repo_dir, { :error_msg => error_msg })
54
+
55
+ query_string_hash = QueryStringHash.new(
56
+ :module_name => @module_ref.module_name,
57
+ :namespace => @module_ref.namespace,
58
+ :rsa_pub_key => SSHUtil.rsa_pub_key_content,
59
+ :version? => @version
60
+ )
61
+ remote_module_info = rest_get "#{BaseRoute}/remote_module_info", query_string_hash
62
+
63
+ unless @version
64
+ @version = remote_module_info.required(:version)
65
+ @module_ref.version = @version
66
+ end
67
+
68
+ LoadSource.fetch_transform_and_merge(remote_module_info, self, :stage_and_commit_steps => true)
69
+ nil
70
+ end
71
+
72
+ end
73
+ end
74
+ end
75
+
76
+
@@ -26,7 +26,7 @@ module DTK::Client
26
26
  raise Error, "Not implemented yet; need to make sure module_ref.client_dir_path is set when client_dir_path given"
27
27
  end
28
28
 
29
- unless module_info = module_exists?(module_ref, :type => :common_module)
29
+ unless module_info = module_version_exists?(module_ref, :type => :common_module)
30
30
  raise Error::Usage, "DTK module '#{module_ref.print_form}' does not exist."
31
31
  end
32
32
 
@@ -51,10 +51,24 @@ module DTK::Client
51
51
  :commit_sha => git_repo_response.data(:head_sha)
52
52
  )
53
53
 
54
- rest_post("#{BaseRoute}/update_from_repo", post_body)
54
+ response = rest_post("#{BaseRoute}/update_from_repo", post_body)
55
+ # TODO: DTK-2786; uncomment out to see what diffs is returning for different examples of what is deleted, added or modified before push
56
+ # pp [:debug_diffs, response.data(:diffs)]
57
+ process_semantic_diffs(response.data(:diffs))
58
+
59
+ # if diffs is nil then indicate no diffs, otherwise render diffs in yaml
60
+ OsUtil.print_info("No Diffs to be pushed.") if response.data(:diffs).nil?
55
61
  nil
56
62
  end
57
63
  end
64
+
65
+ def self.process_semantic_diffs(diffs)
66
+ return if (diffs || {}).empty?
67
+ OsUtil.print_info("\nDiffs that were pushed:")
68
+
69
+ diffs.each { |v| diffs.delete(v[0]) if v[1].nil? }
70
+ OsUtil.print(hash_to_yaml(diffs).gsub("---\n", ""))
71
+ end
58
72
  end
59
73
  end
60
74
  end
@@ -0,0 +1,42 @@
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::PushDtkn
20
+ class ConvertSource
21
+ class ComponentInfo < self
22
+ # attr_reader :parsed_common_module
23
+
24
+ def transform_info
25
+ transform_to_component_info
26
+ end
27
+
28
+ private
29
+
30
+ def self.info_type
31
+ :component_info
32
+ end
33
+
34
+ def transform_to_component_info
35
+ info_processor.read_inputs_and_compute_outputs!
36
+ info_processor.file_path__content_array
37
+ end
38
+
39
+ end
40
+ end
41
+ end
42
+ 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::PushDtkn
20
+ class ConvertSource
21
+ class ServiceInfo < self
22
+ def transform_info
23
+ transform_to_service_info
24
+ end
25
+
26
+ def legacy_assemblies?
27
+ info_processor.legacy_assemblies?
28
+ end
29
+
30
+ private
31
+
32
+ def self.info_type
33
+ :service_info
34
+ end
35
+
36
+ def transform_to_service_info
37
+ info_processor.read_inputs_and_compute_outputs!
38
+ info_processor.file_path__content_array
39
+ # delete old files
40
+ # TODO: just delete the input files
41
+ # Operation::ClientModuleDir.delete_directory_content(target_repo_dir)
42
+ end
43
+
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,155 @@
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; class Operation::Module
19
+ class PushDtkn
20
+ class ConvertSource
21
+ require_relative('convert_source/service_info')
22
+ require_relative('convert_source/component_info')
23
+
24
+ def initialize(transform_helper, info_type, remote_repo_url, parent)
25
+ @info_processor = transform_helper.info_processor(info_type)
26
+ @info_type = info_type
27
+ @remote_repo_url = remote_repo_url
28
+ @target_repo_dir = parent.target_repo_dir
29
+ @version = parent.version
30
+ end
31
+ private :initialize
32
+
33
+ def self.transform_and_commit(remote_module_info, parent)
34
+ target_repo_dir = parent.target_repo_dir
35
+ parsed_common_module = parent.base_dsl_file_obj.parse_content(:common_module)
36
+ local_branch = Operation::ClientModuleDir::GitRepo.current_branch(:path => target_repo_dir).data(:branch)
37
+
38
+ if service_info = remote_module_info.data(:service_info)
39
+ transform_service_info(target_repo_dir, parent, service_info, parsed_common_module, local_branch)
40
+ end
41
+
42
+ if component_info = remote_module_info.data(:component_info)
43
+ transform_component_info(target_repo_dir, parent, component_info, parsed_common_module, local_branch)
44
+ end
45
+ end
46
+
47
+ def self.transform_info(transform_helper, remote_repo_url, parent)
48
+ new(transform_helper, info_type, remote_repo_url, parent).transform_info
49
+ end
50
+
51
+ def self.transform_service_info(target_repo_dir, parent, service_info, parsed_common_module, local_branch = 'master')
52
+ transform_helper = ServiceAndComponentInfo::TransformTo.new(target_repo_dir, parent.module_ref, parent.version, parsed_common_module)
53
+ service_file_path__content_array = ServiceInfo.transform_info(transform_helper, service_info['remote_repo_url'], parent)
54
+
55
+ repo = checkout_branch__return_repo(target_repo_dir, "remotes/dtkn/master").data(:repo)
56
+ FileUtils.mkdir_p("#{target_repo_dir}/assemblies") unless File.exists?("#{target_repo_dir}/assemblies")
57
+
58
+ args = [transform_helper, ServiceInfo.info_type, service_info['remote_repo_url'], parent]
59
+ service_file_path__content_array.each { |file| Operation::ClientModuleDir.create_file_with_content("#{service_file_path(target_repo_dir, file, *args)}", file[:content]) }
60
+
61
+ commit_and_push_to_remote(repo, target_repo_dir, "master", "dtkn", local_branch)
62
+ end
63
+
64
+ def self.transform_component_info(target_repo_dir, parent, component_info, parsed_common_module, local_branch = 'master')
65
+ transform_helper = ServiceAndComponentInfo::TransformTo.new(target_repo_dir, parent.module_ref, parent.version, parsed_common_module)
66
+ component_file_path__content_array = ComponentInfo.transform_info(transform_helper, component_info['remote_repo_url'], parent)
67
+
68
+ repo = checkout_branch__return_repo(target_repo_dir, "remotes/dtkn-component-info/master").data(:repo)
69
+ component_file_path__content_array.each { |file| Operation::ClientModuleDir.create_file_with_content("#{file_path(target_repo_dir, file)}", file[:content]) }
70
+
71
+ commit_and_push_to_remote(repo, target_repo_dir, "master", "dtkn-component-info", local_branch)
72
+ end
73
+
74
+ private
75
+
76
+ attr_reader :info_processor, :target_repo_dir, :parent
77
+
78
+ def self.write_output_path_text_pairs(transform_helper, target_repo_dir, info_types_processed)
79
+ end
80
+
81
+ def self.file_path(target_repo_dir, file)
82
+ file[:full_path] ? file[:path] : "#{target_repo_dir}/#{file[:path]}"
83
+ end
84
+
85
+ def self.service_file_path(target_repo_dir, file, *args)
86
+ @new_service_info ||= ServiceInfo.new(*args)
87
+ @legacy_assemblies ||= @new_service_info.legacy_assemblies?
88
+
89
+ if @legacy_assemblies && !file[:path].include?('module_refs.yaml')
90
+ convert_to_legacy_assebmly(target_repo_dir, file)
91
+ else
92
+ file_path(target_repo_dir, file)
93
+ end
94
+ end
95
+
96
+ def self.convert_to_legacy_assebmly(target_repo_dir, file)
97
+ return file[:path] if file[:full_path]
98
+
99
+ file_path = file[:path]
100
+ file_name = file_path.split('/').last
101
+ assembly_name = file_name.split('.').first
102
+
103
+ "#{target_repo_dir}/assemblies/#{assembly_name}/assembly.yaml"
104
+ end
105
+
106
+ def self.checkout_branch__return_repo(target_repo_dir, branch)
107
+ git_repo_args = {
108
+ :repo_dir => target_repo_dir,
109
+ :local_branch => branch
110
+ }
111
+ git_repo_operation.checkout_branch__return_repo(git_repo_args)
112
+ end
113
+
114
+ def self.commit_and_push_to_remote(repo, target_repo_dir, branch, remote, local_branch)
115
+ repo.stage_and_commit("Add auto-generated files from push-dtkn")
116
+ repo.push_from_cached_branch(remote, branch, { :force => true })
117
+ repo.checkout(local_branch)
118
+ end
119
+
120
+ def self.stage_and_commit(target_repo_dir, commit_msg = nil)
121
+ git_repo_args = {
122
+ :repo_dir => target_repo_dir,
123
+ :commit_msg => commit_msg,
124
+ :local_branch_type => :dtkn
125
+ }
126
+ git_repo_operation.stage_and_commit(git_repo_args)
127
+ end
128
+
129
+ def self.commit_msg(info_types_processed)
130
+ msg = "Added "
131
+ count = 0
132
+ types = info_types_processed #info
133
+ if types.include?(ServiceInfo.info_type)
134
+ msg << 'service '
135
+ count +=1
136
+ end
137
+ if types.include?(ComponentInfo.info_type)
138
+ msg << 'and ' if count > 0
139
+ msg << 'component'
140
+ count +=1
141
+ end
142
+ msg << 'info'
143
+ msg
144
+ end
145
+
146
+ def self.git_repo_operation
147
+ Operation::ClientModuleDir::GitRepo
148
+ end
149
+ def git_repo_operation
150
+ self.class.git_repo_operation
151
+ end
152
+
153
+ end
154
+ end
155
+ end; end