Class: Packagit::Executable
- Inherits:
-
Object
- Object
- Packagit::Executable
- Defined in:
- lib/packagit/executable.rb
Constant Summary collapse
- RELEASES_DIR =
'pkg'
Instance Method Summary collapse
-
#initialize(argv) ⇒ Executable
constructor
A new instance of Executable.
- #invoke! ⇒ Object
Constructor Details
#initialize(argv) ⇒ Executable
Returns a new instance of Executable.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/packagit/executable.rb', line 13 def initialize(argv) pwd = Pathname.new(Dir.pwd) @config = pwd.join(".packagit") version = "undefined" if @config.exist? if @specification = Packagit::Specification.load(@config) version = @specification.version end end @options = { checksums: true, releases: pwd.join(RELEASES_DIR, version), packagers: pwd.join("packagers"), tmp: pwd.join("tmp", "packagit") } optparse = OptionParser.new do |opts| opts. = "Usage: packagit [options]" opts.on('-s', '--[no-]checksums', "Compute check sums (default: #{@options[:checksums]})") do |cs| @options[:checksums] = cs end opts.on('-b', '--builds BUILD[,...]', 'Select builds') do |builds| @options[:builds] ||= [] @options[:builds] += builds.split(/[\,[[:space:]]]+/) end opts.on('-p', '--packagers PATH', "Define packagers directory (default: #{@options[:packagers]})") do |path| @options[:packagers] = Pathname.new(File.(path)) end opts.on('-r', '--releases PATH', "Define releases directory (default: #{@options[:releases]})") do |path| @options[:releases] = Pathname.new(File.(path)) end opts.on('-t', '--tmp PATH', "Define temporary directory (default: #{@options[:tmp]})") do |path| @options[:tmp] = Pathname.new(path). end opts.on('-h', '--help', 'Display this screen') do puts opts exit end end optparse.parse! unless @specification puts "Need a config file (.packagit)" exit(1) end unless @builds = @options.delete(:builds) @builds ||= [] if @options[:packagers].exist? Dir.chdir(@options[:packagers]) do @builds += Dir.glob("*") end end end @builds.sort! end |
Instance Method Details
#invoke! ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/packagit/executable.rb', line 69 def invoke! exit(0) if @builds.empty? FileUtils.rm_rf(@options[:tmp]) # Prepare a clean export of the files reference = @options[:tmp].join("reference") FileUtils.mkdir_p(reference) for file in @specification.files source = Pathname.new(file). dest = reference.join(file) FileUtils.mkdir_p(dest.dirname) FileUtils.cp(source, dest) unless source.directory? end FileUtils.rm_rf(@options[:releases]) # Launch builds STDOUT.sync = true now = Time.now builds_dir = @options[:tmp].join("builds") for build in @builds print "Build #{build}... " build_dir = builds_dir.join(build) FileUtils.mkdir_p(build_dir.dirname) FileUtils.cp_r(reference, build_dir) script = @options[:packagers].join(build).join("build") release = @options[:releases].join(build) FileUtils.mkdir_p(release) command = "BUILD_APP=#{@specification.name}" command << " BUILD_VERSION=#{@specification.version}" command << " BUILD_DIR=#{build_dir}" command << " BUILD_TYPE=#{build}" command << " BUILD_LOG=#{builds_dir.join(build + '.log')}" command << " BUILD_RELEASE=#{release}" command << " #{script} > source.log" if script.exist? puts command `#{command}` else puts "No script! (#{command})" end unless release.exist? File.write(@options[:releases].join(build, ".placeholder"), "#{@specification.name} #{@specification.version} #{build}") end end if @options[:checksums] Dir.chdir(@options[:releases]) do files = `find . -type f`.split(/\s+/) for algo in %w(sha256 sha1 md5) command = "#{algo}sum #{files.join(' ')} > " + @options[:releases].join("#{algo.upcase}SUMS").to_s puts command system(command) end end end end |