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,84 @@
|
|
|
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 TaskStatus::StreamMode
|
|
19
|
+
class Element
|
|
20
|
+
class Stage < self
|
|
21
|
+
require File.expand_path('stage/render', File.dirname(__FILE__))
|
|
22
|
+
include Render::Mixin
|
|
23
|
+
|
|
24
|
+
def initialize(response_element, opts = {})
|
|
25
|
+
super
|
|
26
|
+
@just_render = opts[:just_render]
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# opts has
|
|
30
|
+
# :wait - amount to wait if get no results (required)
|
|
31
|
+
def self.get_and_render_stages(task_status_handle, opts = {})
|
|
32
|
+
unless wait = opts[:wait]
|
|
33
|
+
raise DtkError::Client, "opts[:wait] must be set"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
cursor = Cursor.new
|
|
37
|
+
until cursor.task_end? do
|
|
38
|
+
elements = get_single_stage(task_status_handle, cursor.stage, {:wait_for => cursor.wait_for}.merge(opts))
|
|
39
|
+
if no_results_yet?(elements)
|
|
40
|
+
sleep wait
|
|
41
|
+
next
|
|
42
|
+
end
|
|
43
|
+
render_elements(elements)
|
|
44
|
+
cursor.advance!(task_end?(elements))
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
class Cursor
|
|
49
|
+
def initialize
|
|
50
|
+
@stage = 1
|
|
51
|
+
@wait_for = :start
|
|
52
|
+
@task_end = false
|
|
53
|
+
end
|
|
54
|
+
attr_reader :stage, :wait_for
|
|
55
|
+
def task_end?
|
|
56
|
+
@task_end
|
|
57
|
+
end
|
|
58
|
+
def advance!(task_end)
|
|
59
|
+
unless @task_end = task_end
|
|
60
|
+
if @wait_for == :start
|
|
61
|
+
@wait_for = :end
|
|
62
|
+
else
|
|
63
|
+
@stage += 1
|
|
64
|
+
@wait_for = :start
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def self.get_single_stage(task_status_handle, stage_num, opts = {})
|
|
71
|
+
get_stages(task_status_handle, stage_num, stage_num, opts)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def self.get_stages(task_status_handle, start_stage_num, end_stage_num, opts = {})
|
|
75
|
+
opts_get = {
|
|
76
|
+
:start_index => start_stage_num,
|
|
77
|
+
:end_index => end_stage_num
|
|
78
|
+
}.merge(opts)
|
|
79
|
+
get_task_status_elements(task_status_handle, :stage, opts_get)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end; end
|
|
@@ -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
|
+
class DTK::Client::TaskStatus::StreamMode::Element::Stage
|
|
19
|
+
module Render
|
|
20
|
+
module Mixin
|
|
21
|
+
def render
|
|
22
|
+
render_start unless @just_render and @just_render != :start
|
|
23
|
+
render_end unless @just_render and @just_render != :end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def render_start
|
|
29
|
+
if @ignore_stage_level_info
|
|
30
|
+
render_stage_steps field?(:subtasks)
|
|
31
|
+
render_start_time field?(:started_at)
|
|
32
|
+
else
|
|
33
|
+
render_border
|
|
34
|
+
render_line line__stage_heading?
|
|
35
|
+
render_start_time field?(:started_at)
|
|
36
|
+
render_stage_steps field?(:subtasks)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def render_end
|
|
41
|
+
render_line line__status
|
|
42
|
+
render_duration_line
|
|
43
|
+
render_stage_results field?(:subtasks)
|
|
44
|
+
unless @ignore_stage_level_info
|
|
45
|
+
render_border
|
|
46
|
+
render_empty_line
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def line__stage_heading?
|
|
51
|
+
stage_num = field?(:position)
|
|
52
|
+
stage_name = stage_name?
|
|
53
|
+
|
|
54
|
+
unless stage_num.nil? and stage_name.nil?
|
|
55
|
+
msg = 'STAGE'
|
|
56
|
+
if stage_num = field?(:position)
|
|
57
|
+
msg << " #{stage_num.to_s}"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
if stage_name = stage_name?
|
|
61
|
+
msg << ": #{stage_name}"
|
|
62
|
+
end
|
|
63
|
+
msg
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def line__status
|
|
68
|
+
"STATUS: #{field?(:status) || 'UNKNOWN'}"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def stage_name?
|
|
72
|
+
field?(:display_name)
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
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 TaskStatus::StreamMode
|
|
19
|
+
class Element
|
|
20
|
+
class TaskEnd < self
|
|
21
|
+
def task_end?()
|
|
22
|
+
true
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def render
|
|
26
|
+
return if @ignore_stage_level_info
|
|
27
|
+
msg = "end: '#{field?(:display_name) || 'Workflow'}'"
|
|
28
|
+
if duration = formatted_duration?
|
|
29
|
+
msg << " (total duration: #{duration})"
|
|
30
|
+
end
|
|
31
|
+
render_line msg, :bracket => true
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end; end
|
|
@@ -0,0 +1,37 @@
|
|
|
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 TaskStatus::StreamMode
|
|
19
|
+
class Element
|
|
20
|
+
class TaskStart < self
|
|
21
|
+
def self.get(task_status_handle, opts = {})
|
|
22
|
+
opts_get = {
|
|
23
|
+
:start_index => 0,
|
|
24
|
+
:end_index => 0
|
|
25
|
+
}.merge(opts)
|
|
26
|
+
get_task_status_elements(task_status_handle, :task_start, opts_get)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def render
|
|
30
|
+
return if @ignore_stage_level_info
|
|
31
|
+
msg = "start '#{field?(:display_name) || 'Workflow'}'"
|
|
32
|
+
render_line msg, :bracket => true, :started_at => field?(:started_at)
|
|
33
|
+
render_empty_lines 2
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end; end
|
|
@@ -0,0 +1,37 @@
|
|
|
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 CommonUtil
|
|
21
|
+
class << self
|
|
22
|
+
def substract_array_once(array1, array2, substract_from_back = false)
|
|
23
|
+
# we substract from reverse if flag set
|
|
24
|
+
array1 = array1.reverse if substract_from_back
|
|
25
|
+
|
|
26
|
+
array2.each do |element|
|
|
27
|
+
if index = array1.index(element)
|
|
28
|
+
array1.delete_at(index)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
substract_from_back ? array1.reverse : array1
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
data/lib/util/console.rb
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
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
|
+
require 'readline'
|
|
19
|
+
require 'shellwords'
|
|
20
|
+
|
|
21
|
+
dtk_require("os_util")
|
|
22
|
+
dtk_require_common_commands('../common/thor/push_clone_changes')
|
|
23
|
+
dtk_require_common_commands('../common/thor/reparse')
|
|
24
|
+
dtk_require_from_base("command_helper")
|
|
25
|
+
|
|
26
|
+
module DTK::Client
|
|
27
|
+
module Console
|
|
28
|
+
class << self
|
|
29
|
+
include PushCloneChangesMixin
|
|
30
|
+
include ReparseMixin
|
|
31
|
+
include CommandBase
|
|
32
|
+
include CommandHelperMixin
|
|
33
|
+
|
|
34
|
+
#
|
|
35
|
+
# Display confirmation prompt and repeat message until expected answer is given
|
|
36
|
+
#
|
|
37
|
+
def confirmation_prompt(message, add_options=true)
|
|
38
|
+
# used to disable skip with ctrl+c
|
|
39
|
+
trap("INT", "SIG_IGN")
|
|
40
|
+
message += " (yes|no)" if add_options
|
|
41
|
+
|
|
42
|
+
while line = Readline.readline("#{message}: ", true)
|
|
43
|
+
if (line.eql?("yes") || line.eql?("y"))
|
|
44
|
+
trap("INT",false)
|
|
45
|
+
return true
|
|
46
|
+
elsif (line.eql?("no") || line.eql?("n"))
|
|
47
|
+
trap("INT",false)
|
|
48
|
+
return false
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
#
|
|
54
|
+
# Display confirmation prompt and repeat message until expected answer is given
|
|
55
|
+
#
|
|
56
|
+
def confirmation_prompt_simple(message, add_options=true)
|
|
57
|
+
# used to disable skip with ctrl+c
|
|
58
|
+
trap("INT", "SIG_IGN")
|
|
59
|
+
message += " (Y/n)" if add_options
|
|
60
|
+
|
|
61
|
+
while line = Readline.readline("#{message}: ", true)
|
|
62
|
+
if (line.downcase.eql?("yes") || line.downcase.eql?("y") || line.empty?)
|
|
63
|
+
trap("INT",false)
|
|
64
|
+
return true
|
|
65
|
+
elsif (line.downcase.eql?("no") || line.downcase.eql?("n"))
|
|
66
|
+
trap("INT",false)
|
|
67
|
+
return false
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
#
|
|
73
|
+
# Display confirmation prompt and repeat message until expected answer is given
|
|
74
|
+
# options should be sent as array ['all', 'none']
|
|
75
|
+
def confirmation_prompt_additional_options(message, options = [])
|
|
76
|
+
raise DTK::Client::DtkValidationError, "Options should be sent as array: ['all', 'none']" unless options.is_a?(Array)
|
|
77
|
+
|
|
78
|
+
# used to disable skip with ctrl+c
|
|
79
|
+
trap("INT", "SIG_IGN")
|
|
80
|
+
message += " (yes/no#{options.empty? ? '' : ('/' + options.join('/'))})"
|
|
81
|
+
|
|
82
|
+
while line = Readline.readline("#{message}: ", true)
|
|
83
|
+
if line.eql?("yes") || line.eql?("y")
|
|
84
|
+
trap("INT",false)
|
|
85
|
+
return true
|
|
86
|
+
elsif line.eql?("no") || line.eql?("n")
|
|
87
|
+
trap("INT",false)
|
|
88
|
+
return false
|
|
89
|
+
elsif options.include?(line)
|
|
90
|
+
trap("INT",false)
|
|
91
|
+
return line
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# multiple choice
|
|
97
|
+
# e.g.
|
|
98
|
+
# Select version to delete:
|
|
99
|
+
# 1. base
|
|
100
|
+
# 2. 0.0.1
|
|
101
|
+
# 3. 0.0.2
|
|
102
|
+
# 4. all
|
|
103
|
+
# > 2
|
|
104
|
+
def confirmation_prompt_multiple_choice(message, opts_array)
|
|
105
|
+
indexes = opts_array.map{ |opt| "#{opts_array.index(opt)+1}" }
|
|
106
|
+
|
|
107
|
+
trap("INT", "SIG_IGN")
|
|
108
|
+
|
|
109
|
+
message << "\n"
|
|
110
|
+
opts_array.each {|opt| message << "#{opts_array.index(opt)+1}. #{opt}\n" }
|
|
111
|
+
message << "> "
|
|
112
|
+
|
|
113
|
+
while line = Readline.readline("#{message}", true)
|
|
114
|
+
if indexes.include?(line)
|
|
115
|
+
trap("INT",false)
|
|
116
|
+
return opts_array[line.to_i-1]
|
|
117
|
+
elsif line.eql?('exit')
|
|
118
|
+
return nil
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
# Loading output used to display waiting status
|
|
124
|
+
def wait_animation(message, time_seconds)
|
|
125
|
+
print message
|
|
126
|
+
print " [ ]"
|
|
127
|
+
STDOUT.flush
|
|
128
|
+
time_seconds.downto(1) do
|
|
129
|
+
1.upto(4) do |i|
|
|
130
|
+
next_output = "\b\b\b\b\b\b\b"
|
|
131
|
+
case
|
|
132
|
+
when i % 4 == 0
|
|
133
|
+
next_output += "[ = ]"
|
|
134
|
+
when i % 3 == 0
|
|
135
|
+
next_output += "[ = ]"
|
|
136
|
+
when i % 2 == 0
|
|
137
|
+
next_output += "[ = ]"
|
|
138
|
+
else
|
|
139
|
+
next_output += "[ = ]"
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
print next_output
|
|
143
|
+
STDOUT.flush
|
|
144
|
+
sleep(0.25)
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
# remove loading animation
|
|
148
|
+
print "\b\b\b\b\b\b\bRefreshing..."
|
|
149
|
+
STDOUT.flush
|
|
150
|
+
puts
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
##
|
|
155
|
+
# Method that will execute until interupted as unix like shell. As input takes
|
|
156
|
+
# path to desire directory from where unix shell can execute normaly.
|
|
157
|
+
#
|
|
158
|
+
def unix_shell(path,module_id,module_type,version=nil)
|
|
159
|
+
|
|
160
|
+
dtk_shell_ac_proc = Readline.completion_proc
|
|
161
|
+
dtk_shell_ac_append_char = Readline.completion_append_character
|
|
162
|
+
|
|
163
|
+
if OsUtil.is_windows?
|
|
164
|
+
puts "[NOTICE] Shell interaction is currenly not supported on Windows."
|
|
165
|
+
return
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
begin
|
|
169
|
+
# we need to change path like this since system call 'cd' is not supported
|
|
170
|
+
initial_dir = Dir.pwd
|
|
171
|
+
Dir.chdir(path)
|
|
172
|
+
puts "[NOTICE] You are switching to unix-shell, to path #{path}"
|
|
173
|
+
|
|
174
|
+
# prompt = DTK::Client::OsUtil.colorize("$dtk:unix-shell ", :yellow)
|
|
175
|
+
prompt = DTK::Client::OsUtil.colorize("$:", :yellow)
|
|
176
|
+
|
|
177
|
+
Readline.completion_append_character = ""
|
|
178
|
+
Readline.completion_proc = Proc.new do |str|
|
|
179
|
+
Dir[str+'*'].grep(/^#{Regexp.escape(str)}/)
|
|
180
|
+
end
|
|
181
|
+
while line = Readline.readline("#{prompt}#{OsUtil.current_dir}>", true)
|
|
182
|
+
begin
|
|
183
|
+
line = line.chomp()
|
|
184
|
+
break if line.eql?('exit')
|
|
185
|
+
# since we are not able to support cd command due to ruby specific restrictions
|
|
186
|
+
# we will be using chdir to this.
|
|
187
|
+
if (line.match(/^cd /))
|
|
188
|
+
# remove cd part of command
|
|
189
|
+
line = line.gsub(/^cd /,'')
|
|
190
|
+
# Get path
|
|
191
|
+
path = line.match(/^\//) ? line : "#{Dir.getwd()}/#{line}"
|
|
192
|
+
# If filepat* with '*' at the end, match first directory and go in it, else try to change original input
|
|
193
|
+
if path.match(/\*$/)
|
|
194
|
+
dirs = Dir[path].select{|file| File.directory?(file)}
|
|
195
|
+
unless dirs.empty?
|
|
196
|
+
Dir.chdir(dirs.first)
|
|
197
|
+
next
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
# Change directory
|
|
201
|
+
Dir.chdir(path)
|
|
202
|
+
elsif line.match(/^dtk-push-changes/)
|
|
203
|
+
args = Shellwords.split(line)
|
|
204
|
+
commit_msg = nil
|
|
205
|
+
|
|
206
|
+
unless args.size==1
|
|
207
|
+
raise DTK::Client::DtkValidationError, "To push changes to server use 'dtk-push-changes [-m COMMIT-MSG]'" unless (args[1]=="-m" && args.size==3)
|
|
208
|
+
commit_msg = args.last
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
reparse_aux(path)
|
|
212
|
+
push_clone_changes_aux(module_type, module_id, version, commit_msg)
|
|
213
|
+
else
|
|
214
|
+
# we are sending stderr to stdout
|
|
215
|
+
system("#{line} 2>&1")
|
|
216
|
+
end
|
|
217
|
+
rescue Exception => e
|
|
218
|
+
DtkLogger.instance.error_pp(e.message, e.backtrace)
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
rescue Interrupt
|
|
222
|
+
puts ""
|
|
223
|
+
# do nothing else
|
|
224
|
+
ensure
|
|
225
|
+
Dir.chdir(initial_dir)
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
Readline.completion_append_character = dtk_shell_ac_append_char unless dtk_shell_ac_append_char.nil?
|
|
229
|
+
Readline.completion_proc = dtk_shell_ac_proc unless dtk_shell_ac_proc.nil?
|
|
230
|
+
puts "[NOTICE] You are leaving unix-shell."
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
end
|
|
234
|
+
end
|
|
235
|
+
end
|