Class: Vendorificator::Vendor::Archive
- Inherits:
-
Vendorificator::Vendor
- Object
- Vendorificator::Vendor
- Vendorificator::Vendor::Archive
- Defined in:
- lib/vendorificator/vendor/archive.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#conjured_checksum ⇒ Object
readonly
Returns the value of attribute conjured_checksum.
Attributes inherited from Vendorificator::Vendor
#args, #block, #environment, #name
Instance Method Summary collapse
- #conjure! ⇒ Object
- #conjure_commit_message ⇒ Object
-
#initialize(environment, name, args = {}, &block) ⇒ Archive
constructor
A new instance of Archive.
- #upstream_version ⇒ Object
Methods inherited from Vendorificator::Vendor
#===, [], arg_reader, #branch_name, #category, #compute_dependencies!, compute_dependencies!, each, #head, #in_branch, #inspect, install!, instances, #merged, #merged_tag, #merged_version, #needed?, #path, #run!, #shell, #status, #tag_message, #tag_name, #tag_name_base, #tagged_sha1, #to_s, #updatable?, #version, #work_dir, #work_subdir
Constructor Details
#initialize(environment, name, args = {}, &block) ⇒ Archive
Returns a new instance of Archive.
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 |
# File 'lib/vendorificator/vendor/archive.rb', line 14 def initialize(environment, name, args={}, &block) no_url_given = !args[:url] args[:url] ||= name args[:filename] ||= URI::parse(args[:url]).path.split('/').last case args[:filename] when /\.(tar\.|t)gz$/ args[:type] ||= :targz args[:unpack] ||= 'tar -xzf' when /\.tar\.bz2$/ args[:type] ||= :tarbz2 args[:unpack] ||= 'tar -xjf' when /\.zip$/ args[:type] ||= :zip args[:unpack] ||= 'unzip' when /\.[^\.][^\.]?[^\.]?[^\.]?$/ args[:type] ||= begin unless args[:unpack] raise RuntimeError, "Unknown file type #{$&.inspect}, please provide :unpack argument" end $& end else args[:basename] ||= args[:filename] args[:extname] ||= '' unless args[:unpack] || [:targz, :tarbz2, :zip].include?(args[:type]) raise RuntimeError, "Unknown file type for #{args[:filename].inspect}, please provide :unpack or :type argument" end end args[:basename] ||= $` args[:extname] ||= $& name = args[:basename] if no_url_given super(environment, name, args, &block) end |
Instance Attribute Details
#conjured_checksum ⇒ Object (readonly)
Returns the value of attribute conjured_checksum.
12 13 14 |
# File 'lib/vendorificator/vendor/archive.rb', line 12 def conjured_checksum @conjured_checksum end |
Instance Method Details
#conjure! ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/vendorificator/vendor/archive.rb', line 54 def conjure! shell.say_status :download, url archive = Tempfile.new([basename, extname]) archive.write( open(url).read ) archive.close @conjured_checksum = Digest::SHA256.file(archive.path).hexdigest raise RuntimeError, "Checksum error" if checksum && checksum!=conjured_checksum shell.say_status :unpack, filename system "#{unpack} #{Escape.shell_single_word archive.path}" if Dir.entries('.').length == 3 && !args[:no_strip_root] root = (Dir.entries('.') - %w(.. .)).first root_entries = Dir.entries(root) - %w(.. .) while root_entries.include?(root) FileUtils::mv root, root+"~" root << "~" end FileUtils::mv root_entries.map { |e| File.join(root, e) }, '.' FileUtils::rmdir root end super ensure archive.close archive.unlink end |
#conjure_commit_message ⇒ Object
83 84 85 86 87 |
# File 'lib/vendorificator/vendor/archive.rb', line 83 def rv = "Conjured archive #{name} from #{filename}\nOrigin: #{url}\nChecksum: #{conjured_checksum}\n" rv << "Version: #{version}\n" if version rv end |
#upstream_version ⇒ Object
79 80 81 |
# File 'lib/vendorificator/vendor/archive.rb', line 79 def upstream_version filename end |