Skip to content

Commit

Permalink
Merge pull request #635 from jordansissel/add-zip-support
Browse files Browse the repository at this point in the history
Add zip support
  • Loading branch information
jordansissel committed Feb 10, 2014
2 parents 701890d + 43bccc5 commit 51b93a4
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 18 deletions.
4 changes: 3 additions & 1 deletion lib/fpm/command.rb
Expand Up @@ -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
Expand All @@ -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}")
Expand Down
1 change: 0 additions & 1 deletion lib/fpm/package/deb.rb
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions lib/fpm/package/rpm.rb
Expand Up @@ -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
Expand Down
63 changes: 63 additions & 0 deletions lib/fpm/package/zip.rb
@@ -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
13 changes: 9 additions & 4 deletions lib/fpm/util.rb
Expand Up @@ -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?
Expand All @@ -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

Expand Down Expand Up @@ -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] ]
Expand Down
2 changes: 1 addition & 1 deletion spec/fpm/package/cpan_spec.rb
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions spec/fpm/package/deb_spec.rb
Expand Up @@ -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")
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion spec/fpm/package/gem_spec.rb
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion spec/fpm/package/python_spec.rb
Expand Up @@ -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?
Expand Down
8 changes: 4 additions & 4 deletions spec/fpm/package/rpm_spec.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_setup.rb
Expand Up @@ -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

Expand Down

0 comments on commit 51b93a4

Please sign in to comment.