module BundleHelper

Constants

BUNDLE_DOWNLOADS

{

   "id": "dt-master",
   "description": "DriveTag Master",
   "command": "./bin/drivetag-master -mem 32 local 29101 current",
   "cwd": "$HOME/drivetag/drivetag-master-1.0",
   "repo": {
           "source": "https://s3-eu-west-1.amazonaws.com/drivetag/packages/drivetag-master-1.0.zip",
           "extract": true
   },
   "scale": 1,
"valid": true
   "status_message": "",
   "error_message": ""

}

Public Class Methods

extract_file_path(destination,entry) click to toggle source
# File lib/ignition/helpers/bundle_helper.rb, line 90
def self.extract_file_path(destination,entry)
        dest_folder = File.basename(destination)
        expanded_path = nil
        if (entry.name.index(dest_folder) == 0)
                expanded_path = destination.gsub(dest_folder,entry.name)
        else
                expanded_path = destination + '/' + entry.name
        end

        FileUtils.makedirs(File.dirname(expanded_path))
        expanded_path
end
prepare_bundle(bundle) click to toggle source
# File lib/ignition/helpers/bundle_helper.rb, line 31
def self.prepare_bundle(bundle)
        puts BUNDLE_DOWNLOADS
        puts bundle.cwd

        bundle.status.valid = true
        bundle.status.message = "preparing bundle."

        FileUtils.makedirs(BUNDLE_DOWNLOADS)
        FileUtils.makedirs(bundle.cwd)

        unless bundle.repo.nil?
                repo_file = File.basename(bundle.repo.source)
                download_file_path = "#{BUNDLE_DOWNLOADS}/#{repo_file}"
                begin
                        puts "download_file_path #{download_file_path}"
                        unless File.exists?(download_file_path)
                                bundle.status.message = "preparing bundle. downloading file"
                                DownloadHelper.download_file(bundle.repo.source,download_file_path)
                        end
                        if (bundle.repo.extract)
                                bundle.status.message = "preparing bundle. extracting file"
                                unzip_file(download_file_path,bundle.cwd)
                        end
                rescue Exception => exc
                        puts exc.message
                        puts exc.backtrace
                        bundle.status.valid = false
                        bundle.status.message += " - ERROR ( " + exc.message + ":" + exc.backtrace.to_s + ")"
                end
        end

        bundle.status.message = "bundle complete" if bundle.status.valid

        pp bundle
end
prepare_bundles(bundles) click to toggle source
# File lib/ignition/helpers/bundle_helper.rb, line 25
def self.prepare_bundles(bundles)
        bundles.each do |bundle|
                prepare_bundle(bundle)
        end
end
print_bundles(hostname,bundles) click to toggle source
unzip_file(file, destination) click to toggle source
# File lib/ignition/helpers/bundle_helper.rb, line 67
def self.unzip_file(file, destination)
        Zip::File.open(file) do |zip_file|
          # Handle entries one by one
          zip_file.each do |entry|
            # Extract to file/directory/symlink
            puts "entry.name #{entry.name}"
            dest_file = extract_file_path(destination,entry)
            if (File.exists?(dest_file))
              puts "skipping #{dest_file}" #need to add some size/CRC checking
            else
              puts "Extracting #{entry.name} to #{dest_file}"
              entry.extract(dest_file)
                end
            # Read into memory
            # content = entry.get_input_stream.read
          end

          # Find specific entry
          # entry = zip_file.glob('*.csv').first
          # puts entry.get_input_stream.read
        end
end