Class: DTK::Client::CommonModule::Import
- Inherits:
-
BaseCommandHelper
- Object
- BaseCommandHelper
- DTK::Client::CommonModule::Import
- Includes:
- DTK::Client::CommandBase, DTK::Client::CommandHelperMixin, PushCloneChangesMixin, ReparseMixin
- Defined in:
- lib/commands/common/thor/module/import.rb
Constant Summary
Constants included from ReparseMixin
ReparseMixin::YamlDTKMetaFiles
Constants included from DTK::Client::CommandHelperMixin
DTK::Client::CommandHelperMixin::Loaded
Instance Method Summary collapse
Methods included from ReparseMixin
Methods included from PushCloneChangesMixin
Methods included from DTK::Client::CommandHelperMixin
Methods included from DTK::Client::CommandBase
#get, #get_connection, handle_argument_error, #post, #post_file, #rest_url, #rotate_args
Methods inherited from BaseCommandHelper
#initialize, #print_external_dependencies
Constructor Details
This class inherits a constructor from DTK::Client::BaseCommandHelper
Instance Method Details
#from_file ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/commands/common/thor/module/import.rb', line 86 def from_file() module_type = @command.get_module_type(@context_params) module_name = retrieve_arguments([:option_1!]) opts = {} namespace, local_module_name = get_namespace_and_name(module_name, ModuleUtil::NAMESPACE_SEPERATOR) response = from_git_or_file() return response unless response.ok? opts_pull = { :local_branch => @branch, :namespace => @module_namespace } resp = Helper(:git_repo).pull_changes(module_type, @module_name, opts_pull) return resp unless resp.ok? if error = response.data(:dsl_parse_error) = ServiceImporter.(module_name, error) DTK::Client::OsUtil.print(, :red) end # remove source directory if no errors while importing module_final_dir = @repo_obj.repo_dir if @old_dir and (@old_dir != module_final_dir) FileUtils.rm_rf(@old_dir) unless namespace end if external_dependencies = response.data(:external_dependencies) print_external_dependencies(external_dependencies, 'dtk.model.yaml includes') end # if user do import from default directory (e.g. import ntp - without namespace) print message DTK::Client::OsUtil.print("Module '#{@new_module_name}' has been created and module directory moved to #{module_final_dir}",:yellow) unless namespace Response::Ok.new() end |
#from_git(internal_trigger = false) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/commands/common/thor/module/import.rb', line 30 def from_git(internal_trigger = false) OsUtil.print('Retrieving git module data, please wait ...') unless internal_trigger git_repo_url, module_name = retrieve_arguments([:option_1!, :option_2!]) namespace, local_module_name = get_namespace_and_name(module_name, ModuleUtil::NAMESPACE_SEPERATOR) module_type = @command.get_module_type(@context_params) = { :git_import => true} unless namespace namespace_response = post rest_url("namespace/default_namespace_name") return namespace_response unless namespace_response.ok? namespace = namespace_response.data [:default_namespace] = namespace end opts = { :namespace => namespace, :branch => @options['branch'] } response = Helper(:git_repo).create_clone_from_optional_branch(module_type.to_sym, local_module_name, git_repo_url, opts) return response unless response.ok? # Remove .git directory to rid of git pointing to user's github FileUtils.rm_rf("#{response['data']['module_directory']}/.git") @context_params.() create_response = from_git_or_file() unless create_response.ok? delete_dir = namespace.nil? ? local_module_name : "#{namespace}/#{local_module_name}" full_module_name = create_response.data[:full_module_name] local_module_name = full_module_name.nil? ? delete_dir : full_module_name @command.delete_module_sub_aux(@context_params, local_module_name, :force_delete => true, :no_error_msg => true, :purge => true) return create_response end opts_pull = { :local_branch => @branch, :namespace => @module_namespace } pull_response = Helper(:git_repo).pull_changes(module_type, @module_name, opts_pull) return pull_response unless pull_response.ok? if external_dependencies = create_response.data(:external_dependencies) print_external_dependencies(external_dependencies, 'in the git repo') end unless internal_trigger OsUtil.print("Successfully installed #{ModuleUtil.module_name(module_type)} '#{ModuleUtil.join_name(@module_name, @module_namespace)}' from git.", :green) end end |