Class: Packtory::Command
- Inherits:
-
Object
- Object
- Packtory::Command
- Defined in:
- lib/packtory/command.rb
Class Method Summary collapse
Instance Method Summary collapse
- #detect_deps(argv) ⇒ Object
- #detect_envs(argv) ⇒ Object
- #detect_gemfile(argv) ⇒ Object
- #detect_package_output(argv) ⇒ Object
- #detect_specfile(argv) ⇒ Object
- #exec_fpm ⇒ Object
- #run(argv) ⇒ Object
- #say(msg) ⇒ Object
- #test_dumpinfo(argv) ⇒ Object
Class Method Details
.run(argv) ⇒ Object
5 6 7 |
# File 'lib/packtory/command.rb', line 5 def self.run(argv) self.new.run(argv) end |
Instance Method Details
#detect_deps(argv) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/packtory/command.rb', line 125 def detect_deps(argv) @deps = { } if ENV['PACKAGE_RUBY_VERSION'] && !ENV['PACKAGE_RUBY_VERSION'].empty? @ruby_version = ENV['PACKAGE_RUBY_VERSION'] say 'Using ruby deps : %s' % @ruby_version else @ruby_version = nil say 'Using ruby deps : latest' end Packtory.config[:dependencies]['ruby'] = @ruby_version @deps['ruby'] = @ruby_version if ENV['PACKAGE_DEPENDENCIES'] deps = ENV['PACKAGE_DEPENDENCIES'].split(',') deps.each do |d| if d =~ /^([^\<\>\=]+)(.+)?$/ pname = $~[1] pver = $~[2] Packtory.config[:dependencies][pname] = pver @deps[pname] = pver end end end self end |
#detect_envs(argv) ⇒ Object
9 10 11 12 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 |
# File 'lib/packtory/command.rb', line 9 def detect_envs(argv) if ENV['FPM_EXEC_PATH'] @fpm_exec_path = File.(ENV['FPM_EXEC_PATH']) else @fpm_exec_path = Packtory.bin_support_fpm_path end if !ENV['FPM_USE_RUBY_PATH'].nil? && !ENV['FPM_USE_RUBY_PATH'].empty? Packtory.config[:fpm_use_ruby_path] = ENV['FPM_USE_RUBY_PATH'] elsif !ENV['RUBY_PATH'].nil? && !ENV['RUBY_PATH'].empty? Packtory.config[:fpm_use_ruby_path] = ENV['RUBY_PATH'] end if @fpm_exec_path.nil? || @fpm_exec_path.empty? say 'ERROR: `fpm` executable is not in path. Perhaps, install fpm first?' exit 1 end if argv[0].nil? || argv[0].empty? say 'ERROR: Build path not specified, aborting.' exit 1 end @build_path = File.(argv[0]) unless File.exists?(@build_path) say 'ERROR: Build path %s do not exist, aborting.' % @build_path exit 1 end say 'Using fpm path : %s' % @fpm_exec_path unless Packtory.config[:fpm_use_ruby_path].nil? say 'Fpm using ruby : %s' % Packtory.config[:fpm_use_ruby_path] end say 'Using fpm : %s' % `#{exec_fpm} -v`.strip say 'Using build path : %s' % @build_path Packtory.config[:fpm_exec_path] = @fpm_exec_path Packtory.config[:path] = @build_path if ENV['FPM_EXEC_VERBOSE'] && ENV['FPM_EXEC_VERBOSE'] == '1' Packtory.config[:fpm_exec_verbose] = true end if !ENV['FPM_EXEC_LOG'].nil? && !ENV['FPM_EXEC_LOG'].empty? Packtory.config[:fpm_exec_verbose] = true Packtory.config[:fpm_exec_log] = ENV['FPM_EXEC_LOG'] end self end |
#detect_gemfile(argv) ⇒ Object
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 |
# File 'lib/packtory/command.rb', line 99 def detect_gemfile(argv) @bundle_gemfile = nil if ENV['BUNDLE_GEMFILE'] && !ENV['BUNDLE_GEMFILE'].empty? @bundle_gemfile = ENV['BUNDLE_GEMFILE'] unless @bundle_gemfile =~ /^\/(.+)$/ @bundle_gemfile = File.join(@build_path, @bundle_gemfile) end unless File.exists?(@bundle_gemfile) say 'ERROR: Specified bundle gemfile %s not found, aborting.' % @bundle_gemfile exit 1 end say 'Using Gemfile : %s' % @bundle_gemfile Packtory.config[:gemfile] = @bundle_gemfile end if ENV['BUNDLER_INCLUDE'] Packtory.config[:bundler_include] = true end self end |
#detect_package_output(argv) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/packtory/command.rb', line 155 def detect_package_output(argv) packages = [ ] if ENV['PACKAGE_OUTPUT'] == 'rpm' packages << :rpm elsif ENV['PACKAGE_OUTPUT'] == 'deb' packages << :deb elsif ENV['PACKAGE_OUTPUT'] == 'tgz' packages << :tgz elsif ENV['PACKAGE_OUTPUT'] == 'brew' packages << :brew else packages << :deb end say 'Package output : %s' % packages.join(', ') Packtory.config[:packages] = packages if ENV['PACKAGE_PATH'] pkg_path = File.(ENV['PACKAGE_PATH']) say 'Package path : %s' % pkg_path Packtory.config[:pkg_path] = pkg_path end self end |
#detect_specfile(argv) ⇒ 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 |
# File 'lib/packtory/command.rb', line 69 def detect_specfile(argv) if ENV['GEM_SPECFILE'] @gemspec_file = ENV['GEM_SPECFILE'] unless @gemspec_file =~ /^\/(.+)$/ @gemspec_file = File.join(@build_path, @gemspec_file) end unless File.exists?(@gemspec_file) say 'ERROR: Specified gemspec file %s not found, aborting.' % @gemspec_file exit 1 end else paths = Dir.glob(File.join(@build_path, '/*.gemspec')) if paths.empty? say 'ERROR: No gemspec file found, aborting.' exit 1 elsif paths.count > 1 say 'ERROR: Multiple gemspec file found, aborting.' exit 1 end @gemspec_file = paths[0] end say 'Using spec file : %s' % @gemspec_file Packtory.config[:gemspec] = @gemspec_file self end |
#exec_fpm ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/packtory/command.rb', line 61 def exec_fpm if Packtory.config[:fpm_use_ruby_path].nil? @fpm_exec_path else 'env FPM_USE_RUBY_PATH=%s %s' % [ Packtory.config[:fpm_use_ruby_path], @fpm_exec_path ] end end |
#run(argv) ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/packtory/command.rb', line 201 def run(argv) detect_envs(argv) $:.unshift(@build_path) Dir.chdir(@build_path) detect_specfile(argv) detect_gemfile(argv) detect_deps(argv) detect_package_output(argv) say '==================' Packtory.setup if ENV['TEST_DUMPINFO'] test_dumpinfo(argv) elsif ENV['TEST_NOBUILD'] # do nothing else Packtory.build_package end end |
#say(msg) ⇒ Object
225 226 227 |
# File 'lib/packtory/command.rb', line 225 def say(msg) puts msg end |
#test_dumpinfo(argv) ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/packtory/command.rb', line 183 def test_dumpinfo(argv) dump_file = File.(ENV['TEST_DUMPINFO']) info_h = { :version => ::Packtory::VERSION, :fpm_version => `#{@fpm_exec_path} -v`.strip }.merge(Packtory.config) File.open(dump_file, 'w') do |f| f.write(YAML.dump(info_h)) end say 'Created dump file: %s' % dump_file say File.read(dump_file) self end |