dtk-client 0.9.1 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/Gemfile +1 -3
- data/README.md +2 -121
- data/Rakefile +44 -0
- data/bin/dtk +10 -88
- data/dtk-client.gemspec +21 -44
- data/examples/simple/dtk.module.yaml +32 -0
- data/{lib/git-logs/git.log → examples/simple/test/README.md} +0 -0
- data/examples/spark/dtk.module.yaml +120 -0
- data/examples/with_repo_content/deploy/puppet/manifests/hostname.pp +54 -0
- data/examples/with_repo_content/dtk.module.yaml +49 -0
- data/examples/with_repo_content/test/README.txt +0 -0
- data/features/dtk.feature +8 -0
- data/features/step_definitions/dtk_steps.rb +6 -0
- data/features/support/env.rb +15 -0
- data/lib/cli/command/mixin.rb +101 -0
- data/lib/cli/command/module/clone.rb +42 -0
- data/lib/cli/command/module/install.rb +52 -0
- data/lib/cli/command/module/list.rb +31 -0
- data/lib/cli/command/module/list_assemblies.rb +39 -0
- data/lib/cli/command/module/push.rb +34 -0
- data/lib/cli/command/module/uninstall.rb +46 -0
- data/lib/cli/command/module.rb +33 -0
- data/lib/cli/command/options.rb +33 -0
- data/lib/cli/command/service/cancel_task.rb +33 -0
- data/lib/cli/command/service/converge.rb +37 -0
- data/lib/{parser/adapters/thor/common_option_defs.rb → cli/command/service/create_workspace.rb} +13 -17
- data/lib/cli/command/service/destroy.rb +47 -0
- data/lib/cli/command/service/edit.rb +47 -0
- data/lib/cli/command/service/exec.rb +42 -0
- data/lib/cli/command/service/exec_sync.rb +53 -0
- data/lib/cli/command/service/list.rb +30 -0
- data/lib/cli/command/service/list_actions.rb +39 -0
- data/lib/cli/command/service/list_attributes.rb +44 -0
- data/lib/cli/command/service/list_component_links.rb +33 -0
- data/lib/cli/command/service/list_components.rb +39 -0
- data/lib/cli/command/service/list_dependent_modules.rb +33 -0
- data/lib/cli/command/service/list_nodes.rb +33 -0
- data/lib/cli/command/service/list_violations.rb +33 -0
- data/lib/cli/command/service/pull.rb +32 -0
- data/lib/cli/command/service/push.rb +37 -0
- data/lib/{shell/parse_monkey_patch.rb → cli/command/service/set_default_target.rb} +9 -17
- data/lib/cli/command/service/set_required_attributes.rb +32 -0
- data/lib/cli/command/service/ssh.rb +42 -0
- data/lib/cli/command/service/stage.rb +55 -0
- data/lib/cli/command/service/start.rb +33 -0
- data/lib/{shell/context_aux.rb → cli/command/service/stop.rb} +10 -23
- data/lib/cli/command/service/task_status.rb +39 -0
- data/lib/cli/command/service.rb +55 -0
- data/lib/{commands.rb → cli/command/subcommand.rb} +22 -25
- data/lib/{bundler_monkey_patch.rb → cli/command/token/arg.rb} +6 -6
- data/lib/cli/command/token/class_mixin.rb +96 -0
- data/lib/cli/command/token/flag.rb +42 -0
- data/lib/{execute/command/rest_call.rb → cli/command/token/mixin.rb} +23 -14
- data/lib/cli/command/token/switch.rb +35 -0
- data/lib/cli/command/token.rb +76 -0
- data/lib/cli/command.rb +46 -0
- data/lib/cli/context/attributes.rb +50 -0
- data/lib/cli/context/type/module.rb +34 -0
- data/lib/{commands/thor/state_change.rb → cli/context/type/service.rb} +11 -5
- data/lib/cli/context/type/top.rb +32 -0
- data/lib/cli/context/type.rb +42 -0
- data/lib/cli/context.rb +174 -0
- data/lib/cli/directory_parser/file_system.rb +105 -0
- data/lib/{execute/command.rb → cli/directory_parser.rb} +14 -17
- data/lib/{execute.rb → cli/file_obj.rb} +13 -9
- data/lib/cli/processor/plugin/gli.rb +70 -0
- data/lib/cli/processor.rb +60 -0
- data/lib/cli/runner/dtkn_access.rb +75 -0
- data/lib/cli/runner.rb +58 -0
- data/lib/cli/version.rb +8 -0
- data/lib/{config → client/config}/cacert.pem +0 -0
- data/lib/client/config/default.conf +20 -0
- data/lib/client/config.rb +106 -0
- data/lib/client/configurator.rb +182 -0
- data/lib/client/conn.rb +197 -0
- data/lib/client/content_generator.rb +127 -0
- data/lib/client/error/subclasses.rb +105 -0
- data/lib/client/error.rb +98 -0
- data/lib/client/git_repo/adapter/git_gem/error_handler.rb +70 -0
- data/lib/client/git_repo/adapter/git_gem.rb +179 -0
- data/lib/client/git_repo.rb +122 -0
- data/lib/client/logger.rb +136 -0
- data/lib/client/operation/account.rb +66 -0
- data/lib/client/operation/client_module_dir/git_repo.rb +286 -0
- data/lib/client/operation/client_module_dir.rb +138 -0
- data/lib/client/operation/module/clone_module.rb +52 -0
- data/lib/client/operation/module/install/common_module.rb +58 -0
- data/lib/client/operation/module/install/external_module.rb +122 -0
- data/lib/client/operation/module/install.rb +91 -0
- data/lib/client/operation/module/install_from_catalog.rb +76 -0
- data/lib/client/operation/module/list.rb +34 -0
- data/lib/client/operation/module/list_assemblies.rb +35 -0
- data/lib/client/operation/module/push.rb +62 -0
- data/lib/client/operation/module/uninstall.rb +44 -0
- data/lib/client/operation/module.rb +58 -0
- data/lib/{commands/common/thor/reparse.rb → client/operation/module_service_common.rb} +27 -16
- data/lib/client/operation/service/cancel_task.rb +29 -0
- data/lib/client/operation/service/commit_and_push.rb +128 -0
- data/lib/client/operation/service/converge.rb +50 -0
- data/lib/{util/common_util.rb → client/operation/service/create_workspace.rb} +13 -13
- data/lib/client/operation/service/destroy.rb +42 -0
- data/lib/client/operation/service/edit.rb +54 -0
- data/lib/client/operation/service/exec.rb +73 -0
- data/lib/client/operation/service/list.rb +32 -0
- data/lib/client/operation/service/list_actions.rb +34 -0
- data/lib/{commands/thor/dependency.rb → client/operation/service/list_attributes.rb} +16 -12
- data/lib/client/operation/service/list_component_links.rb +29 -0
- data/lib/{commands/common/thor/pull_clone_changes.rb → client/operation/service/list_components.rb} +13 -7
- data/lib/client/operation/service/list_dependent_modules.rb +29 -0
- data/lib/client/operation/service/list_nodes.rb +29 -0
- data/lib/{commands/thor/project.rb → client/operation/service/list_violations.rb} +8 -13
- data/lib/client/operation/service/pull.rb +37 -0
- data/lib/client/operation/service/set_default_target.rb +31 -0
- data/lib/client/operation/service/set_required_attributes.rb +41 -0
- data/lib/client/operation/service/ssh.rb +118 -0
- data/lib/client/operation/service/stage.rb +54 -0
- data/lib/client/operation/service/start.rb +29 -0
- data/lib/client/operation/service/stop.rb +30 -0
- data/lib/{task_status → client/operation/service/task_status}/refresh_mode.rb +15 -25
- data/lib/{task_status → client/operation/service/task_status}/snapshot_mode.rb +4 -5
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/format.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/result/action.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/result/components.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/result/node_level.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/result.rb +4 -4
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/steps/action.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/steps/components.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/steps/node_level.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/steps.rb +4 -4
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task.rb +3 -3
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/no_results.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/render.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/stage/render.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/stage.rb +3 -3
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/task_end.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/task_start.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element.rb +13 -13
- data/lib/{task_status → client/operation/service/task_status}/stream_mode.rb +5 -9
- data/lib/client/operation/service/task_status.rb +77 -0
- data/lib/client/operation/service.rb +54 -0
- data/lib/client/operation.rb +67 -0
- data/lib/client/operation_args.rb +40 -0
- data/lib/{execute/execute_context/result_store.rb → client/render/view/simple.rb} +15 -14
- data/lib/client/render/view/table/processor.rb +248 -0
- data/lib/client/render/view/table.rb +75 -0
- data/lib/client/render.rb +113 -0
- data/lib/client/response/error_handler.rb +97 -0
- data/lib/client/response/render_helper.rb +78 -0
- data/lib/client/response/subclasses.rb +62 -0
- data/lib/client/response.rb +83 -0
- data/lib/client/session.rb +62 -0
- data/lib/client/util/auxiliary.rb +34 -0
- data/lib/client/util/console.rb +81 -0
- data/lib/client/util/disk_cacher.rb +66 -0
- data/lib/client/util/dtk_path.rb +28 -0
- data/lib/{search_hash.rb → client/util/hash_with_optional_keys.rb} +29 -21
- data/lib/client/util/interactive_wizard.rb +84 -0
- data/lib/client/util/module_ref.rb +92 -0
- data/lib/client/util/os_util/print.rb +121 -0
- data/lib/client/util/os_util.rb +122 -0
- data/lib/{commands/thor/utils.rb → client/util/post_body.rb} +1 -1
- data/lib/{execute/error_usage.rb → client/util/query_string_hash.rb} +2 -2
- data/lib/client/util/remote_dependency.rb +67 -0
- data/lib/client/util/ssh_util.rb +89 -0
- data/lib/client/util/validation.rb +28 -0
- data/lib/client/util.rb +18 -0
- data/lib/{util/permission_util.rb → dtk_cli.rb} +10 -9
- data/lib/dtk_client.rb +18 -14
- data/test/default_test.rb +14 -0
- data/test/test_helper.rb +9 -0
- metadata +196 -307
- data/Gemfile_dev +0 -13
- data/bin/dtk-execute +0 -32
- data/bin/dtk-shell +0 -31
- data/lib/auxiliary.rb +0 -61
- data/lib/client.rb +0 -58
- data/lib/command_helper.rb +0 -33
- data/lib/command_helpers/git_repo/merge.rb +0 -153
- data/lib/command_helpers/git_repo.rb +0 -589
- data/lib/command_helpers/jenkins_client/config_xml.rb +0 -288
- data/lib/command_helpers/jenkins_client.rb +0 -106
- data/lib/command_helpers/service_importer.rb +0 -251
- data/lib/command_helpers/service_link.rb +0 -33
- data/lib/command_helpers/test_module_creator.rb +0 -69
- data/lib/command_helpers/test_module_templates/dtk.model.yaml.eruby +0 -10
- data/lib/command_helpers/test_module_templates/spec_helper.rb.eruby +0 -10
- data/lib/command_helpers/test_module_templates/temp_component_spec.rb.eruby +0 -5
- data/lib/commands/common/thor/access_control.rb +0 -133
- data/lib/commands/common/thor/action_result_handler.rb +0 -74
- data/lib/commands/common/thor/assembly_template.rb +0 -92
- data/lib/commands/common/thor/assembly_workspace.rb +0 -1638
- data/lib/commands/common/thor/base_command_helper.rb +0 -59
- data/lib/commands/common/thor/clone.rb +0 -82
- data/lib/commands/common/thor/common.rb +0 -88
- data/lib/commands/common/thor/common_base.rb +0 -49
- data/lib/commands/common/thor/create_target.rb +0 -70
- data/lib/commands/common/thor/edit.rb +0 -255
- data/lib/commands/common/thor/inventory_parser.rb +0 -98
- data/lib/commands/common/thor/list_diffs.rb +0 -128
- data/lib/commands/common/thor/module/import.rb +0 -215
- data/lib/commands/common/thor/module.rb +0 -1011
- data/lib/commands/common/thor/node.rb +0 -53
- data/lib/commands/common/thor/poller.rb +0 -65
- data/lib/commands/common/thor/pull_from_remote.rb +0 -152
- data/lib/commands/common/thor/puppet_forge.rb +0 -72
- data/lib/commands/common/thor/purge_clone.rb +0 -101
- data/lib/commands/common/thor/push_clone_changes.rb +0 -162
- data/lib/commands/common/thor/push_to_remote.rb +0 -94
- data/lib/commands/common/thor/remotes.rb +0 -71
- data/lib/commands/common/thor/set_required_attributes.rb +0 -46
- data/lib/commands/thor/account.rb +0 -239
- data/lib/commands/thor/assembly.rb +0 -361
- data/lib/commands/thor/attribute.rb +0 -79
- data/lib/commands/thor/component.rb +0 -70
- data/lib/commands/thor/component_module.rb +0 -501
- data/lib/commands/thor/component_template.rb +0 -174
- data/lib/commands/thor/developer.rb +0 -144
- data/lib/commands/thor/dtk.rb +0 -152
- data/lib/commands/thor/library.rb +0 -125
- data/lib/commands/thor/node.rb +0 -504
- data/lib/commands/thor/node_group.rb +0 -203
- data/lib/commands/thor/node_template.rb +0 -94
- data/lib/commands/thor/provider.rb +0 -233
- data/lib/commands/thor/remotes.rb +0 -49
- data/lib/commands/thor/service.rb +0 -932
- data/lib/commands/thor/service_module.rb +0 -900
- data/lib/commands/thor/target.rb +0 -250
- data/lib/commands/thor/task.rb +0 -116
- data/lib/commands/thor/test_module.rb +0 -310
- data/lib/commands/thor/workspace.rb +0 -698
- data/lib/config/client.conf.header +0 -20
- data/lib/config/configuration.rb +0 -99
- data/lib/config/default.conf +0 -16
- data/lib/config/disk_cacher.rb +0 -80
- data/lib/configurator.rb +0 -176
- data/lib/context_router.rb +0 -44
- data/lib/core.rb +0 -489
- data/lib/domain/git_adapter.rb +0 -412
- data/lib/domain/git_error_handler.rb +0 -64
- data/lib/domain/response/error_handler.rb +0 -86
- data/lib/domain/response.rb +0 -285
- data/lib/dtk-client/version.rb +0 -20
- data/lib/dtk_constants.rb +0 -40
- data/lib/dtk_error.rb +0 -114
- data/lib/dtk_logger.rb +0 -113
- data/lib/error.rb +0 -85
- data/lib/execute/cli_pure/cli_rerouter.rb +0 -102
- data/lib/execute/command/api_call/map.rb +0 -60
- data/lib/execute/command/api_call/service.rb +0 -91
- data/lib/execute/command/api_call/translation_term.rb +0 -119
- data/lib/execute/command/api_call.rb +0 -60
- data/lib/execute/command_processor/rest_call.rb +0 -59
- data/lib/execute/command_processor.rb +0 -30
- data/lib/execute/execute_context.rb +0 -86
- data/lib/execute/script/add_tenant.rb +0 -121
- data/lib/execute/script.rb +0 -64
- data/lib/parser/adapters/option_parser.rb +0 -70
- data/lib/parser/adapters/thor.rb +0 -555
- data/lib/require_first.rb +0 -104
- data/lib/shell/context.rb +0 -1064
- data/lib/shell/domain/active_context.rb +0 -186
- data/lib/shell/domain/context_entity.rb +0 -89
- data/lib/shell/domain/context_params.rb +0 -223
- data/lib/shell/domain/override_tasks.rb +0 -88
- data/lib/shell/domain/shadow_entity.rb +0 -76
- data/lib/shell/header_shell.rb +0 -44
- data/lib/shell/help_monkey_patch.rb +0 -283
- data/lib/shell/interactive_wizard.rb +0 -256
- data/lib/shell/message_queue.rb +0 -63
- data/lib/shell/status_monitor.rb +0 -124
- data/lib/shell.rb +0 -261
- data/lib/task_status.rb +0 -83
- data/lib/util/console.rb +0 -235
- data/lib/util/dtk_puppet.rb +0 -65
- data/lib/util/module_util.rb +0 -66
- data/lib/util/os_util.rb +0 -385
- data/lib/util/remote_dependency_util.rb +0 -84
- data/lib/util/ssh_util.rb +0 -94
- data/lib/view_processor/augmented_simple_list.rb +0 -44
- data/lib/view_processor/hash_pretty_print.rb +0 -123
- data/lib/view_processor/simple_list.rb +0 -156
- data/lib/view_processor/table_print.rb +0 -309
- data/lib/view_processor.rb +0 -129
- data/puppet/manifests/init.pp +0 -72
- data/puppet/manifests/params.pp +0 -16
- data/puppet/r8meta.puppet.yml +0 -35
- data/puppet/templates/bash_profile.erb +0 -2
- data/puppet/templates/client.conf.erb +0 -1
- data/puppet/templates/dtkclient.erb +0 -2
- data/spec/component_module_spec.rb +0 -34
- data/spec/dependency_spec.rb +0 -6
- data/spec/dtk_shell_spec.rb +0 -13
- data/spec/dtk_spec.rb +0 -33
- data/spec/lib/spec_helper.rb +0 -10
- data/spec/lib/spec_thor.rb +0 -108
- data/spec/node_template_spec.rb +0 -24
- data/spec/project_spec.rb +0 -6
- data/spec/repo_spec.rb +0 -7
- data/spec/response_spec.rb +0 -52
- data/spec/service_module_spec.rb +0 -38
- data/spec/service_spec.rb +0 -50
- data/spec/state_change_spec.rb +0 -7
- data/spec/table_print_spec.rb +0 -48
- data/spec/target_spec.rb +0 -57
- data/spec/task_spec.rb +0 -28
- data/views/assembly/augmented_simple_list.rb +0 -12
- data/views/assembly_template/augmented_simple_list.rb +0 -12
- data/views/list_task/augmented_simple_list.rb +0 -12
data/lib/shell/status_monitor.rb
DELETED
@@ -1,124 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (C) 2010-2016 dtk contributors
|
3
|
-
#
|
4
|
-
# This file is part of the dtk project.
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
#
|
18
|
-
# TODO-REMOVE: Check if we need this anymore
|
19
|
-
|
20
|
-
require 'thread'
|
21
|
-
require 'singleton'
|
22
|
-
require 'colorize'
|
23
|
-
#dtk_require('../commands')
|
24
|
-
|
25
|
-
# This singleton is used to check status on running processes on the server side
|
26
|
-
# Once certain task is complete it will give notice to user da certain task has been completed
|
27
|
-
# At the moment this only
|
28
|
-
|
29
|
-
module DTK
|
30
|
-
module Shell
|
31
|
-
class TaskStatusThread < Thread
|
32
|
-
attr_accessor :task_id, :finished, :status
|
33
|
-
|
34
|
-
def initialize
|
35
|
-
@finished = false
|
36
|
-
super
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
class StatusMonitor
|
41
|
-
include Singleton
|
42
|
-
include DTK::Client::CommandBase
|
43
|
-
|
44
|
-
THREAD_SLEEP_TIME = DTK::Configuration.get(:task_check_frequency)
|
45
|
-
|
46
|
-
def initialize
|
47
|
-
@threads = []
|
48
|
-
@finished_tasks = []
|
49
|
-
@conn = DTK::Client::Session.get_connection()
|
50
|
-
end
|
51
|
-
|
52
|
-
def self.start_monitoring(task_id)
|
53
|
-
self.instance.start_monitoring(task_id)
|
54
|
-
end
|
55
|
-
|
56
|
-
def self.check_status
|
57
|
-
self.instance.check_status
|
58
|
-
end
|
59
|
-
|
60
|
-
def check_status
|
61
|
-
@threads.each do |t|
|
62
|
-
if t.finished
|
63
|
-
@finished_tasks << t
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
# removes finished tasks from the main queue
|
68
|
-
@threads = @threads - @finished_tasks
|
69
|
-
|
70
|
-
@finished_tasks.each do |t|
|
71
|
-
puts ""
|
72
|
-
puts "[TASK NOTICE] Task with ID: #{t.task_id}, has finished with status: #{colorize_status(t.status)}"
|
73
|
-
end
|
74
|
-
|
75
|
-
@finished_tasks.clear
|
76
|
-
end
|
77
|
-
|
78
|
-
def start_monitoring(task_id)
|
79
|
-
puts "Client has started monitoring task [ID:#{task_id}]. You will be notified when task has been completed."
|
80
|
-
@threads << DTK::Shell::TaskStatusThread.new do
|
81
|
-
begin
|
82
|
-
response, post_hash_body = nil, {}
|
83
|
-
post_hash_body[:task_id] = task_id
|
84
|
-
DTK::Shell::TaskStatusThread.current.task_id = task_id
|
85
|
-
|
86
|
-
# pooling server for task status
|
87
|
-
while task_running?(response)
|
88
|
-
sleep(THREAD_SLEEP_TIME) unless response.nil?
|
89
|
-
response = post rest_url("task/status"),post_hash_body
|
90
|
-
# we break if there is error in response
|
91
|
-
break unless response.ok?
|
92
|
-
end
|
93
|
-
|
94
|
-
DTK::Shell::TaskStatusThread.current.finished = true
|
95
|
-
|
96
|
-
if response.ok?
|
97
|
-
DTK::Shell::TaskStatusThread.current.status = response.data['status'].upcase
|
98
|
-
else
|
99
|
-
DTK::Shell::TaskStatusThread.current.status = "RESPONSE NOT OK, RESPONSE: #{response}"
|
100
|
-
end
|
101
|
-
|
102
|
-
rescue Exception => e
|
103
|
-
DtkLogger.instance.error_pp("[THREAD ERROR] Error getting task status with message: #{e.message}", e.backtrace)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
private
|
109
|
-
|
110
|
-
def colorize_status(status)
|
111
|
-
color = status.eql?('FAILED') ? :red : :green
|
112
|
-
return DTK::Client::OsUtil.colorize(status, color)
|
113
|
-
end
|
114
|
-
|
115
|
-
# return true if status SUCCEDED, FAILED
|
116
|
-
# returns false if status EXECUTING
|
117
|
-
def task_running?(response)
|
118
|
-
return true if response.nil?
|
119
|
-
return !(response.data['status'].eql?("succeeded") || response.data['status'].eql?("failed"))
|
120
|
-
end
|
121
|
-
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
data/lib/shell.rb
DELETED
@@ -1,261 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (C) 2010-2016 dtk contributors
|
3
|
-
#
|
4
|
-
# This file is part of the dtk project.
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
#
|
18
|
-
require File.expand_path('client', File.dirname(__FILE__))
|
19
|
-
require File.expand_path('parser/adapters/thor', File.dirname(__FILE__))
|
20
|
-
require File.expand_path('commands/thor/dtk', File.dirname(__FILE__))
|
21
|
-
require File.expand_path('error', File.dirname(__FILE__))
|
22
|
-
|
23
|
-
# load all from shell directory since those are required
|
24
|
-
Dir[File.expand_path('shell/**/*.rb', File.dirname(__FILE__))].each { |file| require file }
|
25
|
-
|
26
|
-
require 'shellwords'
|
27
|
-
require 'readline'
|
28
|
-
require 'colorize'
|
29
|
-
require 'thor'
|
30
|
-
|
31
|
-
# ideas from http://bogojoker.com/readline/#trap_sigint_and_restore_the_state_of_the_terminal
|
32
|
-
|
33
|
-
# GLOBAL IDENTIFIER
|
34
|
-
$shell_mode = true
|
35
|
-
|
36
|
-
ALIAS_COMMANDS = {
|
37
|
-
'ls' => 'list',
|
38
|
-
'cd' => 'cc',
|
39
|
-
'rm' => 'delete'
|
40
|
-
}
|
41
|
-
|
42
|
-
class MainContext
|
43
|
-
include Singleton
|
44
|
-
|
45
|
-
attr_accessor :context
|
46
|
-
|
47
|
-
def initialize
|
48
|
-
@context = DTK::Shell::Context.new
|
49
|
-
end
|
50
|
-
|
51
|
-
def self.get_context
|
52
|
-
MainContext.instance.context
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
# METHODS
|
57
|
-
|
58
|
-
# support for alias commands (ls for list, cd for cc etc.)
|
59
|
-
def preprocess_commands(original_command)
|
60
|
-
command = ALIAS_COMMANDS[original_command]
|
61
|
-
# return command if alias for specific command exist in predefined ALIAS_COMMANDS
|
62
|
-
# else return entered command because there is no alias for it
|
63
|
-
return (command.nil? ? original_command : command)
|
64
|
-
end
|
65
|
-
# RUNTIME PART - STARTS HERE
|
66
|
-
|
67
|
-
def run_shell_command()
|
68
|
-
# init shell client
|
69
|
-
init_shell_context()
|
70
|
-
|
71
|
-
# prompt init
|
72
|
-
prompt = DTK::Shell::Context::DTK_ROOT_PROMPT
|
73
|
-
|
74
|
-
# trap CTRL-C and remove current text without leaving the dtk-shell
|
75
|
-
trap("INT"){
|
76
|
-
puts "\n"
|
77
|
-
raise Interrupt
|
78
|
-
}
|
79
|
-
|
80
|
-
# runtime part
|
81
|
-
begin
|
82
|
-
while line = Readline.readline(prompt, true)
|
83
|
-
prompt = execute_shell_command(line, prompt) unless line.strip.empty?
|
84
|
-
end
|
85
|
-
rescue DTK::Shell::ExitSignal => e
|
86
|
-
# do nothing
|
87
|
-
rescue ArgumentError => e
|
88
|
-
puts e.backtrace if ::DTK::Configuration.get(:development_mode)
|
89
|
-
retry
|
90
|
-
rescue Interrupt => e
|
91
|
-
retry
|
92
|
-
rescue Exception => e
|
93
|
-
client_internal_error = DTK::Client::DtkError::Client.label()
|
94
|
-
DtkLogger.instance.error_pp("[#{client_internal_error}] #{e.message}", e.backtrace)
|
95
|
-
ensure
|
96
|
-
puts "\n" unless e.is_a? DTK::Shell::ExitSignal
|
97
|
-
# logout
|
98
|
-
DTK::Client::Session.logout()
|
99
|
-
# save users history
|
100
|
-
DTK::Shell::Context.save_session_history(Readline::HISTORY.to_a)
|
101
|
-
exit!
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
def init_shell_context()
|
106
|
-
begin
|
107
|
-
# @context = DTK::Shell::Context.new
|
108
|
-
@shell_header = DTK::Shell::HeaderShell.new
|
109
|
-
|
110
|
-
# loads root context
|
111
|
-
MainContext.get_context.load_context()
|
112
|
-
|
113
|
-
@t1 = nil
|
114
|
-
Readline.completion_append_character=''
|
115
|
-
DTK::Shell::Context.load_session_history().each do |c|
|
116
|
-
Readline::HISTORY.push(c)
|
117
|
-
end
|
118
|
-
|
119
|
-
rescue DTK::Client::DtkError => e
|
120
|
-
DtkLogger.instance.error(e.message, true)
|
121
|
-
puts "Exiting ..."
|
122
|
-
raise DTK::Shell::ExitSignal
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
def execute_shell_command(line, prompt)
|
127
|
-
begin
|
128
|
-
# remove single/double quotes from string because shellwords module is not able to parse it
|
129
|
-
if matched = line.scan(/['"]/)
|
130
|
-
line.gsub!(/['"]/, '') if matched.size.odd?
|
131
|
-
end
|
132
|
-
|
133
|
-
# some special cases
|
134
|
-
raise DTK::Shell::ExitSignal if line == 'exit'
|
135
|
-
return prompt if line.empty?
|
136
|
-
if line == 'clear'
|
137
|
-
DTK::Client::OsUtil::clear_screen
|
138
|
-
return prompt
|
139
|
-
end
|
140
|
-
# when using help on root this is needed
|
141
|
-
line = 'dtk help' if (line == 'help' && MainContext.get_context.root?)
|
142
|
-
|
143
|
-
args = Shellwords.split(line)
|
144
|
-
cmd = args.shift
|
145
|
-
|
146
|
-
# support command alias (ls for list etc.)
|
147
|
-
cmd = preprocess_commands(cmd)
|
148
|
-
|
149
|
-
# DEV only reload shell
|
150
|
-
if ::DTK::Configuration.get(:development_mode)
|
151
|
-
if ('restart' == cmd)
|
152
|
-
puts "DEV Reloading shell ..."
|
153
|
-
::DTK::Client::OsUtil.dev_reload_shell()
|
154
|
-
return prompt
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
|
159
|
-
if ('cc' == cmd)
|
160
|
-
# in case there is no params we just reload command
|
161
|
-
args << "/" if args.empty?
|
162
|
-
prompt = MainContext.get_context.change_context(args, cmd)
|
163
|
-
elsif ('popc' == cmd)
|
164
|
-
MainContext.get_context.dirs.shift()
|
165
|
-
args << (MainContext.get_context.dirs.first.nil? ? '/' : MainContext.get_context.dirs.first)
|
166
|
-
prompt = MainContext.get_context.change_context(args, cmd)
|
167
|
-
elsif ('pushc' == cmd)
|
168
|
-
if args.empty?
|
169
|
-
args << (MainContext.get_context.dirs[1].nil? ? '/' : MainContext.get_context.dirs[1])
|
170
|
-
MainContext.get_context.dirs.unshift(args.first)
|
171
|
-
MainContext.get_context.dirs.uniq!
|
172
|
-
prompt = MainContext.get_context.change_context(args, cmd)
|
173
|
-
else
|
174
|
-
prompt = MainContext.get_context.change_context(args)
|
175
|
-
# using regex to remove dtk: and > from path returned by change_context
|
176
|
-
# e.g transform dtk:/assembly/node> to /assembly/node
|
177
|
-
full_path = prompt.match(/[dtk:](\/.*)[>]/)[1]
|
178
|
-
MainContext.get_context.dirs.unshift(full_path)
|
179
|
-
end
|
180
|
-
elsif ('dirs' == cmd)
|
181
|
-
puts MainContext.get_context.dirs.inspect
|
182
|
-
else
|
183
|
-
|
184
|
-
# get all next-context-candidates (e.g. for assembly get all assembly_names)
|
185
|
-
context_candidates = MainContext.get_context.get_ac_candidates_for_context(MainContext.get_context.active_context.last_context(), MainContext.get_context.active_context())
|
186
|
-
|
187
|
-
# this part of the code is used for calling of nested commands from base context (dtk:/>assembly/assembly_id converge)
|
188
|
-
# base_command is used to check if first command from n-level is valid e.g.
|
189
|
-
# (dtk:/>assembly/assembly_id converge - chech if 'assembly' exists in context_candidates)
|
190
|
-
# revert_context is used to return to context which command is called from after command is executed
|
191
|
-
base_command = cmd.split('/').first
|
192
|
-
revert_context = false
|
193
|
-
|
194
|
-
if context_candidates.include?(base_command)
|
195
|
-
MainContext.get_context.change_context([cmd])
|
196
|
-
cmd = args.shift
|
197
|
-
revert_context = true
|
198
|
-
end
|
199
|
-
|
200
|
-
if cmd.nil?
|
201
|
-
prompt = MainContext.get_context.change_context(["-"]) if revert_context
|
202
|
-
raise DTK::Client::DtkValidationError, "You have to provide command after context name. Usage: CONTEXT-TYPE/CONTEXT-NAME COMMAND [ARG1] .. [ARG2]."
|
203
|
-
end
|
204
|
-
|
205
|
-
# send monkey patch class information about context
|
206
|
-
Thor.set_context(MainContext.get_context)
|
207
|
-
|
208
|
-
# we get command and hash params, will return Validation error if command is not valid
|
209
|
-
entity_name, method_name, context_params, thor_options, invalid_options = MainContext.get_context.get_command_parameters(cmd,args)
|
210
|
-
|
211
|
-
# check if command is executed from parent context (e.g assembly_name list-nodes)
|
212
|
-
if context_candidates.include?(method_name)
|
213
|
-
context_params.add_context_to_params(method_name, entity_name, method_name)
|
214
|
-
method_name = context_params.method_arguments.shift if context_params.method_arguments.size > 0
|
215
|
-
else
|
216
|
-
unless MainContext.get_context.method_valid?(method_name)
|
217
|
-
prompt = MainContext.get_context.change_context(["-"]) if revert_context
|
218
|
-
raise DTK::Client::DtkValidationError, "Method '#{method_name}' is not valid in current context."
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
# raise validation error if option is not valid
|
223
|
-
raise DTK::Client::DtkValidationError.new("Option '#{invalid_options.first||method_name}' is not valid for current command!", true) unless invalid_options.empty?
|
224
|
-
|
225
|
-
# execute command via Thor
|
226
|
-
current_contex_path = MainContext.get_context.active_context.full_path
|
227
|
-
top_level_execute(entity_name, method_name, context_params, thor_options, true)
|
228
|
-
|
229
|
-
# when 'delete' or 'delete-and-destroy' command is executed reload cached tasks with latest commands
|
230
|
-
unless (args.nil? || args.empty?)
|
231
|
-
MainContext.get_context.reload_cached_tasks(entity_name) if (method_name.include?('delete') || method_name.include?('import'))
|
232
|
-
end
|
233
|
-
|
234
|
-
# check execution status, prints status to sttout
|
235
|
-
DTK::Shell::StatusMonitor.check_status()
|
236
|
-
|
237
|
-
# if we change context while executing command, change prompt as well
|
238
|
-
unless current_contex_path.eql?(MainContext.get_context.active_context.full_path)
|
239
|
-
prompt = "dtk:#{MainContext.get_context.active_context.full_path}>"
|
240
|
-
end
|
241
|
-
|
242
|
-
# after nested command called from base context is executed successfully, return to context which command is executed from
|
243
|
-
# this is the same as 'cd -' command is executed
|
244
|
-
prompt = MainContext.get_context.change_context(["-"]) if revert_context
|
245
|
-
end
|
246
|
-
rescue DTK::Client::DSLParsing => e
|
247
|
-
DTK::Client::OsUtil.print(e.message, :red)
|
248
|
-
rescue DTK::Client::DtkValidationError => e
|
249
|
-
DTK::Client::OsUtil.print(e.message, :yellow)
|
250
|
-
rescue DTK::Shell::Error => e
|
251
|
-
DtkLogger.instance.error(e.message, true)
|
252
|
-
end
|
253
|
-
|
254
|
-
return prompt
|
255
|
-
end
|
256
|
-
|
257
|
-
public
|
258
|
-
|
259
|
-
def execute_shell_command_internal(line)
|
260
|
-
execute_shell_command(line, DTK::Shell::Context::DTK_ROOT_PROMPT)
|
261
|
-
end
|
data/lib/task_status.rb
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (C) 2010-2016 dtk contributors
|
3
|
-
#
|
4
|
-
# This file is part of the dtk project.
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
#
|
18
|
-
module DTK::Client
|
19
|
-
module TaskStatusMixin
|
20
|
-
def task_status_aux(mode, object_id, object_type, opts = {})
|
21
|
-
case mode
|
22
|
-
when :refresh
|
23
|
-
TaskStatus::RefreshMode.new(self, mode, object_id, object_type).task_status(opts)
|
24
|
-
when :snapshot
|
25
|
-
TaskStatus::SnapshotMode.new(self, mode, object_id, object_type).task_status(opts)
|
26
|
-
when :stream
|
27
|
-
assembly_or_workspace_id = object_id
|
28
|
-
task_status_stream(assembly_or_workspace_id)
|
29
|
-
else
|
30
|
-
legal_modes = [:refresh, :snapshot, :stream]
|
31
|
-
raise DtkError::Usage.new("Illegal mode '#{mode}'; legal modes are: #{legal_modes.join(', ')}")
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def task_status_stream(assembly_or_workspace_id, opts = {})
|
36
|
-
TaskStatus::StreamMode.new(self, :stream, assembly_or_workspace_id, :assembly).get_and_render(opts)
|
37
|
-
end
|
38
|
-
|
39
|
-
def list_task_info_aux(object_type, object_id)
|
40
|
-
response = TaskStatus.new(self, object_id, object_type).post_call(:form => :list)
|
41
|
-
unless response.ok?
|
42
|
-
DtkError.raise_error(response)
|
43
|
-
end
|
44
|
-
response.override_command_class("list_task")
|
45
|
-
puts response.render_data
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
dtk_require_common_commands('thor/base_command_helper')
|
50
|
-
class TaskStatus < BaseCommandHelper
|
51
|
-
require File.expand_path('task_status/snapshot_mode', File.dirname(__FILE__))
|
52
|
-
require File.expand_path('task_status/refresh_mode', File.dirname(__FILE__))
|
53
|
-
require File.expand_path('task_status/stream_mode', File.dirname(__FILE__))
|
54
|
-
|
55
|
-
def initialize(command, mode, object_id, object_type)
|
56
|
-
super(command)
|
57
|
-
@mode = mode
|
58
|
-
@object_id = object_id
|
59
|
-
@object_type = object_type
|
60
|
-
end
|
61
|
-
|
62
|
-
private
|
63
|
-
|
64
|
-
def post_body(opts = {})
|
65
|
-
id_field = "#{@object_type}_id".to_sym
|
66
|
-
PostBody.new(
|
67
|
-
id_field => @object_id,
|
68
|
-
:form? => opts[:form],
|
69
|
-
:wait_for? => opts[:wait_for],
|
70
|
-
:summarize_node_groups? => opts[:summarize]
|
71
|
-
)
|
72
|
-
end
|
73
|
-
|
74
|
-
def post_call(opts={})
|
75
|
-
response = post rest_url("#{@object_type}/task_status"), post_body(opts)
|
76
|
-
unless response.ok?
|
77
|
-
DtkError.raise_error(response)
|
78
|
-
end
|
79
|
-
response
|
80
|
-
end
|
81
|
-
|
82
|
-
end
|
83
|
-
end
|
data/lib/util/console.rb
DELETED
@@ -1,235 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (C) 2010-2016 dtk contributors
|
3
|
-
#
|
4
|
-
# This file is part of the dtk project.
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
#
|
18
|
-
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
|