Permalink
Browse files

Merge pull request #635 from jordansissel/add-zip-support

Add zip support
  • Loading branch information...
2 parents 2ea0517 + a40eaec commit 0b3b26009d8ab1ebe8b7e7643a0120cca2790d88 @jordansissel committed Feb 10, 2014
View
@@ -385,8 +385,9 @@ def execute
# Write the output somewhere, package can be nil if no --package is specified,
# and that's OK.
+ package_file = output.to_s(package)
begin
- output.output(output.to_s(package))
+ output.output(package_file)
rescue FPM::Package::FileAlreadyExists => e
@logger.fatal(e.message)
return 1
@@ -395,6 +396,7 @@ def execute
return 1
end
+ @logger.log("Created package", :path => package_file)
return 0
rescue FPM::Util::ExecutableNotFound => e
@logger.error("Need executable '#{e}' to convert #{input_type} to #{output_type}")
View
@@ -406,7 +406,6 @@ def output(output_path)
safesystem("ar", "-qc", output_path, "debian-binary", "control.tar.gz", datatar)
end
end
- @logger.log("Created deb package", :path => output_path)
end # def output
def converted_from(origin)
View
@@ -383,8 +383,6 @@ def output(output_path)
# This should only output one rpm, should we verify this?
FileUtils.cp(rpmpath, output_path)
end
-
- @logger.log("Created rpm", :path => output_path)
end # def output
def prefix
View
@@ -0,0 +1,63 @@
+require "backports" # gem backports
+require "fpm/package"
+require "fpm/util"
+require "fileutils"
+require "fpm/package/dir"
+
+# Use a zip as a package.
+#
+# This provides no metadata. Both input and output are supported.
+class FPM::Package::Zip < FPM::Package
+
+ # Input a zipfile.
+ def input(input_path)
+ # use part of the filename as the package name
+ self.name = File.extname(input_path)[1..-1]
+
+ realpath = Pathname.new(input_path).realpath.to_s
+ ::Dir.chdir(build_path) do
+ safesystem("unzip", realpath)
+ end
+
+ # use dir to set stuff up properly, mainly so I don't have to reimplement
+ # the chdir/prefix stuff special for zip.
+ dir = convert(FPM::Package::Dir)
+ if attributes[:chdir]
+ dir.attributes[:chdir] = File.join(build_path, attributes[:chdir])
+ else
+ dir.attributes[:chdir] = build_path
+ end
+
+ cleanup_staging
+ # Tell 'dir' to input "." and chdir/prefix will help it figure out the
+ # rest.
+ dir.input(".")
+ @staging_path = dir.staging_path
+ dir.cleanup_build
+ end # def input
+
+ # Output a tarball.
+ #
+ # If the output path ends predictably (like in .tar.gz) it will try to obey
+ # the compression type.
+ def output(output_path)
+ output_check(output_path)
+
+ files = Find.find(staging_path).to_a
+ safesystem("zip", output_path, *files)
+ end # def output
+
+ # Generate the proper tar flags based on the path name.
+ def tar_compression_flag(path)
+ case path
+ when /\.tar\.bz2$/
+ return "-j"
+ when /\.tar\.gz$|\.tgz$/
+ return "-z"
+ when /\.tar\.xz$/
+ return "-J"
+ else
+ return nil
+ end
+ end # def tar_compression_flag
+end # class FPM::Package::Tar
View
@@ -30,6 +30,13 @@ def program_in_path?(program)
return envpath.select { |p| File.executable?(File.join(p, program)) }.any?
end # def program_in_path
+ def program_exists?(program)
+ # Scan path to find the executable
+ # Do this to help the user get a better error message.
+ return program_in_path?(program) if !program.include?("/")
+ return File.executable?(program)
+ end # def program_exists?
+
def default_shell
shell = ENV["SHELL"]
return "/bin/sh" if shell.nil? || shell.empty?
@@ -45,9 +52,7 @@ def safesystem(*args)
end
program = args[0]
- # Scan path to find the executable
- # Do this to help the user get a better error message.
- if !program.include?("/") and !program_in_path?(program)
+ if !program_exists?(program)
raise ExecutableNotFound.new(program)
end
@@ -79,7 +84,7 @@ def safesystem(*args)
return success
end # def safesystem
-# Run a command safely in a way that captures output and status.
+ # Run a command safely in a way that captures output and status.
def safesystemout(*args)
if args.size == 1
args = [ ENV["SHELL"], "-c", args[0] ]
@@ -2,7 +2,7 @@
require "fpm" # local
require "fpm/package/cpan" # local
-have_cpanm = program_in_path?("cpanm")
+have_cpanm = program_exists?("cpanm")
if !have_cpanm
Cabin::Channel.get("rspec") \
.warn("Skipping CPAN#input tests because 'cpanm' isn't in your PATH")
@@ -6,7 +6,7 @@
describe FPM::Package::Deb do
# dpkg-deb lets us query deb package files.
# Comes with debian and ubuntu systems.
- have_dpkg_deb = program_in_path?("dpkg-deb")
+ have_dpkg_deb = program_exists?("dpkg-deb")
if !have_dpkg_deb
Cabin::Channel.get("rspec") \
.warn("Skipping some deb tests because 'dpkg-deb' isn't in your PATH")
@@ -29,7 +29,7 @@
it "should default to native" do
expected = ""
- if program_in_path?("dpkg")
+ if program_exists?("dpkg")
expected = %x{dpkg --print-architecture}.chomp
end
@@ -2,7 +2,7 @@
require "fpm" # local
require "fpm/package/gem" # local
-have_gem = program_in_path?("gem")
+have_gem = program_exists?("gem")
if !have_gem
Cabin::Channel.get("rspec") \
.warn("Skipping Gem#input tests because 'gem' isn't in your PATH")
@@ -3,7 +3,7 @@
require "fpm/package/python" # local
def python_usable?
- return program_in_path?("python") && program_in_path?("easy_install")
+ return program_exists?("python") && program_exists?("easy_install")
end
if !python_usable?
@@ -5,7 +5,7 @@
require "arr-pm/file" # gem 'arr-pm'
require "stud/temporary" # gem 'stud'
-if !program_in_path?("rpmbuild")
+if !program_exists?("rpmbuild")
Cabin::Channel.get("rspec") \
.warn("Skipping RPM#output tests because 'rpmbuild' isn't in your PATH")
end
@@ -110,7 +110,7 @@ def subject.render_template; @rpmspec = template("rpm.erb").result(binding); end
end # context
end
- describe "#output", :if => program_in_path?("rpmbuild") do
+ describe "#output", :if => program_exists?("rpmbuild") do
context "package attributes" do
before :each do
@target = Stud::Temporary.pathname
@@ -312,7 +312,7 @@ def subject.render_template; @rpmspec = template("rpm.erb").result(binding); end
end # package attributes
end # #output
- describe "regressions should not occur", :if => program_in_path?("rpmbuild") do
+ describe "regressions should not occur", :if => program_exists?("rpmbuild") do
before :each do
@tempfile_handle =
@target = Stud::Temporary.pathname
@@ -392,7 +392,7 @@ def subject.render_template; @rpmspec = template("rpm.erb").result(binding); end
end
end # regression stuff
- describe "#output with digest and compression settings", :if => program_in_path?("rpmbuild") do
+ describe "#output with digest and compression settings", :if => program_exists?("rpmbuild") do
context "bzip2/sha1" do
before :each do
@target = Stud::Temporary.pathname
View
@@ -8,7 +8,7 @@
# put "lib" in RUBYLIB
$: << File.join(File.dirname(File.dirname(__FILE__)), "lib")
-# for method "program_in_path?" etc
+# for method "program_exists?" etc
require "fpm/util"
include FPM::Util

0 comments on commit 0b3b260

Please sign in to comment.