Sha256: e12066ec4886580fbcda9b915c04ba42cad94245910533e3a4126e15b0354aac
Contents?: true
Size: 1.9 KB
Versions: 51
Compression:
Stored size: 1.9 KB
Contents
module Processor def unzip_file(zip_file, target_dir, extract_file=nil, unzip_bin=nil) unzip = unzip_bin || 'unzip' if not File.exists? zip_file $log.writer.error "Zip file #{zip_file} does not exist!" exit 1 end if not File.exists? target_dir FileUtils.mkdir( target_dir ) $log.writer.debug "Create target directory #{target_dir}" end begin stdout = %x"#{unzip} -o \"#{zip_file}\" #{extract_file} -d \"#{target_dir}\"" $log.writer.debug stdout rescue Exception => e $log.writer.error "Can not extract Zipfile #{zip_file} to #{target_dir}" $log.writer.error e.message exit 1 end end module_function :unzip_file def tgz_file(tgz_file, source_dir, add_file=nil, tar_bin=nil) tar = tar_bin || 'tar' if not File.exists? source_dir $log.writer.error "Source directory #{source_dir} does not exist!" exit 1 end begin stdout = %x"#{tar} -c -z -C #{source_dir} -f #{tgz_file} #{add_file}" $log.writer.debug stdout rescue Exception => e $log.writer.error "Can not add files in #{source_dir} to Tar-Gz file #{tgz_file}" $log.writer.error e.message exit 1 end end module_function :tgz_file def untgz_file(tgz_file, target_dir, extract_file=nil, tar_bin=nil) tar = tar_bin || 'tar' if not File.exists? tgz_file $log.writer.error "Tar-Gz file #{tgz_file} does not exist!" exit 1 end if not File.exists? target_dir FileUtils.mkdir( target_dir ) $log.writer.debug "Create target directory #{target_dir}" end begin stdout = %x"#{tar} -x -z -C #{target_dir} -f #{tgz_file} #{extract_file}" $log.writer.debug stdout rescue Exception => e $log.writer.error "Can not extract Tar-Gz file #{tgz_file} to #{target_dir}" $log.writer.error e.message exit 1 end end module_function :untgz_file end
Version data entries
51 entries across 51 versions & 1 rubygems