dtk-shell 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +5 -0
- data/Gemfile_dev +13 -0
- data/README.md +121 -0
- data/bin/dtk-execute +32 -0
- data/bin/dtk-run +92 -0
- data/bin/dtk-shell +31 -0
- data/dtk-shell.gemspec +50 -0
- data/lib/auxiliary.rb +61 -0
- data/lib/bundler_monkey_patch.rb +26 -0
- data/lib/client.rb +58 -0
- data/lib/command_helper.rb +33 -0
- data/lib/command_helpers/git_repo.rb +589 -0
- data/lib/command_helpers/git_repo/merge.rb +153 -0
- data/lib/command_helpers/jenkins_client.rb +106 -0
- data/lib/command_helpers/jenkins_client/config_xml.rb +288 -0
- data/lib/command_helpers/service_importer.rb +251 -0
- data/lib/command_helpers/service_link.rb +33 -0
- data/lib/command_helpers/test_module_creator.rb +69 -0
- data/lib/command_helpers/test_module_templates/dtk.model.yaml.eruby +10 -0
- data/lib/command_helpers/test_module_templates/spec_helper.rb.eruby +10 -0
- data/lib/command_helpers/test_module_templates/temp_component_spec.rb.eruby +5 -0
- data/lib/commands.rb +57 -0
- data/lib/commands/common/thor/access_control.rb +133 -0
- data/lib/commands/common/thor/action_result_handler.rb +74 -0
- data/lib/commands/common/thor/assembly_template.rb +92 -0
- data/lib/commands/common/thor/assembly_workspace.rb +1801 -0
- data/lib/commands/common/thor/base_command_helper.rb +59 -0
- data/lib/commands/common/thor/clone.rb +82 -0
- data/lib/commands/common/thor/common.rb +88 -0
- data/lib/commands/common/thor/common_base.rb +49 -0
- data/lib/commands/common/thor/create_target.rb +70 -0
- data/lib/commands/common/thor/edit.rb +255 -0
- data/lib/commands/common/thor/inventory_parser.rb +98 -0
- data/lib/commands/common/thor/list_diffs.rb +128 -0
- data/lib/commands/common/thor/module.rb +1011 -0
- data/lib/commands/common/thor/module/import.rb +210 -0
- data/lib/commands/common/thor/node.rb +53 -0
- data/lib/commands/common/thor/poller.rb +65 -0
- data/lib/commands/common/thor/pull_clone_changes.rb +28 -0
- data/lib/commands/common/thor/pull_from_remote.rb +152 -0
- data/lib/commands/common/thor/puppet_forge.rb +72 -0
- data/lib/commands/common/thor/purge_clone.rb +101 -0
- data/lib/commands/common/thor/push_clone_changes.rb +162 -0
- data/lib/commands/common/thor/push_to_remote.rb +94 -0
- data/lib/commands/common/thor/remotes.rb +71 -0
- data/lib/commands/common/thor/reparse.rb +40 -0
- data/lib/commands/common/thor/set_required_attributes.rb +46 -0
- data/lib/commands/thor/account.rb +239 -0
- data/lib/commands/thor/assembly.rb +356 -0
- data/lib/commands/thor/attribute.rb +79 -0
- data/lib/commands/thor/component.rb +70 -0
- data/lib/commands/thor/component_module.rb +501 -0
- data/lib/commands/thor/component_template.rb +174 -0
- data/lib/commands/thor/dependency.rb +34 -0
- data/lib/commands/thor/developer.rb +144 -0
- data/lib/commands/thor/dtk.rb +152 -0
- data/lib/commands/thor/library.rb +125 -0
- data/lib/commands/thor/node.rb +504 -0
- data/lib/commands/thor/node_template.rb +94 -0
- data/lib/commands/thor/project.rb +34 -0
- data/lib/commands/thor/provider.rb +233 -0
- data/lib/commands/thor/remotes.rb +49 -0
- data/lib/commands/thor/service.rb +941 -0
- data/lib/commands/thor/service_module.rb +914 -0
- data/lib/commands/thor/state_change.rb +25 -0
- data/lib/commands/thor/target.rb +250 -0
- data/lib/commands/thor/task.rb +116 -0
- data/lib/commands/thor/test_module.rb +310 -0
- data/lib/commands/thor/utils.rb +21 -0
- data/lib/commands/thor/workspace.rb +685 -0
- data/lib/config/cacert.pem +3785 -0
- data/lib/config/client.conf.header +20 -0
- data/lib/config/configuration.rb +99 -0
- data/lib/config/default.conf +16 -0
- data/lib/config/disk_cacher.rb +80 -0
- data/lib/configurator.rb +176 -0
- data/lib/context_router.rb +44 -0
- data/lib/core.rb +497 -0
- data/lib/domain/git_adapter.rb +412 -0
- data/lib/domain/git_error_handler.rb +64 -0
- data/lib/domain/response.rb +285 -0
- data/lib/domain/response/error_handler.rb +86 -0
- data/lib/dtk-shell/version.rb +20 -0
- data/lib/dtk_constants.rb +40 -0
- data/lib/dtk_error.rb +114 -0
- data/lib/dtk_logger.rb +126 -0
- data/lib/dtk_shell.rb +31 -0
- data/lib/error.rb +85 -0
- data/lib/execute.rb +29 -0
- data/lib/execute/cli_pure/cli_rerouter.rb +102 -0
- data/lib/execute/command.rb +40 -0
- data/lib/execute/command/api_call.rb +60 -0
- data/lib/execute/command/api_call/map.rb +60 -0
- data/lib/execute/command/api_call/service.rb +91 -0
- data/lib/execute/command/api_call/translation_term.rb +119 -0
- data/lib/execute/command/rest_call.rb +37 -0
- data/lib/execute/command_processor.rb +30 -0
- data/lib/execute/command_processor/rest_call.rb +59 -0
- data/lib/execute/error_usage.rb +21 -0
- data/lib/execute/execute_context.rb +86 -0
- data/lib/execute/execute_context/result_store.rb +37 -0
- data/lib/execute/script.rb +64 -0
- data/lib/execute/script/add_tenant.rb +121 -0
- data/lib/git-logs/git.log +0 -0
- data/lib/parser/adapters/option_parser.rb +70 -0
- data/lib/parser/adapters/thor.rb +555 -0
- data/lib/parser/adapters/thor/common_option_defs.rb +40 -0
- data/lib/require_first.rb +104 -0
- data/lib/search_hash.rb +44 -0
- data/lib/shell.rb +261 -0
- data/lib/shell/context.rb +1065 -0
- data/lib/shell/context_aux.rb +46 -0
- data/lib/shell/domain/active_context.rb +186 -0
- data/lib/shell/domain/context_entity.rb +89 -0
- data/lib/shell/domain/context_params.rb +223 -0
- data/lib/shell/domain/override_tasks.rb +88 -0
- data/lib/shell/domain/shadow_entity.rb +76 -0
- data/lib/shell/header_shell.rb +44 -0
- data/lib/shell/help_monkey_patch.rb +283 -0
- data/lib/shell/interactive_wizard.rb +225 -0
- data/lib/shell/message_queue.rb +63 -0
- data/lib/shell/parse_monkey_patch.rb +39 -0
- data/lib/shell/status_monitor.rb +124 -0
- data/lib/task_status.rb +83 -0
- data/lib/task_status/refresh_mode.rb +77 -0
- data/lib/task_status/snapshot_mode.rb +28 -0
- data/lib/task_status/stream_mode.rb +48 -0
- data/lib/task_status/stream_mode/element.rb +101 -0
- data/lib/task_status/stream_mode/element/format.rb +101 -0
- data/lib/task_status/stream_mode/element/hierarchical_task.rb +100 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/result.rb +72 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/result/action.rb +93 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/result/components.rb +26 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/result/node_level.rb +26 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/steps.rb +34 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/steps/action.rb +53 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/steps/components.rb +53 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/steps/node_level.rb +42 -0
- data/lib/task_status/stream_mode/element/no_results.rb +26 -0
- data/lib/task_status/stream_mode/element/render.rb +59 -0
- data/lib/task_status/stream_mode/element/stage.rb +84 -0
- data/lib/task_status/stream_mode/element/stage/render.rb +76 -0
- data/lib/task_status/stream_mode/element/task_end.rb +35 -0
- data/lib/task_status/stream_mode/element/task_start.rb +37 -0
- data/lib/util/common_util.rb +37 -0
- data/lib/util/console.rb +235 -0
- data/lib/util/dtk_puppet.rb +65 -0
- data/lib/util/module_util.rb +66 -0
- data/lib/util/os_util.rb +385 -0
- data/lib/util/permission_util.rb +31 -0
- data/lib/util/remote_dependency_util.rb +84 -0
- data/lib/util/ssh_util.rb +94 -0
- data/lib/view_processor.rb +129 -0
- data/lib/view_processor/augmented_simple_list.rb +44 -0
- data/lib/view_processor/hash_pretty_print.rb +123 -0
- data/lib/view_processor/simple_list.rb +156 -0
- data/lib/view_processor/table_print.rb +309 -0
- data/lib/violation.rb +86 -0
- data/lib/violation/attribute.rb +76 -0
- data/lib/violation/fix.rb +26 -0
- data/lib/violation/fix/result.rb +73 -0
- data/lib/violation/fix/result/error.rb +34 -0
- data/lib/violation/fix/set_attribute.rb +41 -0
- data/lib/violation/sub_classes.rb +60 -0
- data/puppet/manifests/init.pp +72 -0
- data/puppet/manifests/params.pp +16 -0
- data/puppet/r8meta.puppet.yml +35 -0
- data/puppet/templates/bash_profile.erb +2 -0
- data/puppet/templates/client.conf.erb +1 -0
- data/puppet/templates/dtkclient.erb +2 -0
- data/spec/component_module_spec.rb +34 -0
- data/spec/dependency_spec.rb +6 -0
- data/spec/dtk_shell_spec.rb +13 -0
- data/spec/dtk_spec.rb +33 -0
- data/spec/lib/spec_helper.rb +10 -0
- data/spec/lib/spec_thor.rb +108 -0
- data/spec/node_template_spec.rb +24 -0
- data/spec/project_spec.rb +6 -0
- data/spec/repo_spec.rb +7 -0
- data/spec/response_spec.rb +52 -0
- data/spec/service_module_spec.rb +38 -0
- data/spec/service_spec.rb +50 -0
- data/spec/state_change_spec.rb +7 -0
- data/spec/table_print_spec.rb +48 -0
- data/spec/target_spec.rb +57 -0
- data/spec/task_spec.rb +28 -0
- data/views/assembly/augmented_simple_list.rb +12 -0
- data/views/assembly_template/augmented_simple_list.rb +12 -0
- data/views/list_task/augmented_simple_list.rb +12 -0
- metadata +421 -0
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
# TODO-REMOVE: Check if we need this anymore
|
|
19
|
+
|
|
20
|
+
module DTK
|
|
21
|
+
module Client
|
|
22
|
+
#
|
|
23
|
+
# Class is used as puppet wrapper, at the moment it will use console comamnds, later
|
|
24
|
+
# to be replaced with direct usage of puppet code, or re-implentation of their direct calls
|
|
25
|
+
#
|
|
26
|
+
class DtkPuppet
|
|
27
|
+
|
|
28
|
+
MODULE_PATH = OsUtil.component_clone_location()
|
|
29
|
+
|
|
30
|
+
# installs puppet module from puppet forge via puppet module
|
|
31
|
+
# method will print out progress or errrors
|
|
32
|
+
#
|
|
33
|
+
# Returns: Name of directory where module is saved
|
|
34
|
+
def self.install_module(module_name)
|
|
35
|
+
output = nil
|
|
36
|
+
|
|
37
|
+
OsUtil.suspend_output do
|
|
38
|
+
output = `puppet module install #{module_name} --modulepath #{MODULE_PATH} --force --render-as json`
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# extract json from output, regex will match json in string
|
|
42
|
+
matched = output.match(/\{.+\}/)
|
|
43
|
+
|
|
44
|
+
raise DTK::Client::DtkError, "Puppet module '#{module_name}' not found." unless matched
|
|
45
|
+
|
|
46
|
+
# parse matched json
|
|
47
|
+
result = JSON.parse(matched[0])
|
|
48
|
+
|
|
49
|
+
if result['result'] == 'failure'
|
|
50
|
+
# we remove puppet specific messages
|
|
51
|
+
filtered = result['error']['multiline'].gsub(/^.*puppet module.*$\n?/,'')
|
|
52
|
+
# we strip and join multiline message
|
|
53
|
+
filtered = filtered.split(/\n/).map(&:strip).join(', ')
|
|
54
|
+
raise DTK::Client::DtkError, filtered
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# puppet uses last part of the module name, as dir for location
|
|
58
|
+
dir_name = module_name.split('-').last
|
|
59
|
+
puts "Successfully installed '#{module_name}' from puppet forge, location: '#{MODULE_PATH}/#{dir_name}'"
|
|
60
|
+
return dir_name
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
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
|
|
19
|
+
module Client
|
|
20
|
+
module ModuleUtil
|
|
21
|
+
|
|
22
|
+
NAMESPACE_SEPERATOR = ':'
|
|
23
|
+
|
|
24
|
+
def self.resolve_name(module_name, module_namespace)
|
|
25
|
+
is_invalid = module_name.nil? || module_namespace.nil? || module_name.empty? || module_namespace.empty?
|
|
26
|
+
raise DtkError, "Failed to provide module name (#{module_name}) or namespace (#{module_namespace})" if is_invalid
|
|
27
|
+
"#{module_namespace}#{NAMESPACE_SEPERATOR}#{module_name}"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.join_name(module_name, module_namespace)
|
|
31
|
+
module_namespace ? resolve_name(module_name, module_namespace) : module_name
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.module_name(module_type)
|
|
35
|
+
module_type.to_s.gsub('_',' ')
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# returns [namespace,name]; namespace can be null if cant determine it
|
|
39
|
+
def self.full_module_name_parts?(name_or_full_module_name)
|
|
40
|
+
if name_or_full_module_name.nil?
|
|
41
|
+
return [nil,nil]
|
|
42
|
+
end
|
|
43
|
+
if name_or_full_module_name =~ Regexp.new("(^.+)#{NAMESPACE_SEPERATOR}(.+$)")
|
|
44
|
+
namespace,name = [$1,$2]
|
|
45
|
+
else
|
|
46
|
+
namespace,name = [nil,name_or_full_module_name]
|
|
47
|
+
end
|
|
48
|
+
[namespace,name]
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def self.filter_module_name(name_or_full_module_name)
|
|
52
|
+
full_module_name_parts?(name_or_full_module_name).last
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def self.check_format!(module_identifier)
|
|
56
|
+
return module_identifier if module_identifier.match(/^[0-9]+$/)
|
|
57
|
+
DtkLogger.instance.debug(caller)
|
|
58
|
+
raise DtkError, "Module name should be in following format NAMESPACE#{NAMESPACE_SEPERATOR}MODULE_NAME" unless module_identifier.match(Regexp.new("^.+#{NAMESPACE_SEPERATOR}.+$"))
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def self.type_to_sym(module_type_s)
|
|
62
|
+
module_type_s.to_s.gsub!(/\_/,'-').to_sym
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
data/lib/util/os_util.rb
ADDED
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
|
3
|
+
#
|
|
4
|
+
# This file is part of the dtk project.
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
dtk_require_from_base('domain/response')
|
|
19
|
+
dtk_require_from_base('auxiliary')
|
|
20
|
+
require 'highline'
|
|
21
|
+
require 'readline'
|
|
22
|
+
|
|
23
|
+
module DTK
|
|
24
|
+
module Client
|
|
25
|
+
module OsUtil
|
|
26
|
+
|
|
27
|
+
extend Auxiliary
|
|
28
|
+
|
|
29
|
+
DTK_IDENTITY_FILE = 'dtk.pem'
|
|
30
|
+
|
|
31
|
+
class << self
|
|
32
|
+
def is_mac?
|
|
33
|
+
RUBY_PLATFORM.downcase.include?('darwin')
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def is_windows?
|
|
37
|
+
RUBY_PLATFORM =~ /mswin|mingw|cygwin/
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def is_linux?
|
|
41
|
+
RUBY_PLATFORM.downcase.include?('linux')
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def get_temp_location
|
|
45
|
+
is_windows? ? genv(:temp) : '/tmp'
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def pop_readline_history(number_of_last_commands)
|
|
49
|
+
number_of_last_commands.downto(1) do
|
|
50
|
+
Readline::HISTORY.pop
|
|
51
|
+
end
|
|
52
|
+
nil
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def get_log_location
|
|
56
|
+
return "#{dtk_local_folder}"
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def clear_screen
|
|
60
|
+
command = is_windows? ? "cls" : "clear"
|
|
61
|
+
system(command)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def dtk_home_dir
|
|
65
|
+
return "#{home_dir}"
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# This will return class object from DTK::Client namespace
|
|
69
|
+
def get_dtk_class(command_name)
|
|
70
|
+
begin
|
|
71
|
+
Object.const_get('DTK').const_get('Client').const_get(cap_form(command_name))
|
|
72
|
+
rescue Exception => e
|
|
73
|
+
return nil
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# for Windows app folder is already under OS username
|
|
78
|
+
def dtk_user_app_folder
|
|
79
|
+
if is_windows?
|
|
80
|
+
dtk_app_folder()
|
|
81
|
+
else
|
|
82
|
+
"#{dtk_app_folder}#{::DTK::Common::Aux.running_process_user()}/"
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def dtk_app_folder
|
|
87
|
+
return (is_windows? ? "#{genv(:homedrive)}#{genv(:homepath)}/dtk/" : "#{/etc/}dtk/")
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def dtk_local_folder
|
|
91
|
+
return (is_windows? ? "#{genv(:homedrive)}#{genv(:homepath)}/dtk/" : "#{home_dir}/dtk/")
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def home_dir
|
|
95
|
+
return (is_windows? ? "#{genv(:homedrive)}#{genv(:homepath)}" : "#{genv(:home)}")
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def current_dir
|
|
99
|
+
current_dir = Dir.getwd()
|
|
100
|
+
current_dir.gsub(home_dir, '~')
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def genv(name)
|
|
104
|
+
return ENV[name.to_s.upcase].gsub(/\\/,'/')
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def edit(file)
|
|
108
|
+
editor = ENV['EDITOR']
|
|
109
|
+
if is_windows?
|
|
110
|
+
raise Client::DtkError, "Environment variable EDITOR needs to be set; exit dtk-shell, set variable and log back into dtk-shell." unless editor
|
|
111
|
+
else
|
|
112
|
+
editor = 'vim' unless editor
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
system("#{editor} #{file}")
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def module_location(module_type,module_name,version=nil,opts={})
|
|
119
|
+
# compact used because module_name can be nil
|
|
120
|
+
location = module_location_parts(module_type,module_name,version,opts).compact.join('/')
|
|
121
|
+
location
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# if module location is /a/b/d/mod it returns ['/a/b/d','mod']
|
|
125
|
+
def module_location_parts(module_type,module_name,version=nil,opts={})
|
|
126
|
+
base_path = clone_base_path(opts[:assembly_module] ? :assembly_module : module_type)
|
|
127
|
+
if assembly_module = opts[:assembly_module]
|
|
128
|
+
assembly_name = opts[:assembly_module][:assembly_name]
|
|
129
|
+
base_all_types = "#{base_path}/#{assembly_name}"
|
|
130
|
+
if module_type == :all
|
|
131
|
+
[base_all_types,nil]
|
|
132
|
+
else
|
|
133
|
+
type = clone_base_path(module_type).split('/').last
|
|
134
|
+
["#{base_all_types}/#{type}", module_name]
|
|
135
|
+
end
|
|
136
|
+
else
|
|
137
|
+
# we detect if we are using full name
|
|
138
|
+
if (module_name.match(/(.*)#{ModuleUtil::NAMESPACE_SEPERATOR}(.*)/))
|
|
139
|
+
[base_path, "#{$1}", "#{$2}#{version && "-#{version}"}"]
|
|
140
|
+
else
|
|
141
|
+
[base_path, "#{module_name}#{version && "-#{version}"}"]
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def module_version_locations(module_type, module_name, version = nil, opts={})
|
|
147
|
+
base_path, namespace, name = module_location_parts(module_type, module_name, version, opts) #.first
|
|
148
|
+
namespace_path = "#{base_path}/#{namespace}"
|
|
149
|
+
module_versions = Dir.entries(namespace_path).select{|a| a.match(/^#{name}-\d{1,2}.\d{1,2}.\d{1,2}$/)}
|
|
150
|
+
module_versions.map{ |version| "#{namespace_path}/#{version}" }
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def module_clone_location(module_type)
|
|
154
|
+
case module_type.to_s
|
|
155
|
+
when "component_module"
|
|
156
|
+
return component_clone_location
|
|
157
|
+
when "service_module"
|
|
158
|
+
return service_clone_location
|
|
159
|
+
when "test_module"
|
|
160
|
+
test_clone_location
|
|
161
|
+
else
|
|
162
|
+
raise Client::DtkError, "Unexpected module_type (#{module_type}) when determining module location"
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def temp_git_remote_location()
|
|
167
|
+
File::join(dtk_local_folder, 'temp_remote_location')
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def component_clone_location()
|
|
171
|
+
clone_base_path(:component_module)
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def service_clone_location()
|
|
175
|
+
clone_base_path(:service_module)
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def test_clone_location()
|
|
179
|
+
clone_base_path(:test_module)
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def assembly_module_base_location()
|
|
183
|
+
clone_base_path(:assembly_module)
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
def backups_location()
|
|
187
|
+
path = Config[:backups_location]
|
|
188
|
+
final_path = path && path.start_with?('/') ? path : "#{dtk_local_folder}#{path}"
|
|
189
|
+
final_path.gsub(/\/$/,'')
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def clone_base_path(module_type)
|
|
193
|
+
|
|
194
|
+
path =
|
|
195
|
+
case module_type.to_sym
|
|
196
|
+
when :service_module then Config[:service_location]
|
|
197
|
+
when :component_module then Config[:module_location]
|
|
198
|
+
when :test_module then Config[:test_module_location]
|
|
199
|
+
when :assembly_module then Config[:assembly_module_base_location]
|
|
200
|
+
else raise Client::DtkError, "Unexpected module_type (#{module_type}) when determining base path"
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
final_path = path && path.start_with?('/') ? path : "#{dtk_local_folder}#{path}"
|
|
205
|
+
# remove last slash if set in configuration by mistake
|
|
206
|
+
final_path.gsub(/\/$/,'')
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
#
|
|
210
|
+
# Checks to find dtk.pem in configuration node, if not found displays tip message
|
|
211
|
+
#
|
|
212
|
+
def dtk_identity_file_location()
|
|
213
|
+
path_to_identity_file = "#{dtk_local_folder}#{DTK_IDENTITY_FILE}"
|
|
214
|
+
return path_to_identity_file if File.exists?(path_to_identity_file)
|
|
215
|
+
print("TIP: You can save your identity file as '#{path_to_identity_file}' and it will be used as default identityfile.", :yellow)
|
|
216
|
+
nil
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
private :clone_base_path
|
|
221
|
+
#
|
|
222
|
+
#
|
|
223
|
+
#
|
|
224
|
+
def local_component_module_list()
|
|
225
|
+
component_module_dir = component_clone_location()
|
|
226
|
+
|
|
227
|
+
directories = Dir.entries(component_module_dir).map do |entry|
|
|
228
|
+
next if (entry =='.' || entry == '..' || entry.index('.') == 0 || !File.directory?(entry))
|
|
229
|
+
|
|
230
|
+
Dir.entries("#{component_module_dir}/#{entry}").map do |m_entry|
|
|
231
|
+
next unless File.directory? File.join(component_module_dir,entry,m_entry)
|
|
232
|
+
next if (m_entry =='.' || m_entry == '..' || m_entry.index('.') == 0)
|
|
233
|
+
|
|
234
|
+
ModuleUtil.join_name(m_entry, entry)
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
directories.flatten.select { |d| !d.nil? }
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
# Public method will convert given string, to string with colorize output
|
|
242
|
+
#
|
|
243
|
+
# message - String to be colorized
|
|
244
|
+
# color - Symbol describing color to be used
|
|
245
|
+
#
|
|
246
|
+
# Returns String with colorize output
|
|
247
|
+
def colorize(message, color)
|
|
248
|
+
# at the moment we do not support colors in windows
|
|
249
|
+
((is_windows? || message.nil?) ? message : message.colorize(color))
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
# Public method will print to STDOUT with given color
|
|
253
|
+
#
|
|
254
|
+
# message - String to be colorize and printed
|
|
255
|
+
# color - Symbol describing the color to be used on STDOUT
|
|
256
|
+
#
|
|
257
|
+
# Void
|
|
258
|
+
def print(message, color = :white)
|
|
259
|
+
puts colorize(message, color)
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
def print_warning(message)
|
|
263
|
+
print(message, :yellow)
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
def print_deprecate_message(message)
|
|
267
|
+
print_warning(message)
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
# Public block, method will suspend STDOUT, STDERR in body of it
|
|
271
|
+
#
|
|
272
|
+
# Example
|
|
273
|
+
# suspend_output do
|
|
274
|
+
# # some calls
|
|
275
|
+
# end
|
|
276
|
+
def suspend_output
|
|
277
|
+
if is_windows?
|
|
278
|
+
retval = yield
|
|
279
|
+
else
|
|
280
|
+
orig_stderr = $stderr.clone
|
|
281
|
+
orig_stdout = $stdout.clone
|
|
282
|
+
begin
|
|
283
|
+
$stderr.reopen File.new('/dev/null', 'w')
|
|
284
|
+
$stdout.reopen File.new('/dev/null', 'w')
|
|
285
|
+
retval = yield
|
|
286
|
+
rescue Exception => e
|
|
287
|
+
$stdout.reopen orig_stdout
|
|
288
|
+
$stderr.reopen orig_stderr
|
|
289
|
+
raise e
|
|
290
|
+
ensure
|
|
291
|
+
$stdout.reopen orig_stdout
|
|
292
|
+
$stderr.reopen orig_stderr
|
|
293
|
+
end
|
|
294
|
+
end
|
|
295
|
+
retval
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
def which(cmd)
|
|
299
|
+
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
|
300
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
|
301
|
+
exts.each { |ext|
|
|
302
|
+
exe = File.join(path, "#{cmd}#{ext}")
|
|
303
|
+
return exe if File.executable? exe
|
|
304
|
+
}
|
|
305
|
+
end
|
|
306
|
+
return nil
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
def dev_reload_shell()
|
|
310
|
+
suspend_output do
|
|
311
|
+
load File.expand_path('../../lib/util/os_util.rb', File.dirname(__FILE__))
|
|
312
|
+
load File.expand_path('../../lib/util/ssh_util.rb', File.dirname(__FILE__))
|
|
313
|
+
load File.expand_path('../../lib/util/remote_dependency_util.rb', File.dirname(__FILE__))
|
|
314
|
+
load File.expand_path('../../lib/shell/help_monkey_patch.rb', File.dirname(__FILE__))
|
|
315
|
+
load File.expand_path('../../lib/shell/domain/context_entity.rb', File.dirname(__FILE__))
|
|
316
|
+
load File.expand_path('../../lib/shell/domain/active_context.rb', File.dirname(__FILE__))
|
|
317
|
+
load File.expand_path('../../lib/shell/domain/context_params.rb', File.dirname(__FILE__))
|
|
318
|
+
load File.expand_path('../../lib/shell/domain/override_tasks.rb', File.dirname(__FILE__))
|
|
319
|
+
load File.expand_path('../../lib/shell.rb', File.dirname(__FILE__))
|
|
320
|
+
load File.expand_path('../../lib/shell/context.rb', File.dirname(__FILE__))
|
|
321
|
+
load File.expand_path('../../lib/domain/git_adapter.rb', File.dirname(__FILE__))
|
|
322
|
+
load File.expand_path('../../lib/command_helpers/git_repo.rb', File.dirname(__FILE__))
|
|
323
|
+
load File.expand_path('../../lib/command_helpers/service_importer.rb', File.dirname(__FILE__))
|
|
324
|
+
load File.expand_path('../../lib/view_processor/table_print.rb', File.dirname(__FILE__))
|
|
325
|
+
load File.expand_path('../../lib/shell/interactive_wizard.rb', File.dirname(__FILE__))
|
|
326
|
+
paths = []
|
|
327
|
+
paths << File.expand_path('../../lib/commands/thor/*.rb', File.dirname(__FILE__))
|
|
328
|
+
paths << File.expand_path('../../lib/commands/common/thor/*.rb', File.dirname(__FILE__))
|
|
329
|
+
|
|
330
|
+
paths.each do |path|
|
|
331
|
+
Dir[path].each do |thor_class_file|
|
|
332
|
+
load thor_class_file
|
|
333
|
+
end
|
|
334
|
+
end
|
|
335
|
+
end
|
|
336
|
+
end
|
|
337
|
+
|
|
338
|
+
def put_warning(prefix, text, color)
|
|
339
|
+
width = HighLine::SystemExtensions.terminal_size[0] - (prefix.length + 1)
|
|
340
|
+
text_split = wrap(text, width)
|
|
341
|
+
Kernel.print colorize(prefix, color), " "
|
|
342
|
+
text_split.lines.each_with_index do |line, index|
|
|
343
|
+
line = " "*(prefix.length + 1) + line unless index == 0
|
|
344
|
+
puts line
|
|
345
|
+
end
|
|
346
|
+
end
|
|
347
|
+
|
|
348
|
+
def wrap(text, wrap_at)
|
|
349
|
+
wrapped = [ ]
|
|
350
|
+
text.each_line do |line|
|
|
351
|
+
# take into account color escape sequences when wrapping
|
|
352
|
+
wrap_at = wrap_at + (line.length - actual_length(line))
|
|
353
|
+
while line =~ /([^\n]{#{wrap_at + 1},})/
|
|
354
|
+
search = $1.dup
|
|
355
|
+
replace = $1.dup
|
|
356
|
+
if index = replace.rindex(" ", wrap_at)
|
|
357
|
+
replace[index, 1] = "\n"
|
|
358
|
+
replace.sub!(/\n[ \t]+/, "\n")
|
|
359
|
+
line.sub!(search, replace)
|
|
360
|
+
else
|
|
361
|
+
line[$~.begin(1) + wrap_at, 0] = "\n"
|
|
362
|
+
end
|
|
363
|
+
end
|
|
364
|
+
wrapped << line
|
|
365
|
+
end
|
|
366
|
+
return wrapped.join
|
|
367
|
+
end
|
|
368
|
+
|
|
369
|
+
def actual_length( string_with_escapes )
|
|
370
|
+
string_with_escapes.to_s.gsub(/\e\[\d{1,2}m/, "").length
|
|
371
|
+
end
|
|
372
|
+
|
|
373
|
+
def remove_html_tags(string_with_tags)
|
|
374
|
+
string_with_tags.gsub(/<\/?[^>]+>/, '')
|
|
375
|
+
end
|
|
376
|
+
|
|
377
|
+
private
|
|
378
|
+
|
|
379
|
+
def seperator
|
|
380
|
+
return (is_windows? ? "\\" : "/")
|
|
381
|
+
end
|
|
382
|
+
end
|
|
383
|
+
end
|
|
384
|
+
end
|
|
385
|
+
end
|