r7z 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/7z/7-zip.chm +0 -0
- data/7z/7za.exe +0 -0
- data/History.txt +4 -0
- data/README.txt +48 -0
- data/Rakefile +29 -0
- data/bin/r7z +8 -0
- data/lib/r7z.rb +49 -0
- data/lib/r7z/compress.rb +111 -0
- data/nbproject/private/private.properties +3 -0
- data/nbproject/private/rake-d.txt +34 -0
- data/nbproject/project.properties +8 -0
- data/nbproject/project.xml +15 -0
- data/spec/r7z_spec.rb +7 -0
- data/spec/spec_helper.rb +16 -0
- data/tasks/ann.rake +80 -0
- data/tasks/bones.rake +20 -0
- data/tasks/gem.rake +201 -0
- data/tasks/git.rake +40 -0
- data/tasks/notes.rake +27 -0
- data/tasks/post_load.rake +34 -0
- data/tasks/rdoc.rake +50 -0
- data/tasks/rubyforge.rake +55 -0
- data/tasks/setup.rb +300 -0
- data/tasks/spec.rake +54 -0
- data/tasks/svn.rake +47 -0
- data/tasks/test.rake +40 -0
- data/test/test_r7z.rb +21 -0
- metadata +94 -0
data/7z/7-zip.chm
ADDED
Binary file
|
data/7z/7za.exe
ADDED
Binary file
|
data/History.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
r7z
|
2
|
+
by FIXME (your name)
|
3
|
+
FIXME (url)
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
FIXME (describe your package)
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* FIXME (list of features or problems)
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
FIXME (code sample of usage)
|
16
|
+
|
17
|
+
== REQUIREMENTS:
|
18
|
+
|
19
|
+
* FIXME (list of requirements)
|
20
|
+
|
21
|
+
== INSTALL:
|
22
|
+
|
23
|
+
* FIXME (sudo gem install, anything else)
|
24
|
+
|
25
|
+
== LICENSE:
|
26
|
+
|
27
|
+
(The MIT License)
|
28
|
+
|
29
|
+
Copyright (c) 2008 FIXME (different license?)
|
30
|
+
|
31
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
32
|
+
a copy of this software and associated documentation files (the
|
33
|
+
'Software'), to deal in the Software without restriction, including
|
34
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
35
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
36
|
+
permit persons to whom the Software is furnished to do so, subject to
|
37
|
+
the following conditions:
|
38
|
+
|
39
|
+
The above copyright notice and this permission notice shall be
|
40
|
+
included in all copies or substantial portions of the Software.
|
41
|
+
|
42
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
43
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
44
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
45
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
46
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
47
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
48
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Look in the tasks/setup.rb file for the various options that can be
|
2
|
+
# configured in this Rakefile. The .rake files in the tasks directory
|
3
|
+
# are where the options are used.
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'bones'
|
7
|
+
Bones.setup
|
8
|
+
rescue LoadError
|
9
|
+
begin
|
10
|
+
load 'tasks/setup.rb'
|
11
|
+
rescue LoadError
|
12
|
+
raise RuntimeError, '### please install the "bones" gem ###'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
ensure_in_path 'lib'
|
17
|
+
require 'r7z'
|
18
|
+
|
19
|
+
task :default => 'spec:run'
|
20
|
+
|
21
|
+
PROJ.name = 'r7z'
|
22
|
+
PROJ.authors = 'Yohan BARUKH'
|
23
|
+
PROJ.email = 'yohan_barukh@systalians.com'
|
24
|
+
PROJ.version = R7z::VERSION
|
25
|
+
PROJ.rubyforge.name = 'r7z'
|
26
|
+
|
27
|
+
PROJ.spec.opts << '--color'
|
28
|
+
|
29
|
+
# EOF
|
data/bin/r7z
ADDED
data/lib/r7z.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
|
2
|
+
module R7z
|
3
|
+
|
4
|
+
# :stopdoc:
|
5
|
+
VERSION = '1.0.2'
|
6
|
+
LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
|
7
|
+
PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
|
8
|
+
# :startdoc:
|
9
|
+
|
10
|
+
# Returns the version string for the library.
|
11
|
+
#
|
12
|
+
def self.version
|
13
|
+
VERSION
|
14
|
+
end
|
15
|
+
|
16
|
+
# Returns the library path for the module. If any arguments are given,
|
17
|
+
# they will be joined to the end of the libray path using
|
18
|
+
# <tt>File.join</tt>.
|
19
|
+
#
|
20
|
+
def self.libpath( *args )
|
21
|
+
args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Returns the lpath for the module. If any arguments are given,
|
25
|
+
# they will be joined to the end of the path using
|
26
|
+
# <tt>File.join</tt>.
|
27
|
+
#
|
28
|
+
def self.path( *args )
|
29
|
+
args.empty? ? PATH : ::File.join(PATH, args.flatten)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Utility method used to require all files ending in .rb that lie in the
|
33
|
+
# directory below this file that has the same name as the filename passed
|
34
|
+
# in. Optionally, a specific _directory_ name can be passed in such that
|
35
|
+
# the _filename_ does not have to be equivalent to the directory.
|
36
|
+
#
|
37
|
+
def self.require_all_libs_relative_to( fname, dir = nil )
|
38
|
+
dir ||= ::File.basename(fname, '.*')
|
39
|
+
search_me = ::File.expand_path(
|
40
|
+
::File.join(::File.dirname(fname), dir, '**', '*.rb'))
|
41
|
+
|
42
|
+
Dir.glob(search_me).sort.each {|rb| require rb}
|
43
|
+
end
|
44
|
+
|
45
|
+
end # module R7z
|
46
|
+
|
47
|
+
R7z.require_all_libs_relative_to(__FILE__)
|
48
|
+
|
49
|
+
# EOF
|
data/lib/r7z/compress.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
module R7z
|
2
|
+
|
3
|
+
PATH_TO_7Z = File.expand_path("7za.exe", File.join(File.dirname(__FILE__), "..", "..", "7z"))
|
4
|
+
BUFFER_LENGTH = 1024 * 1024 * 8
|
5
|
+
|
6
|
+
class Compress
|
7
|
+
|
8
|
+
attr_accessor :archive_file, :inner_file, :inner_directory, :source_file
|
9
|
+
|
10
|
+
def initialize(hash = {})
|
11
|
+
hash.each { |k, v|
|
12
|
+
self.send("#{k}=".to_sym, v)
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
#
|
17
|
+
# -Extraire un repertoire
|
18
|
+
# <pre>
|
19
|
+
# cpx = R7z::Compress.new(:archive_file => 'C:/temporaire/20090520.7z', :inner_directory => '20090520/SAG1')<br>
|
20
|
+
# cpx.extract_to('c:/temporaire/SAG1')
|
21
|
+
# </pre>
|
22
|
+
#
|
23
|
+
# -Extraire un fichier (l'archive contient une arborescence)
|
24
|
+
# <pre>
|
25
|
+
# cpx = R7z::Compress.new(:archive_file => 'C:/temporaire/20090520.7z', :inner_file => '20090520/SAG1/SAG.log')<br>
|
26
|
+
# cpx.extract_to('c:/temporaire/SAG1.log')
|
27
|
+
# </pre>
|
28
|
+
#
|
29
|
+
# -Extraire un fichier (l'archive contient un seul fichier)
|
30
|
+
# <pre>
|
31
|
+
# cpx = R7z::Compress.new(:archive_file => 'C:/temporaire/RE_PROD_PRCGestionCorbeille_20090520_1113-20090520.zip', :inner_file => <b>'*.log'</b>)<br>
|
32
|
+
# cpx.extract_to('c:/temporaire/PRC-20090520.log')
|
33
|
+
# </pre>
|
34
|
+
#
|
35
|
+
def extract_to(destination, mode = 'rb', options = {})
|
36
|
+
if self.inner_file
|
37
|
+
open(destination, "w") do |w|
|
38
|
+
w.binmode
|
39
|
+
IO.popen(self.cmd_extract_string(destination, options), mode) { |io|
|
40
|
+
s = String.new
|
41
|
+
while (s = io.read(BUFFER_LENGTH, s))
|
42
|
+
w << s
|
43
|
+
end
|
44
|
+
}
|
45
|
+
end
|
46
|
+
else
|
47
|
+
%x{#{self.cmd_extract_string(destination, options)}}
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
#
|
52
|
+
# -Compresser un fichier
|
53
|
+
# <pre>
|
54
|
+
# cpx = R7z::Compress.new(:source_file => 'C:/AAG/R_AnalyseLogs/workdir/logs/PRCGestionCorbeille_20091102_1113.LOG', :archive_file => 'C:/temporaire/PRC_Affectation/Resultat/LOGS/PRCGestionCorbeille_20091102.zip')
|
55
|
+
# cpx.compress
|
56
|
+
# </pre>
|
57
|
+
#
|
58
|
+
def compress(format = 'zip', options = {})
|
59
|
+
cmd = "\"#{PATH_TO_7Z}\" a -t#{format} \"#{self.archive_file}\" \"#{self.source_file}\" "
|
60
|
+
cmd = "cmd /c \"#{cmd}\""
|
61
|
+
$stderr.puts "cmd_compress=#{cmd}" if options[:verbose]
|
62
|
+
%x{#{cmd}}
|
63
|
+
end
|
64
|
+
|
65
|
+
def execute_7z_command(*attrs)
|
66
|
+
options = attrs.extract_options! || {}
|
67
|
+
cmd = [PATH_TO_7Z] + attrs
|
68
|
+
cmd = cmd.collect{|p| p.include?(' ') ? "\"#{p}\"" : p}.join(' ')
|
69
|
+
cmd = "cmd /c \"#{cmd}\""
|
70
|
+
|
71
|
+
$stderr.puts "cmd=#{cmd}" if options[:verbose]
|
72
|
+
%x{#{cmd}}
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
def cmd_extract_string(destination, options = {})
|
77
|
+
cmd = nil
|
78
|
+
if all_inner_file?
|
79
|
+
cmd = "\"#{PATH_TO_7Z}\" e \"#{self.archive_file}\" -o\"#{destination}\" -y"
|
80
|
+
elsif self.inner_directory
|
81
|
+
cmd = "\"#{PATH_TO_7Z}\" x \"#{self.archive_file}\" -o\"#{destination}\" #{self.inner_directory} -y"
|
82
|
+
elsif self.inner_file
|
83
|
+
cmd = "\"#{PATH_TO_7Z}\" e \"#{self.archive_file}\" -so \"#{self.inner_file}\""
|
84
|
+
end
|
85
|
+
cmd = "cmd /c \"#{cmd}\""
|
86
|
+
$stderr.puts "cmd_extract=#{cmd}" if options[:verbose]
|
87
|
+
cmd
|
88
|
+
end
|
89
|
+
|
90
|
+
def all_inner_file?
|
91
|
+
self.inner_file.nil? && self.inner_directory.nil?
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
class Array
|
99
|
+
# Extracts options from a set of arguments. Removes and returns the last
|
100
|
+
# element in the array if it's a hash, otherwise returns a blank hash.
|
101
|
+
#
|
102
|
+
# def options(*args)
|
103
|
+
# args.extract_options!
|
104
|
+
# end
|
105
|
+
#
|
106
|
+
# options(1, 2) # => {}
|
107
|
+
# options(1, 2, :a => :b) # => {:a=>:b}
|
108
|
+
def extract_options!
|
109
|
+
last.is_a?(::Hash) ? pop : {}
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
ann=Alias to ann:announcement
|
2
|
+
ann\:announcement=Create an announcement file
|
3
|
+
ann\:email=Send an email announcement
|
4
|
+
ann\:prereqs=
|
5
|
+
announcement.txt=
|
6
|
+
clean=Remove any temporary products.
|
7
|
+
clobber=Remove any generated file. / Remove all build products
|
8
|
+
default=
|
9
|
+
doc=Alias to doc:rdoc
|
10
|
+
doc/index.html=
|
11
|
+
doc\:clobber=
|
12
|
+
doc\:clobber_rdoc=Remove rdoc products
|
13
|
+
doc\:clobber_ri=
|
14
|
+
doc\:rdoc=Build the rdoc HTML Files
|
15
|
+
doc\:rerdoc=Force a rebuild of the RDOC files
|
16
|
+
doc\:ri=Generate ri locally for testing
|
17
|
+
gem=Alias to gem:package
|
18
|
+
gem\:cleanup=Cleanup the gem
|
19
|
+
gem\:clobber=
|
20
|
+
gem\:clobber_package=Remove package products
|
21
|
+
gem\:debug=Show information about the gem
|
22
|
+
gem\:install=Install the gem
|
23
|
+
gem\:package=Build all the packages
|
24
|
+
gem\:prereqs=
|
25
|
+
gem\:reinstall=Reinstall the gem
|
26
|
+
gem\:repackage=Force a rebuild of the package files
|
27
|
+
gem\:spec=Write the gemspec
|
28
|
+
gem\:uninstall=Uninstall the gem
|
29
|
+
pkg=
|
30
|
+
pkg/r7z-1.0.2=
|
31
|
+
pkg/r7z-1.0.2.tgz=
|
32
|
+
pkg/r7z-1.0.2/r7z-1.0.2.gem=
|
33
|
+
test=Alias to test:run
|
34
|
+
test\:run=Run tests for run
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project xmlns="http://www.netbeans.org/ns/project/1">
|
3
|
+
<type>org.netbeans.modules.ruby.rubyproject</type>
|
4
|
+
<configuration>
|
5
|
+
<data xmlns="http://www.netbeans.org/ns/ruby-project/1">
|
6
|
+
<name>R7z</name>
|
7
|
+
<source-roots>
|
8
|
+
<root id="src.dir"/>
|
9
|
+
</source-roots>
|
10
|
+
<test-roots>
|
11
|
+
<root id="test.src.dir" name="test"/>
|
12
|
+
</test-roots>
|
13
|
+
</data>
|
14
|
+
</configuration>
|
15
|
+
</project>
|
data/spec/r7z_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
|
2
|
+
require File.expand_path(
|
3
|
+
File.join(File.dirname(__FILE__), %w[.. lib r7z]))
|
4
|
+
|
5
|
+
Spec::Runner.configure do |config|
|
6
|
+
# == Mock Framework
|
7
|
+
#
|
8
|
+
# RSpec uses it's own mocking framework by default. If you prefer to
|
9
|
+
# use mocha, flexmock or RR, uncomment the appropriate line:
|
10
|
+
#
|
11
|
+
# config.mock_with :mocha
|
12
|
+
# config.mock_with :flexmock
|
13
|
+
# config.mock_with :rr
|
14
|
+
end
|
15
|
+
|
16
|
+
# EOF
|
data/tasks/ann.rake
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
|
2
|
+
begin
|
3
|
+
require 'bones/smtp_tls'
|
4
|
+
rescue LoadError
|
5
|
+
require 'net/smtp'
|
6
|
+
end
|
7
|
+
require 'time'
|
8
|
+
|
9
|
+
namespace :ann do
|
10
|
+
|
11
|
+
# A prerequisites task that all other tasks depend upon
|
12
|
+
task :prereqs
|
13
|
+
|
14
|
+
file PROJ.ann.file do
|
15
|
+
ann = PROJ.ann
|
16
|
+
puts "Generating #{ann.file}"
|
17
|
+
File.open(ann.file,'w') do |fd|
|
18
|
+
fd.puts("#{PROJ.name} version #{PROJ.version}")
|
19
|
+
fd.puts(" by #{Array(PROJ.authors).first}") if PROJ.authors
|
20
|
+
fd.puts(" #{PROJ.url}") if PROJ.url.valid?
|
21
|
+
fd.puts(" (the \"#{PROJ.release_name}\" release)") if PROJ.release_name
|
22
|
+
fd.puts
|
23
|
+
fd.puts("== DESCRIPTION")
|
24
|
+
fd.puts
|
25
|
+
fd.puts(PROJ.description)
|
26
|
+
fd.puts
|
27
|
+
fd.puts(PROJ.changes.sub(%r/^.*$/, '== CHANGES'))
|
28
|
+
fd.puts
|
29
|
+
ann.paragraphs.each do |p|
|
30
|
+
fd.puts "== #{p.upcase}"
|
31
|
+
fd.puts
|
32
|
+
fd.puts paragraphs_of(PROJ.readme_file, p).join("\n\n")
|
33
|
+
fd.puts
|
34
|
+
end
|
35
|
+
fd.puts ann.text if ann.text
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
desc "Create an announcement file"
|
40
|
+
task :announcement => ['ann:prereqs', PROJ.ann.file]
|
41
|
+
|
42
|
+
desc "Send an email announcement"
|
43
|
+
task :email => ['ann:prereqs', PROJ.ann.file] do
|
44
|
+
ann = PROJ.ann
|
45
|
+
from = ann.email[:from] || Array(PROJ.authors).first || PROJ.email
|
46
|
+
to = Array(ann.email[:to])
|
47
|
+
|
48
|
+
### build a mail header for RFC 822
|
49
|
+
rfc822msg = "From: #{from}\n"
|
50
|
+
rfc822msg << "To: #{to.join(',')}\n"
|
51
|
+
rfc822msg << "Subject: [ANN] #{PROJ.name} #{PROJ.version}"
|
52
|
+
rfc822msg << " (#{PROJ.release_name})" if PROJ.release_name
|
53
|
+
rfc822msg << "\n"
|
54
|
+
rfc822msg << "Date: #{Time.new.rfc822}\n"
|
55
|
+
rfc822msg << "Message-Id: "
|
56
|
+
rfc822msg << "<#{"%.8f" % Time.now.to_f}@#{ann.email[:domain]}>\n\n"
|
57
|
+
rfc822msg << File.read(ann.file)
|
58
|
+
|
59
|
+
params = [:server, :port, :domain, :acct, :passwd, :authtype].map do |key|
|
60
|
+
ann.email[key]
|
61
|
+
end
|
62
|
+
|
63
|
+
params[3] = PROJ.email if params[3].nil?
|
64
|
+
|
65
|
+
if params[4].nil?
|
66
|
+
STDOUT.write "Please enter your e-mail password (#{params[3]}): "
|
67
|
+
params[4] = STDIN.gets.chomp
|
68
|
+
end
|
69
|
+
|
70
|
+
### send email
|
71
|
+
Net::SMTP.start(*params) {|smtp| smtp.sendmail(rfc822msg, from, to)}
|
72
|
+
end
|
73
|
+
end # namespace :ann
|
74
|
+
|
75
|
+
desc 'Alias to ann:announcement'
|
76
|
+
task :ann => 'ann:announcement'
|
77
|
+
|
78
|
+
CLOBBER << PROJ.ann.file
|
79
|
+
|
80
|
+
# EOF
|
data/tasks/bones.rake
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
if HAVE_BONES
|
3
|
+
|
4
|
+
namespace :bones do
|
5
|
+
|
6
|
+
desc 'Show the PROJ open struct'
|
7
|
+
task :debug do |t|
|
8
|
+
atr = if t.application.top_level_tasks.length == 2
|
9
|
+
t.application.top_level_tasks.pop
|
10
|
+
end
|
11
|
+
|
12
|
+
if atr then Bones::Debug.show_attr(PROJ, atr)
|
13
|
+
else Bones::Debug.show PROJ end
|
14
|
+
end
|
15
|
+
|
16
|
+
end # namespace :bones
|
17
|
+
|
18
|
+
end # HAVE_BONES
|
19
|
+
|
20
|
+
# EOF
|