riel 1.1.17 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/riel/date.rb +12 -4
- data/lib/riel/dir.rb +73 -67
- data/lib/riel/enumerable.rb +30 -51
- data/lib/riel/pathname.rb +1 -1
- data/lib/riel/rcfile.rb +0 -2
- data/lib/riel/regexp.rb +2 -6
- data/lib/riel/setdiff.rb +0 -2
- data/lib/riel/string.rb +75 -80
- data/lib/riel/timer.rb +7 -9
- data/lib/riel.rb +1 -1
- data/test/riel/date_test.rb +4 -0
- data/test/riel/dir_test.rb +4 -0
- data/test/riel/enumerable_test.rb +86 -11
- data/test/riel/regexp_test.rb +6 -0
- data/test/riel/size_converter_test.rb +4 -4
- data/test/riel/string_test.rb +4 -4
- metadata +9 -32
- data/lib/riel/array.rb +0 -19
- data/lib/riel/log/log.rb +0 -244
- data/lib/riel/log/loggable.rb +0 -101
- data/lib/riel/log/logger.rb +0 -266
- data/lib/riel/log/severity.rb +0 -22
- data/lib/riel/log.rb +0 -21
- data/lib/riel/optproc.rb +0 -296
- data/test/riel/array_test.rb +0 -22
- data/test/riel/log/format_test.rb +0 -48
- data/test/riel/optproc_test.rb +0 -202
- data/test/riel/testlog/log_stack_test.rb +0 -98
- data/test/riel/testlog/log_test.rb +0 -254
- data/test/riel/testlog/loggable_test.rb +0 -31
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d9fec4fdc968d7eac63fc2e894a6bd3b2252d86f
|
4
|
+
data.tar.gz: 38b6c94c7045866f8fbf88fdd6ec7861a0bd0750
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 59546acde4a6fdf7d2716be86af60d2cc6c5a3a6fa389dede2790de02c2c251f6708510f59413c07c6f79604529c8c957cd4a5e48250f1007ecf3cae9740a10f
|
7
|
+
data.tar.gz: a2d02521a496858feb6d9d08dfb2fca21ec6bf7f97c9b381ef971554ad49a8c8bf9ec6f30ebeb1d0106e557b04a474a4b1c544ce928ea94b251810c44cb432f2
|
data/lib/riel/date.rb
CHANGED
@@ -4,9 +4,17 @@
|
|
4
4
|
|
5
5
|
require 'date'
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
module RIEL
|
8
|
+
module DateExt
|
9
|
+
def self.included base
|
10
|
+
base.extend ClassMethods
|
11
|
+
end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
# Returns the number of days in the given month.
|
15
|
+
def days_in_month year, month
|
16
|
+
(Date.new(year, 12, 31) << (12 - month)).day
|
17
|
+
end
|
18
|
+
end
|
11
19
|
end
|
12
20
|
end
|
data/lib/riel/dir.rb
CHANGED
@@ -3,90 +3,96 @@
|
|
3
3
|
|
4
4
|
require 'pathname'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
def self.home
|
11
|
-
ENV["HOME"] || begin
|
12
|
-
hd = ENV["HOMEDRIVE"]
|
13
|
-
hp = ENV["HOMEPATH"]
|
14
|
-
if hd || hp
|
15
|
-
(hd || "") + (hp || "\\")
|
16
|
-
end
|
17
|
-
end
|
6
|
+
module RIEL
|
7
|
+
module DirExt
|
8
|
+
def self.included base
|
9
|
+
base.extend ClassMethods
|
18
10
|
end
|
19
|
-
end
|
20
11
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
12
|
+
module ClassMethods
|
13
|
+
# Returns the home directory, for both Unix and Windows.
|
14
|
+
unless RUBY_VERSION.index('1.9')
|
15
|
+
def home
|
16
|
+
ENV["HOME"] || begin
|
17
|
+
hd = ENV["HOMEDRIVE"]
|
18
|
+
hp = ENV["HOMEPATH"]
|
19
|
+
if hd || hp
|
20
|
+
(hd || "") + (hp || "\\")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
27
25
|
|
28
|
-
|
29
|
-
|
26
|
+
# Removes directories containing no files or files matching only those in
|
27
|
+
# args[:deletable_files], which are basenames.
|
28
|
+
def remove_if_empty dir, args = Hash.new
|
29
|
+
deletable = args[:deletable] || Array.new
|
30
|
+
verbose = args[:verbose]
|
31
|
+
level = args[:level] || 0
|
30
32
|
|
31
|
-
|
33
|
+
subargs = args.dup
|
34
|
+
subargs[:level] = level + 1
|
32
35
|
|
33
|
-
|
34
|
-
puts "dir: #{dir}"
|
35
|
-
end
|
36
|
+
dir = Pathname.new(dir) unless dir.kind_of?(Pathname)
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
if child.exist? && child.directory?
|
40
|
-
self.remove_if_empty child, subargs
|
38
|
+
if level <= 1 && verbose
|
39
|
+
puts "dir: #{dir}"
|
41
40
|
end
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
can_delete = dir.children.all? do |x|
|
48
|
-
bname = x.basename.to_s
|
49
|
-
deletable.any? do |del|
|
50
|
-
if del.kind_of? String
|
51
|
-
bname == del
|
52
|
-
elsif del.kind_of? Regexp
|
53
|
-
del.match bname
|
54
|
-
else
|
55
|
-
false
|
41
|
+
|
42
|
+
if dir.readable?
|
43
|
+
dir.children.sort.each do |child|
|
44
|
+
if child.exist? && child.directory?
|
45
|
+
self.remove_if_empty child, subargs
|
56
46
|
end
|
57
47
|
end
|
58
|
-
|
48
|
+
|
49
|
+
if dir.expand_path == Pathname.pwd.expand_path
|
50
|
+
puts "skipping current directory: #{dir}" if verbose
|
51
|
+
else
|
52
|
+
can_delete = dir.children.all? do |x|
|
53
|
+
bname = x.basename.to_s
|
54
|
+
deletable.any? do |del|
|
55
|
+
if del.kind_of? String
|
56
|
+
bname == del
|
57
|
+
elsif del.kind_of? Regexp
|
58
|
+
del.match bname
|
59
|
+
else
|
60
|
+
false
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
59
64
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
+
if can_delete
|
66
|
+
dir.children.each do |x|
|
67
|
+
puts "removing file: #{x}" if verbose
|
68
|
+
x.delete
|
69
|
+
end
|
65
70
|
|
66
|
-
|
71
|
+
puts "removing directory: #{dir}" if verbose
|
67
72
|
|
68
|
-
|
69
|
-
|
70
|
-
|
73
|
+
dir.delete
|
74
|
+
else
|
75
|
+
# puts "#{dir} not empty"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
elsif verbose
|
79
|
+
puts "#{dir} not readable"
|
71
80
|
end
|
72
81
|
end
|
73
|
-
elsif verbose
|
74
|
-
puts "#{dir} not readable"
|
75
|
-
end
|
76
|
-
end
|
77
82
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
83
|
+
# Moves and copies files to the given directory, creating
|
84
|
+
# it if it does not exist.
|
85
|
+
def move_and_copy_files dir, move_files, copy_files
|
86
|
+
dir.mkdir unless dir.exist?
|
82
87
|
|
83
|
-
|
84
|
-
|
85
|
-
|
88
|
+
move_files.each do |mfile|
|
89
|
+
File.move mfile.to_s, dir.to_s
|
90
|
+
end
|
86
91
|
|
87
|
-
|
88
|
-
|
92
|
+
copy_files.each do |cfile|
|
93
|
+
File.copy cfile.to_s, dir.to_s
|
94
|
+
end
|
95
|
+
end
|
89
96
|
end
|
90
97
|
end
|
91
|
-
|
92
98
|
end
|
data/lib/riel/enumerable.rb
CHANGED
@@ -1,64 +1,43 @@
|
|
1
1
|
#!/usr/bin/ruby -w
|
2
2
|
# -*- ruby -*-
|
3
3
|
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
module RIEL
|
5
|
+
module EnumerableExt
|
6
|
+
def collect_with_index &blk
|
7
|
+
ary = []
|
8
|
+
self.each_with_index do |item, idx|
|
9
|
+
ary << blk.call(item, idx)
|
10
|
+
end
|
11
|
+
ary
|
9
12
|
end
|
10
|
-
ary
|
11
|
-
end
|
12
|
-
|
13
|
-
NOT_NIL = Object.new
|
14
|
-
|
15
|
-
def select_with_index arg = NOT_NIL, &blk
|
16
|
-
ary = []
|
17
|
-
self.each_with_index do |item, idx|
|
18
|
-
ary << item if _match?(arg, item, idx, &blk)
|
19
|
-
end
|
20
|
-
ary
|
21
|
-
end
|
22
13
|
|
23
|
-
|
24
|
-
self.each_with_index do |item, idx|
|
25
|
-
return item if _match?(arg, item, idx, &blk)
|
26
|
-
end
|
27
|
-
nil
|
28
|
-
end
|
29
|
-
|
30
|
-
alias :orig_select :select
|
31
|
-
alias :orig_collect :collect
|
32
|
-
alias :orig_detect :detect
|
33
|
-
alias :orig_reject :reject
|
14
|
+
NOT_NIL = Object.new
|
34
15
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
ary
|
16
|
+
def select_with_index arg = NOT_NIL, &blk
|
17
|
+
ary = []
|
18
|
+
self.each_with_index do |item, idx|
|
19
|
+
ary << item if _match?(arg, item, idx, &blk)
|
20
|
+
end
|
21
|
+
ary
|
41
22
|
end
|
42
|
-
ary
|
43
|
-
end
|
44
23
|
|
45
|
-
|
46
|
-
|
47
|
-
|
24
|
+
def detect_with_index arg = NOT_NIL, &blk
|
25
|
+
self.each_with_index do |item, idx|
|
26
|
+
return item if _match?(arg, item, idx, &blk)
|
27
|
+
end
|
28
|
+
nil
|
48
29
|
end
|
49
|
-
nil
|
50
|
-
end
|
51
|
-
$-w = origw
|
52
30
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
31
|
+
def _match? arg, item, idx, &blk
|
32
|
+
if blk
|
33
|
+
args = [ item ]
|
34
|
+
args << idx if idx && blk.arity > 1
|
35
|
+
blk.call(*args)
|
36
|
+
elsif arg == NOT_NIL
|
37
|
+
!item.nil?
|
38
|
+
else
|
39
|
+
arg == item
|
40
|
+
end
|
62
41
|
end
|
63
42
|
end
|
64
43
|
end
|
data/lib/riel/pathname.rb
CHANGED
@@ -9,7 +9,7 @@ class Pathname
|
|
9
9
|
# a compliment to the +dirname+, +basename+, and +extname+ family, this returns
|
10
10
|
# the basename without the extension, e.g. "foo" from "/usr/share/lib/foo.bar".
|
11
11
|
def rootname
|
12
|
-
basename.to_s
|
12
|
+
basename.to_s.sub extname.to_s, ''
|
13
13
|
end
|
14
14
|
|
15
15
|
# Returns an array of the path split into its components.
|
data/lib/riel/rcfile.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
#!/usr/bin/ruby -w
|
2
2
|
# -*- ruby -*-
|
3
3
|
|
4
|
-
|
5
4
|
# Represents a resource file, where '#' is used to comment to end of lines, and
|
6
5
|
# name/value pairs are separated by '=' or ':'.
|
7
6
|
|
8
7
|
class RCFile
|
9
|
-
|
10
8
|
attr_reader :settings
|
11
9
|
|
12
10
|
# Reads the RC file, if it exists, and if a block is passed, calls the block
|
data/lib/riel/regexp.rb
CHANGED
@@ -3,15 +3,12 @@
|
|
3
3
|
|
4
4
|
# Negates the given expression.
|
5
5
|
class NegatedRegexp < Regexp
|
6
|
-
|
7
6
|
def match str
|
8
7
|
!super
|
9
8
|
end
|
10
|
-
|
11
9
|
end
|
12
10
|
|
13
11
|
class Regexp
|
14
|
-
|
15
12
|
# shell expressions to Ruby regular expression sequences
|
16
13
|
SH2RE = Hash[
|
17
14
|
'*' => '.*',
|
@@ -103,7 +100,7 @@ class Regexp
|
|
103
100
|
else
|
104
101
|
pattern.sub!(%r{ ^\/ (.*[^\\]) \/ $ }x) { $1 }
|
105
102
|
end
|
106
|
-
|
103
|
+
|
107
104
|
if wholewords
|
108
105
|
# sanity check:
|
109
106
|
|
@@ -116,7 +113,7 @@ class Regexp
|
|
116
113
|
end.compact
|
117
114
|
|
118
115
|
if errs.length > 0
|
119
|
-
|
116
|
+
raise RuntimeError.new("pattern '#{pattern}' does not " + errs.join(" and ") + " on a word boundary")
|
120
117
|
end
|
121
118
|
pattern = '\b' + pattern + '\b'
|
122
119
|
elsif wholelines
|
@@ -148,5 +145,4 @@ class Regexp
|
|
148
145
|
# applies Perl-style substitution (s/foo/bar/).
|
149
146
|
def self.perl_subst pat
|
150
147
|
end
|
151
|
-
|
152
148
|
end
|
data/lib/riel/setdiff.rb
CHANGED
data/lib/riel/string.rb
CHANGED
@@ -10,98 +10,93 @@
|
|
10
10
|
# Documentation:: Author
|
11
11
|
#
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
#
|
22
|
-
# Returns the string, as a number if it is one, and nil otherwise,
|
23
|
-
#
|
24
|
-
def num
|
25
|
-
begin
|
26
|
-
Integer self
|
27
|
-
rescue ArgumentError
|
28
|
-
nil
|
13
|
+
module RIEL
|
14
|
+
module StringExt
|
15
|
+
#
|
16
|
+
# Returns whether the string ends with the given substring.
|
17
|
+
#
|
18
|
+
def ends_with substr
|
19
|
+
return rindex(substr) == length - substr.length
|
29
20
|
end
|
30
|
-
end
|
31
21
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
22
|
+
#
|
23
|
+
# Returns the string, as a number if it is one, and nil otherwise,
|
24
|
+
#
|
25
|
+
def num
|
26
|
+
begin
|
27
|
+
Integer self
|
28
|
+
rescue ArgumentError
|
29
|
+
nil
|
30
|
+
end
|
31
|
+
end
|
39
32
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
33
|
+
#
|
34
|
+
# Returns a string based on this instance, with the first occurrance of
|
35
|
+
# +other+ removed. +other+ may be a string or regular expression.
|
36
|
+
#
|
37
|
+
def - other
|
38
|
+
sub other, ''
|
39
|
+
end
|
44
40
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
41
|
+
#
|
42
|
+
# Represents infinity, for the +to_ranges+ function.
|
43
|
+
#
|
44
|
+
Infinity = (1.0 / 0)
|
49
45
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
str.to_ranges args
|
55
|
-
end
|
46
|
+
# :stopdoc:
|
47
|
+
# from (maybe to this)
|
48
|
+
RANGE_REGEXP = %r{^ \s* (\d*) (?: \s* (\-|\.\.) \s* (\d*) )? \s* $ }x
|
49
|
+
# :startdoc:
|
56
50
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
ranges = Array.new
|
79
|
-
self.split(%r{\s*,\s*}).each do |section|
|
80
|
-
md = section.match(RANGE_REGEXP)
|
81
|
-
next unless md
|
51
|
+
#
|
52
|
+
# Splits num into array of ranges, limiting itself to +args[:min]+ and +args[:max]+,
|
53
|
+
# if specified. The +args[:collapse]+, if true, results in sequential values put
|
54
|
+
# into the same range.
|
55
|
+
#
|
56
|
+
# Examples:
|
57
|
+
#
|
58
|
+
# "1,2".to_ranges # [ 1 .. 1, 2 .. 2 ]
|
59
|
+
# "1,2".to_ranges :collapse => true # [ 1 .. 2 ]
|
60
|
+
# "1-4".to_ranges # [ 1 .. 4 ]
|
61
|
+
# "1-3,5-6,10,11,12,".to_ranges :collapse => true # [ 1 .. 3, 5 .. 6, 10 .. 12 ]
|
62
|
+
# "1-3,5-6,10,11,12,".to_ranges # [ 1 .. 3, 5 .. 6, 10 .. 10, 11 .. 11, 12 .. 12 ]
|
63
|
+
# "-4".to_ranges # [ -String::Infinity .. 4 ]
|
64
|
+
# "4-".to_ranges # [ 4 .. String::Infinity ]
|
65
|
+
# "1-".to_ranges :min => 0, :max => 8 # [ 1 .. 8 ]
|
66
|
+
#
|
67
|
+
def to_ranges args = Hash.new
|
68
|
+
min = args[:min] || -Infinity
|
69
|
+
max = args[:max] || Infinity
|
70
|
+
collapse = args[:collapse]
|
82
71
|
|
83
|
-
|
84
|
-
|
72
|
+
ranges = Array.new
|
73
|
+
self.split(%r{\s*,\s*}).each do |section|
|
74
|
+
md = section.match(RANGE_REGEXP)
|
75
|
+
next unless md
|
76
|
+
|
77
|
+
from = _matchdata_to_number md, 1, min
|
78
|
+
to = _has_matchdata?(md, 2) ? _matchdata_to_number(md, 3, max) : from
|
85
79
|
|
86
|
-
|
80
|
+
prevrange = ranges[-1]
|
87
81
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
82
|
+
if collapse && prevrange && prevrange.include?(from - 1) && prevrange.include?(to - 1)
|
83
|
+
ranges[-1] = (prevrange.first .. to)
|
84
|
+
else
|
85
|
+
ranges << (from .. to)
|
86
|
+
end
|
92
87
|
end
|
93
|
-
end
|
94
88
|
|
95
|
-
|
96
|
-
|
89
|
+
ranges
|
90
|
+
end
|
97
91
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
92
|
+
# :stopdoc:
|
93
|
+
def _has_matchdata? md, idx
|
94
|
+
md && md[idx] && !md[idx].empty?
|
95
|
+
end
|
102
96
|
|
103
|
-
|
104
|
-
|
97
|
+
def _matchdata_to_number md, idx, default
|
98
|
+
_has_matchdata?(md, idx) ? md[idx].to_i : default
|
99
|
+
end
|
100
|
+
# :startdoc:
|
105
101
|
end
|
106
|
-
# :startdoc:
|
107
102
|
end
|
data/lib/riel/timer.rb
CHANGED
@@ -1,17 +1,16 @@
|
|
1
1
|
#!/usr/bin/ruby -w
|
2
2
|
# -*- ruby -*-
|
3
3
|
|
4
|
-
require '
|
4
|
+
require 'logue/log'
|
5
5
|
|
6
6
|
class Timer
|
7
|
-
|
8
7
|
def initialize what, args = Hash.new
|
9
8
|
if args.kind_of? Fixnum
|
10
9
|
args = { :level => args }
|
11
10
|
end
|
12
11
|
|
13
12
|
@io = args[:io] || $stdout
|
14
|
-
@level = args[:level] || Log::DEBUG
|
13
|
+
@level = args[:level] || Logue::Log::DEBUG
|
15
14
|
|
16
15
|
stmsg = args.include?(:startmsg) ? args[:startmsg] : "#{what} start time"
|
17
16
|
endmsg = args.include?(:endmsg) ? args[:endmsg] : "#{what} end time"
|
@@ -34,19 +33,18 @@ class Timer
|
|
34
33
|
if @io
|
35
34
|
@io.puts "#{msg}: #{value}"
|
36
35
|
else
|
37
|
-
Log.log "#{msg}: #{value}", @level
|
36
|
+
Logue::Logue::Log.log "#{msg}: #{value}", @level
|
38
37
|
end
|
39
38
|
end
|
40
39
|
end
|
41
|
-
|
42
40
|
end
|
43
41
|
|
44
42
|
def timethis what
|
45
43
|
sttime = Time.new
|
46
|
-
Log.log "#{what} start time: #{sttime}"
|
44
|
+
Logue::Log.log "#{what} start time: #{sttime}"
|
47
45
|
yield
|
48
46
|
endtime = Time.new
|
49
|
-
Log.log "#{what} start time: #{sttime}"
|
50
|
-
Log.log "#{what} end time : #{endtime}"
|
51
|
-
Log.log "#{what} elapsed : #{endtime - sttime}"
|
47
|
+
Logue::Log.log "#{what} start time: #{sttime}"
|
48
|
+
Logue::Log.log "#{what} end time : #{endtime}"
|
49
|
+
Logue::Log.log "#{what} elapsed : #{endtime - sttime}"
|
52
50
|
end
|
data/lib/riel.rb
CHANGED
data/test/riel/date_test.rb
CHANGED