Cross package maker. DEB/RPM generation or conversion. Derived from jordansissel/fpm.

⌈⌋ ⎇ branch:  cross package maker


Check-in [e40c10b115]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add --log=xxx support Supported log levels: error, warn, info, debug. --verbose is the same as --log=info --debug is the same as --log=debug --log=warn is the default Requested by mattgreenrocks on irc.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e40c10b1150dd39662e0497c488aa029d205a49b
User & Date: jls@semicomplete.com 2014-10-15 18:29:42
Context
2014-10-16
18:47
Merge pull request #772 from djhaskin987/feature/661 Feature/661 check-in: adc3cb9bcc user: jls@semicomplete.com tags: trunk
16:00
Check first for Build.PL, then for Makefile.PL check-in: a90240e8b0 user: daniel.haskin@storagecraft.com tags: trunk
2014-10-15
18:29
Add --log=xxx support Supported log levels: error, warn, info, debug. --verbose is the same as --log=info --debug is the same as --log=debug --log=warn is the default Requested by mattgreenrocks on irc. check-in: e40c10b115 user: jls@semicomplete.com tags: trunk
2014-10-07
18:58
Merge pull request #778 from nbrownus/master Allow removal of Vendor field for deb This can be done in the CLI by setting --vendor to an empty string. For example `--vendor ""` The default behavior "Vendor: none" still remains. check-in: f3092896a3 user: jls@semicomplete.com tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to lib/fpm/command.rb.

54
55
56
57
58
59
60










61
62
63
64
65
66
67
    "A path to prefix files with when building the target package. This may " \
    "be necessary for all input packages. For example, the 'gem' type will " \
    "prefix with your gem directory automatically."
  option ["-p", "--package"], "OUTPUT", "The package file path to output."
  option ["-f", "--force"], :flag, "Force output even if it will overwrite an " \
    "existing file", :default => false
  option ["-n", "--name"], "NAME", "The name to give to the package"










  option "--verbose", :flag, "Enable verbose output"
  option "--debug", :flag, "Enable debug output"
  option "--debug-workspace", :flag, "Keep any file workspaces around for " \
    "debugging. This will disable automatic cleanup of package staging and " \
    "build paths. It will also print which directories are available."
  option ["-v", "--version"], "VERSION", "The version to give to the package",
    :default => 1.0







>
>
>
>
>
>
>
>
>
>







54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
    "A path to prefix files with when building the target package. This may " \
    "be necessary for all input packages. For example, the 'gem' type will " \
    "prefix with your gem directory automatically."
  option ["-p", "--package"], "OUTPUT", "The package file path to output."
  option ["-f", "--force"], :flag, "Force output even if it will overwrite an " \
    "existing file", :default => false
  option ["-n", "--name"], "NAME", "The name to give to the package"

  loglevels = %w(error warn info debug)
  option "--log", "LEVEL", "Set the log level. Values: #{loglevels.join(", ")}.",
    :attribute_name => :log_level do |val|
    val.downcase.tap do |v|
      if !loglevels.include?(v)
        raise FPM::Package::InvalidArgument, "Invalid log level, #{v.inspect}. Must be one of: #{loglevels.join(", ")}"
      end
    end
  end # --log
  option "--verbose", :flag, "Enable verbose output"
  option "--debug", :flag, "Enable debug output"
  option "--debug-workspace", :flag, "Keep any file workspaces around for " \
    "debugging. This will disable automatic cleanup of package staging and " \
    "build paths. It will also print which directories are available."
  option ["-v", "--version"], "VERSION", "The version to give to the package",
    :default => 1.0
224
225
226
227
228
229
230






231
232
233
234
235
236
237
    # Short-circuit if someone simply runs `fpm --version`
    if ARGV == [ "--version" ]
      puts FPM::VERSION
      return 0
    end

    @logger.level = :warn







    if (stray_flags = args.grep(/^-/); stray_flags.any?)
      @logger.warn("All flags should be before the first argument " \
                   "(stray flags found: #{stray_flags}")
    end

    # Some older behavior, if you specify:







>
>
>
>
>
>







234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
    # Short-circuit if someone simply runs `fpm --version`
    if ARGV == [ "--version" ]
      puts FPM::VERSION
      return 0
    end

    @logger.level = :warn
    @logger.level = :info if verbose? # --verbose
    @logger.level = :debug if debug? # --debug
    if log_level
      @logger.level = log_level.to_sym
    end


    if (stray_flags = args.grep(/^-/); stray_flags.any?)
      @logger.warn("All flags should be before the first argument " \
                   "(stray flags found: #{stray_flags}")
    end

    # Some older behavior, if you specify:
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270

      @logger.fatal("Fix the above problems, and you'll be rolling packages in no time!")
      return 1
    end
    input_class = FPM::Package.types[input_type]
    output_class = FPM::Package.types[output_type]

    @logger.level = :info if verbose? # --verbose
    @logger.level = :debug if debug? # --debug

    input = input_class.new

    # Merge in package settings. 
    # The 'settings' stuff comes in from #apply_options, which goes through
    # all the options defined in known packages and puts them into our command.
    # Flags in packages defined as "--foo-bar" become named "--<packagetype>-foo-bar"
    # They are stored in 'settings' as :gem_foo_bar.







