clutil 2011.138.0 → 2014.304.0
Sign up to get free protection for your applications and to get access to all the features.
- metadata +47 -71
- data/cl/util/clqsend.rb +0 -86
- data/cl/util/console.rb +0 -60
- data/cl/util/cvs.maint.rb +0 -41
- data/cl/util/decide.rb +0 -69
- data/cl/util/dirsize.rb +0 -144
- data/cl/util/doc/License +0 -14
- data/cl/util/doc/Readme +0 -22
- data/cl/util/file.rb +0 -312
- data/cl/util/install.rb +0 -117
- data/cl/util/install.util.rb +0 -67
- data/cl/util/net.rb +0 -35
- data/cl/util/progress.rb +0 -104
- data/cl/util/smtp.rb +0 -170
- data/cl/util/string.rb +0 -73
- data/cl/util/test/dirsizetest.rb +0 -137
- data/cl/util/test/filetest.rb +0 -244
- data/cl/util/test/installtest.rb +0 -11
- data/cl/util/test/progresstest.rb +0 -43
- data/cl/util/test/stringtest.rb +0 -58
- data/cl/util/test/wintest.rb +0 -106
- data/cl/util/test.rb +0 -90
- data/cl/util/time.rb +0 -35
- data/cl/util/win.rb +0 -350
data/cl/util/smtp.rb
DELETED
@@ -1,170 +0,0 @@
|
|
1
|
-
# $Id: smtp.rb,v 1.4 2008/12/09 06:58:56 chrismo Exp $
|
2
|
-
=begin
|
3
|
-
--------------------------------------------------------------------------
|
4
|
-
Copyright (c) 2001-2010, Chris Morris
|
5
|
-
All rights reserved.
|
6
|
-
|
7
|
-
Redistribution and use in source and binary forms, with or without modification,
|
8
|
-
are permitted provided that the following conditions are met:
|
9
|
-
|
10
|
-
1. Redistributions of source code must retain the above copyright notice, this
|
11
|
-
list of conditions and the following disclaimer.
|
12
|
-
|
13
|
-
2. Redistributions in binary form must reproduce the above copyright notice,
|
14
|
-
this list of conditions and the following disclaimer in the documentation and/or
|
15
|
-
other materials provided with the distribution.
|
16
|
-
|
17
|
-
3. Neither the names Chris Morris, cLabs nor the names of contributors to this
|
18
|
-
software may be used to endorse or promote products derived from this software
|
19
|
-
without specific prior written permission.
|
20
|
-
|
21
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
|
22
|
-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
23
|
-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
24
|
-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
|
25
|
-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
26
|
-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
27
|
-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
28
|
-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
29
|
-
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
30
|
-
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
-
--------------------------------------------------------------------------------
|
32
|
-
=end
|
33
|
-
require 'net/smtp'
|
34
|
-
require 'time'
|
35
|
-
|
36
|
-
module ClUtil
|
37
|
-
class Attachment
|
38
|
-
def self.load_from_file(filename)
|
39
|
-
data = nil
|
40
|
-
File.open(filename, 'rb') do |f|
|
41
|
-
data = f.read()
|
42
|
-
end
|
43
|
-
data = [data].pack("m*")
|
44
|
-
Attachment.new(File.basename(filename), data)
|
45
|
-
end
|
46
|
-
|
47
|
-
attr_reader :name, :data
|
48
|
-
|
49
|
-
def initialize(name, data)
|
50
|
-
@name = name
|
51
|
-
@data = data
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
class Smtp
|
56
|
-
attr_reader :attachments
|
57
|
-
attr_accessor :from, :subj, :body, :extra_headers, :username, :password, :auth_type, :enable_starttls, :port
|
58
|
-
|
59
|
-
def initialize(smtpsrv='localhost', port=25)
|
60
|
-
@smtpsrv = smtpsrv
|
61
|
-
@port = port
|
62
|
-
@attachments = []
|
63
|
-
@username = nil
|
64
|
-
@password = nil
|
65
|
-
@auth_type = :login
|
66
|
-
@enable_starttls = false
|
67
|
-
end
|
68
|
-
|
69
|
-
def to
|
70
|
-
@to
|
71
|
-
end
|
72
|
-
|
73
|
-
def to=(value)
|
74
|
-
@to = [value].flatten
|
75
|
-
end
|
76
|
-
|
77
|
-
def sendmail
|
78
|
-
msg = build_message
|
79
|
-
@smtp = Net::SMTP.new(@smtpsrv, @port)
|
80
|
-
start_tls_if_needed
|
81
|
-
@smtp.start('localhost.localdomain', @username, @password, @auth_type) do |smtp|
|
82
|
-
smtp.sendmail(msg, @from, @to)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def start_tls_if_needed
|
87
|
-
return if !@enable_starttls
|
88
|
-
# require 'rubygems'
|
89
|
-
# gem 'smtp_tls'
|
90
|
-
# require 'smtp_tls'
|
91
|
-
@smtp.enable_starttls
|
92
|
-
end
|
93
|
-
|
94
|
-
def content_type
|
95
|
-
@body =~ /<html>/ ? "text/html" : "text/plain"
|
96
|
-
end
|
97
|
-
|
98
|
-
def build_message
|
99
|
-
msg = format_headers
|
100
|
-
boundary = create_boundary
|
101
|
-
|
102
|
-
if !@attachments.empty?
|
103
|
-
msg << [
|
104
|
-
"Content-Type: multipart/mixed; boundary=\"#{boundary}\"\n",
|
105
|
-
"\n",
|
106
|
-
"This is a multi-part message in MIME format.\n",
|
107
|
-
"\n"
|
108
|
-
]
|
109
|
-
end
|
110
|
-
|
111
|
-
if @body
|
112
|
-
msg << [ "--#{boundary}\n" ] if !@attachments.empty?
|
113
|
-
msg << [
|
114
|
-
"Content-Type: #{content_type}; charset=\"iso-8859-1\"\n",
|
115
|
-
"Content-Transfer-Encoding: 8bit\n",
|
116
|
-
"\n",
|
117
|
-
"#{@body}\n",
|
118
|
-
"\n"
|
119
|
-
]
|
120
|
-
end
|
121
|
-
|
122
|
-
@attachments.each do |attachment|
|
123
|
-
basename = attachment.name
|
124
|
-
msg << [
|
125
|
-
"--#{boundary}\n",
|
126
|
-
"Content-Type: application/octet-stream; name=\"#{basename}\"\n",
|
127
|
-
"Content-Transfer-Encoding: base64\n",
|
128
|
-
"Content-Disposition: attachment; filename=\"#{basename}\"\n",
|
129
|
-
"\n",
|
130
|
-
"#{attachment.data}", # no \n needed
|
131
|
-
"\n"
|
132
|
-
]
|
133
|
-
end
|
134
|
-
|
135
|
-
msg << ["--#{boundary}--\n"] if !@attachments.empty?
|
136
|
-
|
137
|
-
msg.flatten!
|
138
|
-
end
|
139
|
-
|
140
|
-
def create_boundary()
|
141
|
-
return "_____clabs_smtp_boundary______#{Time.new.to_i.to_s}___"
|
142
|
-
end
|
143
|
-
|
144
|
-
def format_headers
|
145
|
-
headers = ["Subject: #{subj}", "From: #{from}", "To: #{to.join(";")}", "Date: #{Time.now.rfc2822}", "MIME-Version: 1.0" ]
|
146
|
-
headers << @extra_headers if @extra_headers
|
147
|
-
headers.flatten!
|
148
|
-
headers.collect! { |hdr| hdr.strip << "\n" }
|
149
|
-
[headers].flatten
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
# deprecated - use ClUtil::Smtp instead. The attachments argument is designed
|
155
|
-
# to be either a single filename or an array of filenames.
|
156
|
-
def sendmail(to, from, subj, body, smtpsrv=nil, attachments=nil, extra_headers=nil)
|
157
|
-
smtpsrv = 'localhost' if !smtpsrv
|
158
|
-
smtp = ClUtil::Smtp.new(smtpsrv)
|
159
|
-
smtp.to = to
|
160
|
-
smtp.from = from
|
161
|
-
smtp.subj = subj
|
162
|
-
smtp.body = body
|
163
|
-
smtp.extra_headers = extra_headers
|
164
|
-
attachments = [attachments].flatten
|
165
|
-
attachments.compact!
|
166
|
-
attachments.each do |attachment_fn|
|
167
|
-
smtp.attachments << ClUtil::Attachment.load_from_file(attachment_fn)
|
168
|
-
end
|
169
|
-
smtp.sendmail
|
170
|
-
end
|
data/cl/util/string.rb
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
# $Id: string.rb,v 1.2 2003/06/27 17:46:03 chrismo Exp $
|
2
|
-
=begin
|
3
|
-
----------------------------------------------------------------------------
|
4
|
-
Copyright (c) 2001 - 2010, Chris Morris
|
5
|
-
All rights reserved.
|
6
|
-
|
7
|
-
Redistribution and use in source and binary forms, with or without
|
8
|
-
modification, are permitted provided that the following conditions are met:
|
9
|
-
|
10
|
-
1. Redistributions of source code must retain the above copyright notice,
|
11
|
-
this list of conditions and the following disclaimer.
|
12
|
-
|
13
|
-
2. Redistributions in binary form must reproduce the above copyright notice,
|
14
|
-
this list of conditions and the following disclaimer in the documentation
|
15
|
-
and/or other materials provided with the distribution.
|
16
|
-
|
17
|
-
3. Neither the names Chris Morris, cLabs nor the names of contributors to
|
18
|
-
this software may be used to endorse or promote products derived from this
|
19
|
-
software without specific prior written permission.
|
20
|
-
|
21
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
|
22
|
-
IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
23
|
-
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
24
|
-
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
|
25
|
-
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
26
|
-
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
27
|
-
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
28
|
-
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
29
|
-
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
30
|
-
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
31
|
-
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
32
|
-
----------------------------------------------------------------------------
|
33
|
-
(based on BSD Open Source License)
|
34
|
-
=end
|
35
|
-
|
36
|
-
class String
|
37
|
-
def get_indent
|
38
|
-
scan(/^(\s*)/).flatten[0].to_s
|
39
|
-
end
|
40
|
-
|
41
|
-
def rbpath
|
42
|
-
self.gsub(/\\/, '/')
|
43
|
-
end
|
44
|
-
|
45
|
-
def winpath
|
46
|
-
self.gsub(/\//, "\\")
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def indent(s, amt)
|
51
|
-
a = s.split("\n", -1)
|
52
|
-
if amt >= 0
|
53
|
-
a.collect! do |ln|
|
54
|
-
if !ln.empty?
|
55
|
-
(' ' * amt) + ln
|
56
|
-
else
|
57
|
-
ln
|
58
|
-
end
|
59
|
-
end
|
60
|
-
else
|
61
|
-
a.collect! do |ln|
|
62
|
-
(1..amt.abs).each do ln = ln[1..-1] if ln[0..0] == ' ' end
|
63
|
-
ln
|
64
|
-
end
|
65
|
-
end
|
66
|
-
a.join("\n")
|
67
|
-
end
|
68
|
-
|
69
|
-
def here_ltrim(s, add_indent_amt=0)
|
70
|
-
a = s.split("\n", -1)
|
71
|
-
trim_indent_amt = a[0].get_indent.length
|
72
|
-
indent(s, add_indent_amt - trim_indent_amt)
|
73
|
-
end
|
data/cl/util/test/dirsizetest.rb
DELETED
@@ -1,137 +0,0 @@
|
|
1
|
-
=begin
|
2
|
-
--------------------------------------------------------------------------
|
3
|
-
Copyright (c) 2001, Chris Morris
|
4
|
-
All rights reserved.
|
5
|
-
|
6
|
-
Redistribution and use in source and binary forms, with or without modification,
|
7
|
-
are permitted provided that the following conditions are met:
|
8
|
-
|
9
|
-
1. Redistributions of source code must retain the above copyright notice, this
|
10
|
-
list of conditions and the following disclaimer.
|
11
|
-
|
12
|
-
2. Redistributions in binary form must reproduce the above copyright notice,
|
13
|
-
this list of conditions and the following disclaimer in the documentation and/or
|
14
|
-
other materials provided with the distribution.
|
15
|
-
|
16
|
-
3. Neither the names Chris Morris, cLabs nor the names of contributors to this
|
17
|
-
software may be used to endorse or promote products derived from this software
|
18
|
-
without specific prior written permission.
|
19
|
-
|
20
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
|
21
|
-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
22
|
-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23
|
-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
|
24
|
-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
25
|
-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
26
|
-
SERVICES LOSS OF USE, DATA, OR PROFITS OR BUSINESS INTERRUPTION) HOWEVER
|
27
|
-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
28
|
-
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
29
|
-
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30
|
-
--------------------------------------------------------------------------------
|
31
|
-
=end
|
32
|
-
|
33
|
-
require File.dirname(__FILE__) + '/../test'
|
34
|
-
require File.dirname(__FILE__) + '/../dirsize'
|
35
|
-
require 'test/unit'
|
36
|
-
|
37
|
-
TestData = Struct.new("TestData",
|
38
|
-
:clusterSize,
|
39
|
-
:expectedFileSize,
|
40
|
-
:expectedDiskSpace,
|
41
|
-
:expectedFileSizeIncludeSubs,
|
42
|
-
:expectedDiskSpaceIncludeSubs,
|
43
|
-
:expectedFileCount,
|
44
|
-
:expectedAvgFileSize,
|
45
|
-
:expectedFileCountIncludeSubs,
|
46
|
-
:expectedAvgFileSizeIncludeSubs
|
47
|
-
)
|
48
|
-
|
49
|
-
class TestDirSize < TempDirTest
|
50
|
-
def setup
|
51
|
-
super
|
52
|
-
@test_data = TestData.new
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_larger_singleton
|
56
|
-
make_sample_text_file('', 5000)
|
57
|
-
@test_data.clusterSize = 4096
|
58
|
-
@test_data.expectedFileSize = 5000
|
59
|
-
@test_data.expectedDiskSpace = (4096 * 2)
|
60
|
-
@test_data.expectedFileSizeIncludeSubs = 5000
|
61
|
-
@test_data.expectedDiskSpaceIncludeSubs = (4096 * 2)
|
62
|
-
@test_data.expectedFileCount = 1
|
63
|
-
@test_data.expectedAvgFileSize = 5000
|
64
|
-
@test_data.expectedFileCountIncludeSubs = 1
|
65
|
-
@test_data.expectedAvgFileSizeIncludeSubs = 5000
|
66
|
-
do_test_dir_size(@test_data)
|
67
|
-
end
|
68
|
-
|
69
|
-
def do_test_dir_size(test_data)
|
70
|
-
dir_size = DirSize.new
|
71
|
-
dir_size.directory = @temp_dir
|
72
|
-
dir_size.clusterSize = test_data.clusterSize
|
73
|
-
dir_size.getSize
|
74
|
-
assert_equal(test_data.expectedFileSize, dir_size.fileSize(false))
|
75
|
-
assert_equal(test_data.expectedDiskSpace, dir_size.diskSpace(false))
|
76
|
-
assert_equal(test_data.expectedFileSizeIncludeSubs, dir_size.fileSize(true))
|
77
|
-
assert_equal(test_data.expectedDiskSpaceIncludeSubs,
|
78
|
-
dir_size.diskSpace(true))
|
79
|
-
assert_equal(test_data.expectedDiskSpace - test_data.expectedFileSize,
|
80
|
-
dir_size.unusedDiskSpace(false))
|
81
|
-
assert_equal(
|
82
|
-
(test_data.expectedDiskSpaceIncludeSubs -
|
83
|
-
test_data.expectedFileSizeIncludeSubs), dir_size.unusedDiskSpace(true))
|
84
|
-
assert_equal(test_data.expectedFileCount, dir_size.fileCount(false))
|
85
|
-
assert_equal(test_data.expectedAvgFileSize, dir_size.avgFileSize(false))
|
86
|
-
assert_equal(test_data.expectedFileCountIncludeSubs,
|
87
|
-
dir_size.fileCount(true))
|
88
|
-
assert_equal(test_data.expectedAvgFileSizeIncludeSubs,
|
89
|
-
dir_size.avgFileSize(true))
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_small_singleton
|
93
|
-
make_sample_text_file('', 1000)
|
94
|
-
@test_data.clusterSize = 4096
|
95
|
-
@test_data.expectedFileSize = 1000
|
96
|
-
@test_data.expectedDiskSpace = (4096 * 1)
|
97
|
-
@test_data.expectedFileSizeIncludeSubs = 1000
|
98
|
-
@test_data.expectedDiskSpaceIncludeSubs = (4096 * 1)
|
99
|
-
@test_data.expectedFileCount = 1
|
100
|
-
@test_data.expectedAvgFileSize = 1000
|
101
|
-
@test_data.expectedFileCountIncludeSubs = 1
|
102
|
-
@test_data.expectedAvgFileSizeIncludeSubs = 1000
|
103
|
-
do_test_dir_size(@test_data)
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_sub_dir
|
107
|
-
make_sub_dir('suba')
|
108
|
-
make_sub_dir("suba\\suba1")
|
109
|
-
make_sample_text_file('', 1000)
|
110
|
-
make_sample_text_file('suba', 1000)
|
111
|
-
make_sample_text_file("suba\\suba1", 1000)
|
112
|
-
make_sample_text_file("suba\\suba1", 2000)
|
113
|
-
@test_data.clusterSize = 4096
|
114
|
-
@test_data.expectedFileSize = 1000
|
115
|
-
@test_data.expectedDiskSpace = (4096 * 1)
|
116
|
-
@test_data.expectedFileSizeIncludeSubs = 5000
|
117
|
-
@test_data.expectedDiskSpaceIncludeSubs = (4096 * 4)
|
118
|
-
@test_data.expectedFileCount = 1
|
119
|
-
@test_data.expectedAvgFileSize = 1000
|
120
|
-
@test_data.expectedFileCountIncludeSubs = 4
|
121
|
-
@test_data.expectedAvgFileSizeIncludeSubs = 1250
|
122
|
-
do_test_dir_size(@test_data)
|
123
|
-
end
|
124
|
-
|
125
|
-
def test_empty_dir
|
126
|
-
@test_data.clusterSize = 4096
|
127
|
-
@test_data.expectedFileSize = 0
|
128
|
-
@test_data.expectedDiskSpace = 0
|
129
|
-
@test_data.expectedFileCount = 0
|
130
|
-
@test_data.expectedAvgFileSize = 0
|
131
|
-
@test_data.expectedFileCountIncludeSubs = 0
|
132
|
-
@test_data.expectedAvgFileSizeIncludeSubs = 0
|
133
|
-
@test_data.expectedFileSizeIncludeSubs = 0
|
134
|
-
@test_data.expectedDiskSpaceIncludeSubs = 0
|
135
|
-
do_test_dir_size(@test_data)
|
136
|
-
end
|
137
|
-
end
|
data/cl/util/test/filetest.rb
DELETED
@@ -1,244 +0,0 @@
|
|
1
|
-
# $Id: filetest.rb,v 1.3 2002/08/28 16:49:33 chrismo Exp $
|
2
|
-
=begin
|
3
|
-
--------------------------------------------------------------------------
|
4
|
-
Copyright (c) 2001, Chris Morris
|
5
|
-
All rights reserved.
|
6
|
-
|
7
|
-
Redistribution and use in source and binary forms, with or without modification,
|
8
|
-
are permitted provided that the following conditions are met:
|
9
|
-
|
10
|
-
1. Redistributions of source code must retain the above copyright notice, this
|
11
|
-
list of conditions and the following disclaimer.
|
12
|
-
|
13
|
-
2. Redistributions in binary form must reproduce the above copyright notice,
|
14
|
-
this list of conditions and the following disclaimer in the documentation and/or
|
15
|
-
other materials provided with the distribution.
|
16
|
-
|
17
|
-
3. Neither the names Chris Morris, cLabs nor the names of contributors to this
|
18
|
-
software may be used to endorse or promote products derived from this software
|
19
|
-
without specific prior written permission.
|
20
|
-
|
21
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
|
22
|
-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
23
|
-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
24
|
-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
|
25
|
-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
26
|
-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
27
|
-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
28
|
-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
29
|
-
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
30
|
-
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
-
--------------------------------------------------------------------------------
|
32
|
-
(based on BSD Open Source License)
|
33
|
-
=end
|
34
|
-
|
35
|
-
require File.dirname(__FILE__) + '/../file'
|
36
|
-
require File.dirname(__FILE__) + '/../test'
|
37
|
-
require 'test/unit'
|
38
|
-
|
39
|
-
# don't inherit from clutiltest.rb.TempDirTest, it uses things that are tested here
|
40
|
-
class TestUtilFile < Test::Unit::TestCase
|
41
|
-
READ_WRITE = 0644
|
42
|
-
READ_ONLY = 0444
|
43
|
-
|
44
|
-
def create_test_file(file_name, content, mtime=Time.now, attr=READ_WRITE)
|
45
|
-
f = File.new(file_name, 'w+')
|
46
|
-
f.puts(content)
|
47
|
-
f.flush
|
48
|
-
f.close
|
49
|
-
File.utime(mtime, mtime, file_name)
|
50
|
-
File.chmod(attr, file_name)
|
51
|
-
end
|
52
|
-
|
53
|
-
def setup
|
54
|
-
@files = []
|
55
|
-
end
|
56
|
-
|
57
|
-
def teardown
|
58
|
-
@files.each { | filename | File.delete_all(filename) if File.exists?(filename) }
|
59
|
-
@dirs.reverse_each { | dirname | Dir.delete(dirname) if File.exists?(dirname) } if @dirs
|
60
|
-
end
|
61
|
-
|
62
|
-
def do_test_del_tree(attr)
|
63
|
-
@dirs = ['/tmp/utilfiletest',
|
64
|
-
'/tmp/utilfiletest/subA',
|
65
|
-
'/tmp/utilfiletest/subA/subA1',
|
66
|
-
'/tmp/utilfiletest/subA/subA2',
|
67
|
-
'/tmp/utilfiletest/subB',
|
68
|
-
'/tmp/utilfiletest/subB/subB1',
|
69
|
-
'/tmp/utilfiletest/subB/subB1/subB1a']
|
70
|
-
@dirs.each { | dir_name | FileUtils::makedirs(dir_name) }
|
71
|
-
@files = ['/tmp/utilfiletest/subA/blah.txt',
|
72
|
-
'/tmp/utilfiletest/subA/subA1/blah.txt',
|
73
|
-
'/tmp/utilfiletest/subA/subA2/blah.txt',
|
74
|
-
'/tmp/utilfiletest/subB/blah.txt',
|
75
|
-
'/tmp/utilfiletest/subB/subB1/blah.txt',
|
76
|
-
'/tmp/utilfiletest/subB/subB1/subB1a/blah.txt']
|
77
|
-
@files.each { | filename | create_test_file(filename, 'test content', Time.now, attr) }
|
78
|
-
ClUtilFile.delTree(@dirs[0])
|
79
|
-
@files.each { | file_name | assert(!File.exists?(file_name)) }
|
80
|
-
@dirs.each { | dir_name | assert(!File.exists?(dir_name)) }
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_del_tree
|
84
|
-
do_test_del_tree(READ_WRITE)
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_del_tree_ro_files
|
88
|
-
do_test_del_tree(READ_ONLY)
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_del_tree_file_name_match
|
92
|
-
@dirs = ['/tmp/utilfiletest',
|
93
|
-
'/tmp/utilfiletest/subA',
|
94
|
-
'/tmp/utilfiletest/subB']
|
95
|
-
@dirs.each { | dir_name | FileUtils::makedirs(dir_name) }
|
96
|
-
@files_to_stay = ['/tmp/utilfiletest/subA/blah.doc',
|
97
|
-
'/tmp/utilfiletest/subB/blah.doc']
|
98
|
-
@files_to_delete = ['/tmp/utilfiletest/subA/blah.txt',
|
99
|
-
'/tmp/utilfiletest/subB/blah.txt']
|
100
|
-
@files << @files_to_stay
|
101
|
-
@files << @files_to_delete
|
102
|
-
@files.flatten!
|
103
|
-
|
104
|
-
@files_to_stay.each { | filename | create_test_file(filename, 'test content') }
|
105
|
-
@files_to_delete.each { | filename | create_test_file(filename, 'test content') }
|
106
|
-
ClUtilFile.delTree(@dirs[0], '*.txt')
|
107
|
-
@files_to_stay.each { | file_name | assert(File.exists?(file_name)) }
|
108
|
-
@files_to_delete.each { | file_name | assert(!File.exists?(file_name)) }
|
109
|
-
ClUtilFile.delTree(@dirs[0])
|
110
|
-
@files_to_stay.each { | file_name | assert(!File.exists?(file_name)) }
|
111
|
-
@files_to_delete.each { | file_name | assert(!File.exists?(file_name)) }
|
112
|
-
@dirs.each { | dir_name | assert(!File.exists?(dir_name)) }
|
113
|
-
end
|
114
|
-
|
115
|
-
def test_del_tree_aging
|
116
|
-
@dirs = ['/tmp/utilfiletest',
|
117
|
-
'/tmp/utilfiletest/subA',
|
118
|
-
'/tmp/utilfiletest/subB']
|
119
|
-
@dirs.each { | dir_name | FileUtils::makedirs(dir_name) }
|
120
|
-
@files_to_stay = ['/tmp/utilfiletest/subA/blah0.txt',
|
121
|
-
'/tmp/utilfiletest/subB/blah1.txt']
|
122
|
-
@files_to_delete = ['/tmp/utilfiletest/subA/blah2.txt',
|
123
|
-
'/tmp/utilfiletest/subB/blah3.txt']
|
124
|
-
@files << @files_to_stay
|
125
|
-
@files << @files_to_delete
|
126
|
-
@files.flatten!
|
127
|
-
|
128
|
-
@files_to_stay.each { | filename | create_test_file(filename, 'test content') }
|
129
|
-
|
130
|
-
day = 60 * 60 * 24
|
131
|
-
eight_days = day * 8
|
132
|
-
seven_days = day * 7
|
133
|
-
@files_to_delete.each { | filename | create_test_file(filename, 'test content', Time.now - eight_days) }
|
134
|
-
|
135
|
-
ClUtilFile.delTree(@dirs[0]) { | file_name |
|
136
|
-
(File.mtime(file_name) < (Time.now - seven_days))
|
137
|
-
}
|
138
|
-
|
139
|
-
@files_to_stay.each { | file_name | assert(File.exists?(file_name)) }
|
140
|
-
@files_to_delete.each { | file_name | assert(!File.exists?(file_name)) }
|
141
|
-
ClUtilFile.delTree(@dirs[0])
|
142
|
-
@files_to_stay.each { | file_name | assert(!File.exists?(file_name)) }
|
143
|
-
@files_to_delete.each { | file_name | assert(!File.exists?(file_name)) }
|
144
|
-
@dirs.each { | dir_name | assert(!File.exists?(dir_name)) }
|
145
|
-
end
|
146
|
-
|
147
|
-
def test_dir_files
|
148
|
-
@dirs = ['/tmp/utilfiletest',
|
149
|
-
'/tmp/utilfiletest/subA',
|
150
|
-
'/tmp/utilfiletest/subA/subA1',
|
151
|
-
'/tmp/utilfiletest/subA/subA2',
|
152
|
-
'/tmp/utilfiletest/subB',
|
153
|
-
'/tmp/utilfiletest/subB/subB1',
|
154
|
-
'/tmp/utilfiletest/subB/subB1/subB1a']
|
155
|
-
@dirs.each { | dir_name | FileUtils::makedirs(dir_name) }
|
156
|
-
@files = ['/tmp/utilfiletest/subA/blah.txt',
|
157
|
-
'/tmp/utilfiletest/subA/subA1/blah.txt',
|
158
|
-
'/tmp/utilfiletest/subA/subA2/blah.txt',
|
159
|
-
'/tmp/utilfiletest/subB/blah.txt',
|
160
|
-
'/tmp/utilfiletest/subB/subB1/blah.txt',
|
161
|
-
'/tmp/utilfiletest/subB/subB1/subB1a/blah.txt']
|
162
|
-
@files.each { | filename | create_test_file(filename, 'test content') }
|
163
|
-
#puts 'Dir.entries'
|
164
|
-
#puts Dir.entries('/tmp/utilfiletest/subA/subA1/')
|
165
|
-
#puts 'Dir.files'
|
166
|
-
#puts Dir.files('/tmp/utilfiletest/subA/subA1/')
|
167
|
-
assert_equal(["blah.txt"], Dir.files('/tmp/utilfiletest/subA/subA1/'))
|
168
|
-
end
|
169
|
-
|
170
|
-
def test_file_extension
|
171
|
-
assert_equal('rb', File.extension('/test/file.rb'))
|
172
|
-
assert_equal(nil, File.extension('/test/file'))
|
173
|
-
assert_equal('rb', File.extension('/test/file.of.some.such.rb'))
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
class TestBackup < TempDirTest
|
178
|
-
|
179
|
-
def setup
|
180
|
-
super
|
181
|
-
@a_dir = make_sub_dir('a')
|
182
|
-
@b_dir = make_sub_dir('b')
|
183
|
-
end
|
184
|
-
|
185
|
-
def test_backed_up_because_not_exists
|
186
|
-
src = make_sample_text_file('a')
|
187
|
-
dst = File.join(@b_dir, File.basename(src))
|
188
|
-
assert_equal(true, File.backup(src, dst))
|
189
|
-
assert_equal(true, File.exists?(dst))
|
190
|
-
end
|
191
|
-
|
192
|
-
def test_not_backed_up_because_exists
|
193
|
-
src = make_sample_text_file('a')
|
194
|
-
dst = File.join(@b_dir, File.basename(src))
|
195
|
-
assert_equal(true, File.backup(src, dst))
|
196
|
-
assert_equal(false, File.backup(src, dst))
|
197
|
-
end
|
198
|
-
|
199
|
-
def test_backed_up_because_exists_different_mtime
|
200
|
-
src = make_sample_text_file('a')
|
201
|
-
dst = File.join(@b_dir, File.basename(src))
|
202
|
-
assert_equal(true, File.backup(src, dst))
|
203
|
-
|
204
|
-
File.utime(0, 0, dst)
|
205
|
-
assert_equal(true, File.backup(src, dst))
|
206
|
-
end
|
207
|
-
|
208
|
-
def test_backed_up_because_exists_different_size
|
209
|
-
src = make_sample_text_file('a')
|
210
|
-
dst = File.join(@b_dir, File.basename(src))
|
211
|
-
assert_equal(true, File.backup(src, dst))
|
212
|
-
|
213
|
-
File.open(dst, 'a+') do |f| f.print "bigger" end
|
214
|
-
assert_equal(true, File.backup(src, dst))
|
215
|
-
end
|
216
|
-
|
217
|
-
def test_not_backed_up_because_exists_byte_diff_but_no_bincompare
|
218
|
-
src = make_sample_text_file('a')
|
219
|
-
dst = File.join(@b_dir, File.basename(src))
|
220
|
-
assert_equal(true, File.backup(src, dst))
|
221
|
-
|
222
|
-
guts = File.read(dst)
|
223
|
-
guts.reverse!
|
224
|
-
File.open(dst, 'w+') do |f| f.print guts end
|
225
|
-
File.utime(File.atime(src), File.mtime(src), dst)
|
226
|
-
assert_equal(false, File.backup(src, dst))
|
227
|
-
end
|
228
|
-
|
229
|
-
def test_backed_up_because_exists_byte_diff_and_bincompare
|
230
|
-
src = make_sample_text_file('a')
|
231
|
-
dst = File.join(@b_dir, File.basename(src))
|
232
|
-
assert_equal(true, File.backup(src, dst))
|
233
|
-
|
234
|
-
guts = File.read(dst)
|
235
|
-
guts.reverse!
|
236
|
-
File.open(dst, 'w+') do |f| f.print guts end
|
237
|
-
File.utime(File.atime(src), File.mtime(src), dst)
|
238
|
-
assert_equal(true, File.backup(src, dst, true))
|
239
|
-
end
|
240
|
-
|
241
|
-
end
|
242
|
-
|
243
|
-
|
244
|
-
|
data/cl/util/test/installtest.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../install')
|
2
|
-
require 'test/unit'
|
3
|
-
|
4
|
-
class TestInstall < Test::Unit::TestCase
|
5
|
-
def test_set_prefix
|
6
|
-
install = CLabs::Install.new
|
7
|
-
conf = install.get_conf({'prefix' => '/tmp/ruby'})
|
8
|
-
assert_equal('/tmp/ruby', conf['prefix'])
|
9
|
-
assert_equal('/tmp/ruby/lib/ruby/site_ruby', conf['sitedir'])
|
10
|
-
end
|
11
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
# $Id: progresstest.rb,v 1.2 2003/09/12 14:53:53 chrismo Exp $
|
2
|
-
=begin
|
3
|
-
--------------------------------------------------------------------------
|
4
|
-
Copyright (c) 2002, Chris Morris
|
5
|
-
All rights reserved.
|
6
|
-
|
7
|
-
Redistribution and use in source and binary forms, with or without modification,
|
8
|
-
are permitted provided that the following conditions are met:
|
9
|
-
|
10
|
-
1. Redistributions of source code must retain the above copyright notice, this
|
11
|
-
list of conditions and the following disclaimer.
|
12
|
-
|
13
|
-
2. Redistributions in binary form must reproduce the above copyright notice,
|
14
|
-
this list of conditions and the following disclaimer in the documentation and/or
|
15
|
-
other materials provided with the distribution.
|
16
|
-
|
17
|
-
3. Neither the names Chris Morris, cLabs nor the names of contributors to this
|
18
|
-
software may be used to endorse or promote products derived from this software
|
19
|
-
without specific prior written permission.
|
20
|
-
|
21
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
|
22
|
-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
23
|
-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
24
|
-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
|
25
|
-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
26
|
-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
27
|
-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
28
|
-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
29
|
-
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
30
|
-
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
-
--------------------------------------------------------------------------------
|
32
|
-
=end
|
33
|
-
|
34
|
-
$LOAD_PATH << '..'
|
35
|
-
require 'progress'
|
36
|
-
|
37
|
-
p = Progress.new(10)
|
38
|
-
p.start
|
39
|
-
(0..9).each do |x| puts p.progress(true); sleep 0.5 end
|
40
|
-
|
41
|
-
p = Progress.new(10)
|
42
|
-
p.start
|
43
|
-
(0..9).each do |x| print p.in_place_pct(true); sleep 0.5 end
|