Class: Sensible::Task
- Inherits:
-
Object
- Object
- Sensible::Task
- Defined in:
- lib/sensible/task.rb
Instance Attribute Summary collapse
-
#check ⇒ Object
readonly
Returns the value of attribute check.
-
#copy ⇒ Object
readonly
Returns the value of attribute copy.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#packages ⇒ Object
readonly
Returns the value of attribute packages.
-
#require ⇒ Object
readonly
Returns the value of attribute require.
-
#script ⇒ Object
readonly
Returns the value of attribute script.
-
#sensible ⇒ Object
readonly
Returns the value of attribute sensible.
-
#show_output ⇒ Object
Returns the value of attribute show_output.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #check_exists(path) ⇒ Object
- #do_check ⇒ Object
- #do_copy ⇒ Object
-
#do_packages_check ⇒ Object
Check if the packages in this task is installed.
-
#do_packages_install ⇒ Object
Install the packages in this task.
- #do_script ⇒ Object
- #do_verify ⇒ Object
-
#initialize(taskHash, file_name, user = nil, sensible) ⇒ Task
constructor
A new instance of Task.
Constructor Details
#initialize(taskHash, file_name, user = nil, sensible) ⇒ Task
Returns a new instance of Task.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/sensible/task.rb', line 21 def initialize(taskHash, file_name, user = nil, sensible) @name = taskHash['name'] @check = taskHash['check'] @script = taskHash['script'] @require = taskHash['require'] @env = taskHash['env'] || [] @file_name = file_name @description = taskHash['description'] @show_output = taskHash['showOutput'] @copy = taskHash['copy'] # If task is initalized with user, force use of that if user != nil @user = user end # Always use the user from the task if taskHash['user'] != nil @user = taskHash['user'] end @sensible = sensible @packages = [] if taskHash['packages'] taskHash['packages'].each do |distro, packages| packages.each do |packageName| @packages << Package.new(packageName, distro, sensible) end end end end |
Instance Attribute Details
#check ⇒ Object (readonly)
Returns the value of attribute check.
11 12 13 |
# File 'lib/sensible/task.rb', line 11 def check @check end |
#copy ⇒ Object (readonly)
Returns the value of attribute copy.
19 20 21 |
# File 'lib/sensible/task.rb', line 19 def copy @copy end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
17 18 19 |
# File 'lib/sensible/task.rb', line 17 def description @description end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
14 15 16 |
# File 'lib/sensible/task.rb', line 14 def env @env end |
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
15 16 17 |
# File 'lib/sensible/task.rb', line 15 def file_name @file_name end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/sensible/task.rb', line 9 def name @name end |
#packages ⇒ Object (readonly)
Returns the value of attribute packages.
10 11 12 |
# File 'lib/sensible/task.rb', line 10 def packages @packages end |
#require ⇒ Object (readonly)
Returns the value of attribute require.
13 14 15 |
# File 'lib/sensible/task.rb', line 13 def require @require end |
#script ⇒ Object (readonly)
Returns the value of attribute script.
12 13 14 |
# File 'lib/sensible/task.rb', line 12 def script @script end |
#sensible ⇒ Object (readonly)
Returns the value of attribute sensible.
8 9 10 |
# File 'lib/sensible/task.rb', line 8 def sensible @sensible end |
#show_output ⇒ Object
Returns the value of attribute show_output.
18 19 20 |
# File 'lib/sensible/task.rb', line 18 def show_output @show_output end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
16 17 18 |
# File 'lib/sensible/task.rb', line 16 def user @user end |
Instance Method Details
#check_exists(path) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/sensible/task.rb', line 140 def check_exists(path) is_folder = path.end_with?('/') = File.(path) if is_folder == true return Dir.exist?() else return File.exist?() end # Handle remote end |
#do_check ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/sensible/task.rb', line 82 def do_check # Always return false to force copy if @copy != nil return false end # If check is not set, always run the task if @check == nil return false end # If there is no check, default to false, to force task to script every time shell = Shell.new(@sensible) return shell.run_command(@check, @user, show_output: @show_output) end |
#do_copy ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/sensible/task.rb', line 99 def do_copy origin = File.(@copy['origin']) destination = @copy['dest'] = File.(@copy['dest']) puts destination commmand = nil if @sensible.opts.host if @user command = "rsync -avu --delete #{Shellwords.escape(origin)} root@#{@sensible.opts.host}:#{Shellwords.escape(destination.sub('~', "/home/#{user}"))}" else command = "rsync -avu --delete #{Shellwords.escape(origin)} root@#{@sensible.opts.host}:#{Shellwords.escape(destination)}" end else command = "rsync -avu --delete #{Shellwords.escape(origin)} #{Shellwords.escape()}" end if @sensible.opts.verbose system(command) else system(command, out: File::NULL, err: File::NULL) end return $?.success? end |
#do_packages_check ⇒ Object
Check if the packages in this task is installed
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/sensible/task.rb', line 55 def do_packages_check has_all_packages_install = true @packages.each do |package| package.name if !package.do_check has_all_packages_install = false end end return has_all_packages_install end |
#do_packages_install ⇒ Object
Install the packages in this task
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/sensible/task.rb', line 70 def do_packages_install has_all_packages_install = true @packages.each do |package| if !package.do_install has_all_packages_install = false end end return has_all_packages_install end |
#do_script ⇒ Object
129 130 131 132 133 |
# File 'lib/sensible/task.rb', line 129 def do_script # TODO: Handle the show output property! shell = Shell.new(@sensible) return shell.run_command(@script, @user, show_output: @show_output) end |
#do_verify ⇒ Object
135 136 137 |
# File 'lib/sensible/task.rb', line 135 def do_verify return true end |