<
<
<







270
271
272
273
274
275
276



277
278
279
280
281
282
283

      @logger.fatal("Fix the above problems, and you'll be rolling packages in no time!")
      return 1
    end
    input_class = FPM::Package.types[input_type]
    output_class = FPM::Package.types[output_type]




    input = input_class.new

    # Merge in package settings. 
    # The 'settings' stuff comes in from #apply_options, which goes through
    # all the options defined in known packages and puts them into our command.
    # Flags in packages defined as "--foo-bar" become named "--<packagetype>-foo-bar"
    # They are stored in 'settings' as :gem_foo_bar.
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
    return 0
  rescue FPM::Util::ExecutableNotFound => e
    @logger.error("Need executable '#{e}' to convert #{input_type} to #{output_type}")
    return 1
  rescue FPM::InvalidPackageConfiguration => e
    @logger.error("Invalid package configuration: #{e}")
    return 1
  rescue FPM::Package::InvalidArgument => e
    @logger.error("Invalid package argument: #{e}")
    return 1
  rescue FPM::Util::ProcessFailed => e
    @logger.error("Process failed: #{e}")
    return 1
  ensure
    if debug_workspace?
      # only emit them if they have files
      [input, output].each do |plugin|







<
<
<







441
442
443
444
445
446
447



448
449
450
451
452
453
454
    return 0
  rescue FPM::Util::ExecutableNotFound => e
    @logger.error("Need executable '#{e}' to convert #{input_type} to #{output_type}")
    return 1
  rescue FPM::InvalidPackageConfiguration => e
    @logger.error("Invalid package configuration: #{e}")
    return 1



  rescue FPM::Util::ProcessFailed => e
    @logger.error("Process failed: #{e}")
    return 1
  ensure
    if debug_workspace?
      # only emit them if they have files
      [input, output].each do |plugin|
476
477
478
479
480
481
482



483
484
485
486
487
488
489
            ARGV.unshift(arg)
          end
        end
      end
    end

    super(*args)



  end # def run

  # A simple flag validator
  #
  # The goal of this class is to ensure the flags and arguments given
  # are a valid configuration.
  class Validator







>
>
>







486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
            ARGV.unshift(arg)
          end
        end
      end
    end

    super(*args)
  rescue FPM::Package::InvalidArgument => e
    @logger.error("Invalid package argument: #{e}")
    return 1
  end # def run

  # A simple flag validator
  #
  # The goal of this class is to ensure the flags and arguments given
  # are a valid configuration.
  class Validator

Added spec/fixtures/mockpackage.rb.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
require "fpm/namespace"
require "fpm/package"

class FPM::Package::Mock < FPM::Package
  def input(*args); end
  def output(*args); end
end

Changes to spec/fpm/command_spec.rb.

1
2
3
4

5
6
7
8
9
10
11
require "spec_setup"
require "stud/temporary"
require "fpm" # local
require "fpm/command" # local


describe FPM::Command do
  describe "--prefix"
  describe "-C"
  describe "-p / --package"
  describe "-f"
  describe "-n"




>







1
2
3
4
5
6
7
8
9
10
11
12
require "spec_setup"
require "stud/temporary"
require "fpm" # local
require "fpm/command" # local
require "fixtures/mockpackage"

describe FPM::Command do
  describe "--prefix"
  describe "-C"
  describe "-p / --package"
  describe "-f"
  describe "-n"
48
49
50
51
52
53
54








55


















          files = Dir.new(path).to_a - ['.', '..']
          insist { files.size } == 1
          insist { files[0] } =~ /example_/
        end
      end
    end
  end








end

























>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
          files = Dir.new(path).to_a - ['.', '..']
          insist { files.size } == 1
          insist { files[0] } =~ /example_/
        end
      end
    end
  end

  describe "--log" do
    subject { FPM::Command.new("fpm") }
    let (:args) { [ "-s", "mock", "-t", "mock" ] }

    context "when not given" do
      it "should not raise an exception" do
        subject.parse([*args])
      end
    end
    context "when given a valid log level" do
      it "should not raise an exception" do
        subject.parse([*args, "--log", "error"])
        subject.parse([*args, "--log", "warn"])
        subject.parse([*args, "--log", "info"])
        subject.parse([*args, "--log", "debug"])
      end
    end
    context "when given an invalid log level" do
      it "should raise an exception" do
        insist { subject.parse([*args, "--log", ""]) }.raises FPM::Package::InvalidArgument
        insist { subject.parse([*args, "--log", "whatever"]) }.raises FPM::Package::InvalidArgument
        insist { subject.parse([*args, "--log", "fatal"]) }.raises FPM::Package::InvalidArgument
      end
    end
  end
end