Permalink
Browse files

- some code cleanup

- source rpm => target puppet works now
  • Loading branch information...
1 parent 3f24e79 commit 66bfb56e0e9139812d004458c172b2d97b03c511 @jordansissel committed Jun 21, 2011
View
@@ -91,8 +91,7 @@ def assemble!
# Perhaps something like @package.prepare
if @package.respond_to?(:unpack_data_to)
data_tarball = File.join(builddir, "data.tar.gz")
- FileUtils.mkdir_p(output)
- Dir.chdir(output) do
+ Dir.chdir(builddir) do
FileUtils.mkdir_p(@package.unpack_data_to)
system("gzip -d #{data_tarball}")
Dir.chdir(@package.unpack_data_to) do
View
@@ -62,6 +62,7 @@ class FPM::Package
def initialize(source)
@source = source
@logger = Logger.new(STDERR)
+ @logger.level = $DEBUG ? Logger::DEBUG : Logger::WARN
@name = source[:name] # || fail
@@ -119,10 +120,9 @@ def type
def template(path=nil)
path ||= "#{type}.erb"
- @template ||= begin
- tpl = File.read("#{FPM::DIRS[:templates]}/#{path}")
- ERB.new(tpl, nil, "-")
- end
+ @logger.info("Reading template: #{path}")
+ tpl = File.read("#{FPM::DIRS[:templates]}/#{path}")
+ return ERB.new(tpl, nil, "-")
end # def template
def render_spec
@@ -152,15 +152,15 @@ def default_output
end # def default_output
def fixpath(path)
- p :fixpath => path
if path.first != "/"
path = File.join(@source.root, path)
end
return path if File.symlink?(path)
+ @logger.info(:fixpath => path)
realpath = Pathname.new(path).realpath.to_s
re = Regexp.new("^#{Regexp.escape(@source.root)}")
realpath.gsub!(re, "")
- p :fixpath => {:path => realpath, :caller => caller[0] }
+ @logger.info(:fixpath_result => realpath)
return realpath
end # def fixpath
end # class FPM::Package
View
@@ -26,6 +26,9 @@ def dependencies
attr_accessor :root
def initialize(paths, root, params={})
+ @logger = Logger.new(STDERR)
+ @logger.level = $DEBUG ? Logger::DEBUG : Logger::WARN
+
@paths = paths
@root = root
@@ -119,7 +122,6 @@ def tar(output, paths, chdir=".")
+ excludes \
+ ["-cf", output, "--no-recursion" ] \
+ dirs
- p :dirs => dirs
::Dir.chdir(chdir) do
system(*dir_tar) if dirs.any?
View
@@ -3,11 +3,11 @@
class FPM::Source::RPM < FPM::Source
def get_metadata
@rpm = @paths.first
- self[:name] = %x{rpm -q --qf '%{name}' -p #{@rpm}}
+ self[:name] = %x{rpm -q --qf '%{name}' -p #{@rpm}}.chomp
- self[:version] = %x{rpm -q --qf '%{version}' -p #{@rpm}}
- self[:iteration] = %x{rpm -q --qf '%{release}' -p #{@rpm}}
- self[:summary] = %x{rpm -q --qf '%{summary}' -p #{@rpm}}
+ self[:version] = %x{rpm -q --qf '%{version}' -p #{@rpm}}.chomp
+ self[:iteration] = %x{rpm -q --qf '%{release}' -p #{@rpm}}.chomp
+ self[:summary] = %x{rpm -q --qf '%{summary}' -p #{@rpm}}.chomp
#self[:description] = %x{rpm -q --qf '%{description}' -p #{@rpm}}
self[:dependencies] = %x{rpm -qRp #{@rpm}}.split("\n")\
.collect { |line| line.strip }
@@ -20,9 +20,7 @@ def make_tarball!(tar_path, builddir)
::Dir.mkdir(tmpdir)
system("rpm2cpio #{@rpm} | (cd #{tmpdir}; cpio -i --make-directories)")
tar(tar_path, ".", tmpdir)
- @paths = "."
- @root = tmpdir
-
+ @paths = ["."]
# TODO(sissel): Make a helper method.
system(*["gzip", "-f", tar_path])
end
View
@@ -14,7 +14,7 @@ def architecture
# to ask the system about.
arch = %x{dpkg --print-architecture}.chomp
if $?.exitstatus != 0
- arch = %x{uname -m}
+ arch = %x{uname -m}.chomp
@logger.warn("Can't find 'dpkg' tool (need it to get default " \
"architecture!). Please specificy --architecture " \
"specifically. (Defaulting now to #{arch})")
View
@@ -3,17 +3,18 @@
require "fpm/package"
require "fpm/errors"
require "etc"
+require "ftools"
-class ::Dir
- class << self
- alias :orig_mkdir :mkdir
-
- def mkdir(*args)
- p :mkdir => { :args => args, :caller => caller }
- orig_mkdir(*args)
- end
- end
-end
+#class ::Dir
+ #class << self
+ #alias :orig_mkdir :mkdir
+#
+ #def mkdir(*args)
+ ##p :mkdir => { :args => args, :caller => caller }
+ #orig_mkdir(*args)
+ #end
+ #end
+#end
require "fileutils" # for FileUtils
@@ -36,18 +37,29 @@ def specfile(builddir)
# this package.
def generate_specfile(builddir)
paths = []
- @source.paths.each do |path|
- Find.find(path) { |p| paths << p }
+ @logger.info("PWD: #{File.join(builddir, unpack_data_to)}")
+ fileroot = File.join(builddir, unpack_data_to)
+ Dir.chdir(fileroot) do
+ Find.find(".") do |p|
+ next if p == "."
+ paths << p
+ end
end
+ @logger.info(paths[-1])
manifests = %w{package.pp package/remove.pp}
- manifests.each do |name|
- dir = File.join(builddir, File.dirname(name))
+
+ ::Dir.mkdir(File.join(builddir, "manifests"))
+ manifests.each do |manifest|
+ dir = File.join(builddir, "manifests", File.dirname(manifest))
@logger.info("manifests targeting: #{dir}")
- Dir.mkdir(dir) if !File.directory?(dir)
+ ::Dir.mkdir(dir) if !File.directory?(dir)
- @logger.info("Generating #{name}")
- File.open(File.join(builddir, name), "w") do |f|
- f.puts template(File.join("puppet", "#{name}.erb")).result(binding)
+ File.open(File.join(builddir, "manifests", manifest), "w") do |f|
+ @logger.info("manifest: #{f.path}")
+ template = template(File.join("puppet", "#{manifest}.erb"))
+ ::Dir.chdir(fileroot) do
+ f.puts template.result(binding)
+ end
end
end
end # def generate_specfile
@@ -63,6 +75,7 @@ def render_spec
#@logger.info(:paths => paths.sort)
template.result(binding)
end # def render_spec
+
def unpack_data_to
"files"
end
@@ -84,15 +97,18 @@ def build!(params)
"exists. Delete it or choose another output (-p flag)")
end
- Dir.mkdir(params[:output])
- builddir = Dir.pwd
+ ::Dir.mkdir(params[:output])
+ builddir = ::Dir.pwd
- Dir.chdir(params[:output]) do
- Dir.mkdir("manifests")
- FileUtils.cp(specfile(builddir), "manifests")
+ # Copy 'files' from builddir to :output/files
+ Find.find("files", "manifests") do |path|
+ @logger.info("Copying path: #{path}")
+ if File.directory?(path)
+ ::Dir.mkdir(File.join(params[:output], path))
+ else
+ File.copy(path, File.join(params[:output], path))
+ end
end
- # Files are now in the 'files' path
- # Generate a manifest 'package.pp' with all the information from
end # def build!
# The directory we create should just be the name of the package as the
@@ -2,10 +2,12 @@ class <%= name %>::package::remove {
$version = "<%= version %>"
$iteration = "<%= iteration %>"
+ fail("DO NOT USE THIS. IT IS NOT WELL DEFINED YET.")
+
file {
<% paths.each do |path| -%>
"<%= fixpath(path) %>":
- <%= settings %>;
+ ensure => absent;
<% end # paths.each -%>
}
}

0 comments on commit 66bfb56

Please sign in to comment.