class Pennyworth::BaseCommand
Attributes
boxes_dir[R]
Public Class Methods
new(boxes_dir, remote_url = nil)
click to toggle source
Calls superclass method
# File lib/pennyworth/commands/base_command.rb, line 23 def initialize(boxes_dir, remote_url = nil) super() @boxes_dir = boxes_dir @remote_url = remote_url end
Public Instance Methods
local_base_images()
click to toggle source
# File lib/pennyworth/commands/base_command.rb, line 43 def local_base_images Dir.glob(File.join(@boxes_dir, "definitions", "*")). select { |f| File.directory?(f) }. map { |d| File.basename(d) } end
process_base_image_parameter(all_images, base_image = nil)
click to toggle source
# File lib/pennyworth/commands/base_command.rb, line 49 def process_base_image_parameter(all_images, base_image = nil) if !base_image return all_images end if all_images.include?(base_image) return [base_image] else raise "Unknown base image '#{base_image}'. Known images are: #{all_images.join(", ")}." end end
read_box_sources_state(box_name)
click to toggle source
# File lib/pennyworth/commands/base_command.rb, line 60 def read_box_sources_state(box_name) sources = Hash.new source_dir = File.join(@boxes_dir, "definitions", box_name) Find.find(source_dir) do |file| next if File.directory?(file) relative_path = file.gsub(/^#{File.join(source_dir, "/")}/, "") sources[relative_path] = Digest::MD5.file(file).hexdigest end sources end
read_box_target_state(box_name)
click to toggle source
# File lib/pennyworth/commands/base_command.rb, line 71 def read_box_target_state(box_name) box_file = File.join(@boxes_dir, box_name) + ".box" if File.exist?(box_file) target_state = Digest::MD5.file(box_file).hexdigest end target_state end
read_local_box_state_file()
click to toggle source
# File lib/pennyworth/commands/base_command.rb, line 85 def read_local_box_state_file box_state_file = File.join(@boxes_dir, "box_state.yaml") if File.exist? box_state_file box_state = YAML.load_file(box_state_file) else box_state = {} end box_state end
remote_base_images(subdir = "")
click to toggle source
# File lib/pennyworth/commands/base_command.rb, line 29 def remote_base_images(subdir = "") return [] if !@remote_url || @remote_url.empty? uri = URI.parse(URLs.join(@remote_url, subdir, "import_state.yaml")) response = Net::HTTP.get_response(uri) if response.is_a?(Net::HTTPSuccess) index = YAML.load(response.body) index.keys else STDERR.puts "Could not download remote state file at #{uri.to_s}: " + response.message exit 1 end end
write_box_state_file(box_state)
click to toggle source
# File lib/pennyworth/commands/base_command.rb, line 79 def write_box_state_file(box_state) File.open(File.join(@boxes_dir, "box_state.yaml"), "w") do |f| f.write(box_state.to_yaml) end end