Module: BundleHelper

Defined in:
lib/ignition/helpers/bundle_helper.rb

Constant Summary collapse

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”: “s3-eu-west-1.amazonaws.com/drivetag/packages/drivetag-master-1.0.zip”, “extract”: true }, “scale”: 1,

"valid": true

“status_message”: “”, “error_message”: “” }

"#{Ignition::ROOT_FOLDER}/downloads"

Class Method Summary collapse

Class Method Details

.extract_file_path(destination, entry) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
# 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) ⇒ Object



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
# 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) ⇒ Object



25
26
27
28
29
# File 'lib/ignition/helpers/bundle_helper.rb', line 25

def self.prepare_bundles(bundles)
	bundles.each do |bundle|
		prepare_bundle(bundle)
	end
end


103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/ignition/helpers/bundle_helper.rb', line 103

def self.print_bundles(hostname,bundles)
	a = []
	bundles.each do |bundle|
		h = {}
		h[:id] = bundle.id
		# h[:command] = bundle.command
		h[:hostname] = hostname
		h[:num_runing] = bundle.status.pids.size
		h[:status] = bundle.status.message
		a << h
	end
	tp(a)
end

.unzip_file(file, destination) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# 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