Module: Debra::Execute
- Included in:
- Debra
- Defined in:
- lib/debra/execute.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args) ⇒ Object
66
67
68
|
# File 'lib/debra/execute.rb', line 66
def method_missing(sym, *args)
@@control[sym] = args[0]
end
|
Instance Method Details
#control ⇒ Object
81
82
83
|
# File 'lib/debra/execute.rb', line 81
def control
yield
end
|
#files(*args, &block) ⇒ Object
70
71
72
|
# File 'lib/debra/execute.rb', line 70
def files(*args, &block)
@@files = Rake::FileList.new *args, &block
end
|
#generate_control_text ⇒ Object
74
75
76
77
78
79
|
# File 'lib/debra/execute.rb', line 74
def generate_control_text
@@control.to_a.map do |item|
key = item[0].to_s.split("_").map{|v| v.capitalize}.join("-")
"#{key}: #{item[1]}"
end.join("\n")
end
|
#load_file ⇒ Object
93
94
95
|
# File 'lib/debra/execute.rb', line 93
def load_file
class_eval "load '#{@@options.file}'"
end
|
#package_name ⇒ Object
56
57
58
|
# File 'lib/debra/execute.rb', line 56
def package_name
"#{@@control[:package]}-#{@@control[:version]}-#{@@control[:architecture]}.deb"
end
|
#run(options) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
53
54
|
# File 'lib/debra/execute.rb', line 5
def run(options)
@@options = options
@@control = {}
@@files = []
@@generate = {}
puts "Loading #{options.file}" if options.verbose
load_file
puts "Creating temp files" if options.verbose
tmp_dir = "/tmp/debra_" + Process.pid.to_s
Dir.mkdir tmp_dir
Dir.mkdir tmp_dir + "/DEBIAN"
if @@options.revision != nil
@@control[:version] = @@control[:version] + "-" + @@options.revision
end
write tmp_dir + "/DEBIAN/control", generate_control_text
@@generate.each_pair do |name, contents|
write tmp_dir + "/DEBIAN/#{name.to_s}", contents
File.chmod 0755, tmp_dir + "/DEBIAN/#{name.to_s}"
end
@@files.resolve.each do |file|
if File.directory?(file)
FileUtils.mkdir_p tmp_dir + "/" + file
else
FileUtils.cp file, tmp_dir + "/" + file
end
end
puts "Generating debian package" if options.verbose
`dpkg --build #{tmp_dir} #{package_name}`
if $? != 0
puts "Error running dpkg, exiting"
FileUtils.rm_rf tmp_dir
exit 1
end
puts "Removing temp files" if options.verbose
FileUtils.rm_rf tmp_dir
puts "Created package: #{package_name}"
end
|
#write(file, str) ⇒ Object
60
61
62
63
64
|
# File 'lib/debra/execute.rb', line 60
def write(file, str)
file = File.new(file, "w")
file.write(str + "\n")
file.close
end
|