lib/buildrdeb/package.rb in buildrdeb-0.0.3 vs lib/buildrdeb/package.rb in buildrdeb-1.0.0
- old
+ new
@@ -24,47 +24,42 @@
# the file_map is the result of the computations of the include and exclude filters.
#
# With deb we recreate the structure asked by the user
# then we will call dpkg --build over it.
def create_from(file_map)
- root = File.join("target", "_#{File.basename(name)}")
+ root = File.join("target", "#{File.basename(name)}-contents")
mkpath File.join(root, "DEBIAN")
- #echo "THe version " + @version
- for file in ["control", "prerm", "postinst", "postrm", "preinst", "triggers"]
- thefile = eval("self."+file)
- targetFile = File.join(root, "DEBIAN", file)
- if !thefile.nil? and File.exists? thefile
- actualFile = File.open(thefile, "r")
- myfile = File.open( targetFile, "w")
- actualFile.each { |line|
- if file == "control" then
- if line.match /^Version: / and !@version.nil? then myfile.puts("Version: " + @version +"\n")
- else myfile.puts eval('"'+ line + '"') end
- else myfile.puts line end
+ for filename in ["control", "prerm", "postinst", "postrm", "preinst", "triggers"]
+ file = send(filename)
+ if file.nil?
+ raise "no control file was defined when packaging as a deb file" if filename == "control"
+ else
+ raise "Cannot find #{filename}: #{file} doesn't exist" if !File.exists? file
+ target = File.join(root, "DEBIAN", filename)
+ contents = File.read(file)
+ # Replace version if we are looking at control.
+ contents.gsub!(/^Version: .*$/, "Version: #{@version}") if (filename == "control" && !@version.nil?)
+ File.open(target, "w+") {|t|
+ t.write eval("\"#{contents}\"")
}
- myfile.close
- actualFile.close
- File.chmod 0755, targetFile
- #cp send(file.to_sym), File.join(root, "DEBIAN", file)
- #File.chmod 0755, File.join(root, "DEBIAN", file)
+ File.chmod 0755, target
end
end
-
file_map.each do |path, content|
_path = File.join(root, path)
if content.respond_to?(:call)
raise "Not implemented"
- content.call path
- elsif content.nil? || File.directory?(content.to_s)
- mkpath _path
+ #content.call path
+ elsif content.nil?
+ mkdir_p _path
+ elsif File.directory?(content.to_s)
+
else
- mkpath File.dirname(_path)
+ mkdir_p File.dirname(_path) if !File.exists?(File.dirname(_path))
cp content.to_s, _path
end
end
-
-
out = %x[ dpkg --build \"#{root}\" \"#{name}\" 2>&1 ]
raise "dpkg failed with this error:\n#{out}" if $? != 0
end
end
@@ -72,16 +67,13 @@
module ActAsDebPackager
include Extension
def package_as_deb(file_name)
deb = DebTask.define_task(file_name)
- deb.tap do
- package ||= project.id
- version ||= project.version
- end
deb.enhance do |task|
task.enhance do
- raise "no control file was defined when packaging #{project.id} as a deb file" if task.control.nil?
+ package ||= project.id
+ version ||= project.version
end
end
return deb
end
end
\ No newline at end of file