Class: ZipTask

Inherits:
CLApp show all
Includes:
FileUtils
Defined in:
lib/rakeutils/ziptask.rb

Overview

Implements programmatic control of the 7Zip application.

Instance Method Summary collapse

Methods inherited from CLApp

#execute, #normalize_dir_path, #quote_all_values, #quote_value, #rubyize_path, #windowize_path

Constructor Details

#initializeZipTask

Constructor



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rakeutils/ziptask.rb', line 24

def initialize()
  super( find_app )

  app_path = find_app
  if app_path.nil? or app_path.empty?
    if Ktutils::OS.windows?
      raise "7Zip is not installed"
    else
      raise "7z not found"
    end
  end
end

Instance Method Details

#compress(src_path, archive_path) ⇒ Object

Compress all files within a directory.

src_path

Source directory. Path must use forward slashes.

archive_path

Destination file. Path must use forward slashes.



48
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
# File 'lib/rakeutils/ziptask.rb', line 48

def compress(src_path, archive_path)
  src_dir = File.dirname( File.expand_path( src_path ) )
  src_file = File.basename( src_path )
  archive_path = File.expand_path( archive_path )
  dest_dir = File.dirname( archive_path )

  puts "src_dir: #{src_dir}"
  puts "src_path: #{src_path}"
  puts "dest_dir: #{dest_dir}"
  puts "archive_path: #{archive_path}"

  # Create the destination dir if it doesn't exist.
  if( !File.exists?( dest_dir ) )
    File.makedirs( dest_dir, true )
  end

  cmd_line = "-tzip u #{archive_path} #{src_path}"

  cur_dir = pwd
  cd( src_dir )
    begin
      execute( cmd_line, false )
    rescue
      # do nothing
    end
  cd( cur_dir )
end

#find_appObject

initialize



37
38
39
40
41
42
43
# File 'lib/rakeutils/ziptask.rb', line 37

def find_app
  if Ktutils::OS.windows?
    app_home = "7za.exe"
  else
    app_path = `which 7z`.chomp
  end
end