-
Notifications
You must be signed in to change notification settings - Fork 30
/
archive_recipe.rb
38 lines (30 loc) · 964 Bytes
/
archive_recipe.rb
1
2
3
4
5
6
7
8
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
# encoding: utf-8
require 'tmpdir'
require_relative 'yaml_presenter'
class ArchiveRecipe
def initialize(recipe)
@recipe = recipe
end
def compress!
return if @recipe.archive_files.empty?
@recipe.setup_tar if @recipe.respond_to? :setup_tar
Dir.mktmpdir do |dir|
archive_path = File.join(dir, @recipe.archive_path_name)
FileUtils.mkdir_p(archive_path)
@recipe.archive_files.each do |glob|
`cp -r #{glob} #{archive_path}`
end
File.write("#{dir}/sources.yml", YAMLPresenter.new(@recipe).to_yaml)
print "Running 'archive' for #{@recipe.name} #{@recipe.version}... "
if @recipe.archive_filename.split('.').last == 'zip'
output_dir = Dir.pwd
Dir.chdir(dir) do
`zip #{File.join(output_dir, @recipe.archive_filename)} -r .`
end
else
`ls -A #{dir} | xargs tar czf #{@recipe.archive_filename} -C #{dir}`
end
puts 'OK'
end
end
end