wishdev-rio 0.4.3.1
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.
- data/COPYING +341 -0
- data/README +81 -0
- data/Rakefile +281 -0
- data/build_doc.rb +94 -0
- data/doc/ANNOUNCE +159 -0
- data/doc/RELEASE_NOTES +308 -0
- data/doc/RIOIS +215 -0
- data/doc/generators/template/html/rio.css +428 -0
- data/doc/generators/template/html/rio.rb +523 -0
- data/doc/generators/template/html/ugly.rb +132 -0
- data/doc/pkg_def.rb +60 -0
- data/doc/rfc1738.txt +1403 -0
- data/doc/rfc959.txt +3933 -0
- data/ex/catcsv.rb +64 -0
- data/ex/colx.rb +8 -0
- data/ex/findinruby +15 -0
- data/ex/findruby +14 -0
- data/ex/passwd_report.rb +8 -0
- data/ex/prompt.rb +25 -0
- data/ex/rgb.txt.gz +0 -0
- data/ex/riocat +42 -0
- data/ex/riogunzip +31 -0
- data/ex/riogzip +24 -0
- data/ex/rioprompt.rb +10 -0
- data/ex/targz2zip +17 -0
- data/ex/tonl +10 -0
- data/lib/rio/abstract_method.rb +56 -0
- data/lib/rio/argv.rb +56 -0
- data/lib/rio/arycopy.rb +43 -0
- data/lib/rio/assert.rb +114 -0
- data/lib/rio/base.rb +56 -0
- data/lib/rio/callstr.rb +46 -0
- data/lib/rio/const.rb +51 -0
- data/lib/rio/construct.rb +50 -0
- data/lib/rio/constructor.rb +258 -0
- data/lib/rio/context/autoclose.rb +72 -0
- data/lib/rio/context/copying.rb +55 -0
- data/lib/rio/context/cxx.rb +66 -0
- data/lib/rio/context/dir.rb +120 -0
- data/lib/rio/context/gzip.rb +50 -0
- data/lib/rio/context/methods.rb +182 -0
- data/lib/rio/context/skip.rb +66 -0
- data/lib/rio/context/stream.rb +229 -0
- data/lib/rio/context.rb +117 -0
- data/lib/rio/cp.rb +370 -0
- data/lib/rio/def.rb +53 -0
- data/lib/rio/dir.rb +144 -0
- data/lib/rio/doc/EXAMPLES.rb +299 -0
- data/lib/rio/doc/HOWTO.rb +737 -0
- data/lib/rio/doc/INDEX.rb +311 -0
- data/lib/rio/doc/INTRO.rb +1068 -0
- data/lib/rio/doc/OPTIONAL.rb +130 -0
- data/lib/rio/doc/SYNOPSIS.rb +183 -0
- data/lib/rio/doc.rb +45 -0
- data/lib/rio/entrysel.rb +246 -0
- data/lib/rio/exception/copy.rb +97 -0
- data/lib/rio/exception/notimplemented.rb +57 -0
- data/lib/rio/exception/notsupported.rb +46 -0
- data/lib/rio/exception/open.rb +61 -0
- data/lib/rio/exception/state.rb +73 -0
- data/lib/rio/exception.rb +41 -0
- data/lib/rio/ext/csv.rb +351 -0
- data/lib/rio/ext/if.rb +45 -0
- data/lib/rio/ext/mp3info.rb +80 -0
- data/lib/rio/ext/splitlines.rb +253 -0
- data/lib/rio/ext/yaml/doc.rb +133 -0
- data/lib/rio/ext/yaml/tie.rb +149 -0
- data/lib/rio/ext/yaml.rb +164 -0
- data/lib/rio/ext/zipfile/fs.rb +116 -0
- data/lib/rio/ext/zipfile/rl.rb +251 -0
- data/lib/rio/ext/zipfile/rootdir.rb +117 -0
- data/lib/rio/ext/zipfile/state.rb +161 -0
- data/lib/rio/ext/zipfile/wrap.rb +204 -0
- data/lib/rio/ext/zipfile.rb +110 -0
- data/lib/rio/ext.rb +138 -0
- data/lib/rio/factory.rb +436 -0
- data/lib/rio/file.rb +118 -0
- data/lib/rio/filter/closeoneof.rb +103 -0
- data/lib/rio/filter/gzip.rb +70 -0
- data/lib/rio/filter.rb +94 -0
- data/lib/rio/fs/base.rb +41 -0
- data/lib/rio/fs/impl.rb +122 -0
- data/lib/rio/fs/native.rb +75 -0
- data/lib/rio/fs/stream.rb +61 -0
- data/lib/rio/fs/url.rb +63 -0
- data/lib/rio/ftp/conncache.rb +101 -0
- data/lib/rio/ftp/dir.rb +94 -0
- data/lib/rio/ftp/fs.rb +180 -0
- data/lib/rio/ftp/ftpfile.rb +20 -0
- data/lib/rio/grande.rb +97 -0
- data/lib/rio/handle.rb +100 -0
- data/lib/rio/if/basic.rb +64 -0
- data/lib/rio/if/csv.rb +76 -0
- data/lib/rio/if/dir.rb +157 -0
- data/lib/rio/if/file.rb +89 -0
- data/lib/rio/if/fileordir.rb +268 -0
- data/lib/rio/if/grande.rb +729 -0
- data/lib/rio/if/grande_entry.rb +379 -0
- data/lib/rio/if/grande_stream.rb +693 -0
- data/lib/rio/if/internal.rb +125 -0
- data/lib/rio/if/path.rb +462 -0
- data/lib/rio/if/rubyio.rb +681 -0
- data/lib/rio/if/string.rb +83 -0
- data/lib/rio/if/temp.rb +45 -0
- data/lib/rio/if/test.rb +282 -0
- data/lib/rio/if/yaml.rb +206 -0
- data/lib/rio/if.rb +64 -0
- data/lib/rio/ioh.rb +162 -0
- data/lib/rio/iomode.rb +109 -0
- data/lib/rio/ios/fail.rb +106 -0
- data/lib/rio/ios/generic.rb +119 -0
- data/lib/rio/ios/mode.rb +60 -0
- data/lib/rio/ios/null.rb +119 -0
- data/lib/rio/iowrap.rb +128 -0
- data/lib/rio/kernel.rb +54 -0
- data/lib/rio/local.rb +62 -0
- data/lib/rio/match.rb +53 -0
- data/lib/rio/matchrecord.rb +283 -0
- data/lib/rio/no_warn.rb +49 -0
- data/lib/rio/nullio.rb +159 -0
- data/lib/rio/open3.rb +68 -0
- data/lib/rio/ops/construct.rb +61 -0
- data/lib/rio/ops/create.rb +77 -0
- data/lib/rio/ops/dir.rb +346 -0
- data/lib/rio/ops/either.rb +134 -0
- data/lib/rio/ops/file.rb +102 -0
- data/lib/rio/ops/path.rb +296 -0
- data/lib/rio/ops/stream/input.rb +267 -0
- data/lib/rio/ops/stream/output.rb +100 -0
- data/lib/rio/ops/stream/read.rb +86 -0
- data/lib/rio/ops/stream/write.rb +57 -0
- data/lib/rio/ops/stream.rb +87 -0
- data/lib/rio/ops/symlink.rb +80 -0
- data/lib/rio/path/reset.rb +69 -0
- data/lib/rio/path.rb +129 -0
- data/lib/rio/piper/cp.rb +80 -0
- data/lib/rio/piper.rb +122 -0
- data/lib/rio/prompt.rb +66 -0
- data/lib/rio/rectype.rb +88 -0
- data/lib/rio/rl/base.rb +118 -0
- data/lib/rio/rl/builder.rb +117 -0
- data/lib/rio/rl/chmap.rb +66 -0
- data/lib/rio/rl/fs2url.rb +82 -0
- data/lib/rio/rl/ioi.rb +78 -0
- data/lib/rio/rl/path.rb +110 -0
- data/lib/rio/rl/pathmethods.rb +116 -0
- data/lib/rio/rl/uri.rb +200 -0
- data/lib/rio/rl/withpath.rb +296 -0
- data/lib/rio/scheme/aryio.rb +88 -0
- data/lib/rio/scheme/cmdio.rb +80 -0
- data/lib/rio/scheme/cmdpipe.rb +118 -0
- data/lib/rio/scheme/fd.rb +65 -0
- data/lib/rio/scheme/ftp.rb +141 -0
- data/lib/rio/scheme/http.rb +78 -0
- data/lib/rio/scheme/null.rb +55 -0
- data/lib/rio/scheme/path.rb +98 -0
- data/lib/rio/scheme/stderr.rb +55 -0
- data/lib/rio/scheme/stdio.rb +71 -0
- data/lib/rio/scheme/strio.rb +87 -0
- data/lib/rio/scheme/sysio.rb +63 -0
- data/lib/rio/scheme/tcp.rb +75 -0
- data/lib/rio/scheme/temp.rb +200 -0
- data/lib/rio/state/error.rb +72 -0
- data/lib/rio/state.rb +242 -0
- data/lib/rio/stream/base.rb +54 -0
- data/lib/rio/stream/duplex.rb +79 -0
- data/lib/rio/stream/open.rb +202 -0
- data/lib/rio/stream.rb +181 -0
- data/lib/rio/symantics.rb +45 -0
- data/lib/rio/tempdir.rb +132 -0
- data/lib/rio/to_rio/all.rb +39 -0
- data/lib/rio/to_rio/array.rb +39 -0
- data/lib/rio/to_rio/io.rb +40 -0
- data/lib/rio/to_rio/object.rb +42 -0
- data/lib/rio/to_rio/string.rb +40 -0
- data/lib/rio/to_rio.rb +67 -0
- data/lib/rio/uri/file.rb +198 -0
- data/lib/rio/util.rb +48 -0
- data/lib/rio/version.rb +51 -0
- data/lib/rio.rb +162 -0
- data/setup.rb +1360 -0
- data/test/bin/count_lines.rb +11 -0
- data/test/bin/find_lines.rb +13 -0
- data/test/bin/list_dir.rb +14 -0
- data/test/ftp/all.rb +9 -0
- data/test/ftp/anon_copy_data.rb +36 -0
- data/test/ftp/anon_misc.rb +124 -0
- data/test/ftp/anon_read.rb +105 -0
- data/test/ftp/anon_special.rb +68 -0
- data/test/ftp/anon_write.rb +70 -0
- data/test/ftp/ftp2ftp.rb +51 -0
- data/test/ftp/initftpfiles.rb +14 -0
- data/test/ftp/testdef.rb +55 -0
- data/test/gem_runtests.rb +15 -0
- data/test/http/all.rb +4 -0
- data/test/http/copy-from-http.rb +141 -0
- data/test/http/uri-meta.rb +72 -0
- data/test/lib/temp_server.rb +46 -0
- data/test/runalltests.rb +17 -0
- data/test/runftptests.rb +14 -0
- data/test/runhttp.rb +11 -0
- data/test/runhttptests.rb +14 -0
- data/test/runtests.rb +52 -0
- data/test/tc/abs.rb +355 -0
- data/test/tc/all.rb +80 -0
- data/test/tc/base.rb +31 -0
- data/test/tc/base2.rb +87 -0
- data/test/tc/cd1.rb +113 -0
- data/test/tc/clearsel.rb +68 -0
- data/test/tc/clone.rb +208 -0
- data/test/tc/closeoncopy.rb +102 -0
- data/test/tc/closeoneof.rb +194 -0
- data/test/tc/cmdpipe.rb +149 -0
- data/test/tc/copy-dir-samevar.rb +91 -0
- data/test/tc/copy-from.rb +129 -0
- data/test/tc/copy-to.rb +91 -0
- data/test/tc/copy.rb +74 -0
- data/test/tc/copyarray.rb +188 -0
- data/test/tc/copydest.rb +50 -0
- data/test/tc/copydir.rb +166 -0
- data/test/tc/copydirlines.rb +121 -0
- data/test/tc/copylines.rb +46 -0
- data/test/tc/copynonex.rb +118 -0
- data/test/tc/copysymlink.rb +39 -0
- data/test/tc/create.rb +114 -0
- data/test/tc/csv.rb +226 -0
- data/test/tc/csv2.rb +138 -0
- data/test/tc/csv_columns.rb +37 -0
- data/test/tc/csvutil.rb +56 -0
- data/test/tc/dir.rb +76 -0
- data/test/tc/dir_iter.rb +383 -0
- data/test/tc/dirautoclose.rb +67 -0
- data/test/tc/dirent.rb +178 -0
- data/test/tc/dirss.rb +81 -0
- data/test/tc/each.rb +111 -0
- data/test/tc/each_break.rb +243 -0
- data/test/tc/edf.rb +81 -0
- data/test/tc/empty.rb +51 -0
- data/test/tc/emptyriodir.rb +129 -0
- data/test/tc/entary.rb +227 -0
- data/test/tc/entsel.rb +110 -0
- data/test/tc/eq.rb +101 -0
- data/test/tc/expand_path.rb +69 -0
- data/test/tc/ext.rb +136 -0
- data/test/tc/fileno.rb +94 -0
- data/test/tc/files_select.rb +92 -0
- data/test/tc/get.rb +152 -0
- data/test/tc/getrec.rb +137 -0
- data/test/tc/gzip.rb +109 -0
- data/test/tc/io_each_byte.rb +60 -0
- data/test/tc/io_read.rb +80 -0
- data/test/tc/iometh.rb +149 -0
- data/test/tc/likeio.rb +116 -0
- data/test/tc/line_record_row.rb +51 -0
- data/test/tc/lineno.rb +196 -0
- data/test/tc/lines.rb +66 -0
- data/test/tc/misc.rb +432 -0
- data/test/tc/nolines.rb +204 -0
- data/test/tc/noqae.rb +879 -0
- data/test/tc/null.rb +45 -0
- data/test/tc/once.rb +6 -0
- data/test/tc/overload.rb +140 -0
- data/test/tc/pa.rb +158 -0
- data/test/tc/path_parts.rb +175 -0
- data/test/tc/pathop.rb +60 -0
- data/test/tc/paths.rb +145 -0
- data/test/tc/pid.rb +31 -0
- data/test/tc/piper.rb +143 -0
- data/test/tc/programs_util.rb +24 -0
- data/test/tc/qae.rb +493 -0
- data/test/tc/qae_riovar.rb +499 -0
- data/test/tc/readline.rb +30 -0
- data/test/tc/records.rb +68 -0
- data/test/tc/rename.rb +233 -0
- data/test/tc/rename_assign.rb +45 -0
- data/test/tc/riorl.rb +181 -0
- data/test/tc/route.rb +51 -0
- data/test/tc/selnosel.rb +33 -0
- data/test/tc/skip.rb +89 -0
- data/test/tc/skiplines.rb +71 -0
- data/test/tc/split.rb +28 -0
- data/test/tc/splitlines.rb +65 -0
- data/test/tc/splitpath.rb +83 -0
- data/test/tc/sub.rb +46 -0
- data/test/tc/symlink.rb +176 -0
- data/test/tc/symlink0.rb +348 -0
- data/test/tc/symlink1.rb +114 -0
- data/test/tc/synopsis.rb +75 -0
- data/test/tc/temp.rb +152 -0
- data/test/tc/tempdir.rb +60 -0
- data/test/tc/tempfile.rb +66 -0
- data/test/tc/testcase.rb +170 -0
- data/test/tc/tonl.rb +37 -0
- data/test/tc/truncate.rb +39 -0
- data/test/tc/yaml.rb +275 -0
- metadata +387 -0
data/lib/rio/def.rb
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# ===============================================================================
|
|
3
|
+
# Copyright (c) 2005,2006,2007 Christopher Kleckner
|
|
4
|
+
# All rights reserved
|
|
5
|
+
#
|
|
6
|
+
# This file is part of the Rio library for ruby.
|
|
7
|
+
#
|
|
8
|
+
# Rio is free software; you can redistribute it and/or modify
|
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
|
10
|
+
# the Free Software Foundation; either version 2 of the License, or
|
|
11
|
+
# (at your option) any later version.
|
|
12
|
+
#
|
|
13
|
+
# Rio is distributed in the hope that it will be useful,
|
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+
# GNU General Public License for more details.
|
|
17
|
+
#
|
|
18
|
+
# You should have received a copy of the GNU General Public License
|
|
19
|
+
# along with Rio; if not, write to the Free Software
|
|
20
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
21
|
+
# ===============================================================================
|
|
22
|
+
#++
|
|
23
|
+
#
|
|
24
|
+
# To create the documentation for Rio run the command
|
|
25
|
+
# ruby build_doc.rb
|
|
26
|
+
# from the distribution directory.
|
|
27
|
+
#
|
|
28
|
+
# Suggested Reading
|
|
29
|
+
# * RIO::Doc::SYNOPSIS
|
|
30
|
+
# * RIO::Doc::INTRO
|
|
31
|
+
# * RIO::Doc::HOWTO
|
|
32
|
+
# * RIO::Doc::EXAMPLES
|
|
33
|
+
# * RIO::Rio
|
|
34
|
+
#
|
|
35
|
+
|
|
36
|
+
require 'rio/base'
|
|
37
|
+
|
|
38
|
+
module RIO
|
|
39
|
+
# See also: RIO::Doc::SYNOPSIS; RIO::Doc::INTRO; RIO::Doc::HOWTO.
|
|
40
|
+
class Rio < Base #:doc:
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
if $0 == __FILE__
|
|
45
|
+
eval DATA.read, nil, $0, __LINE__+4
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
__END__
|
|
49
|
+
|
|
50
|
+
puts
|
|
51
|
+
puts("Run the tests that came with the distribution")
|
|
52
|
+
puts("From the distribution directory use 'test/runtests.rb'")
|
|
53
|
+
puts
|
data/lib/rio/dir.rb
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# ===============================================================================
|
|
3
|
+
# Copyright (c) 2005,2006,2007 Christopher Kleckner
|
|
4
|
+
# All rights reserved
|
|
5
|
+
#
|
|
6
|
+
# This file is part of the Rio library for ruby.
|
|
7
|
+
#
|
|
8
|
+
# Rio is free software; you can redistribute it and/or modify
|
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
|
10
|
+
# the Free Software Foundation; either version 2 of the License, or
|
|
11
|
+
# (at your option) any later version.
|
|
12
|
+
#
|
|
13
|
+
# Rio is distributed in the hope that it will be useful,
|
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+
# GNU General Public License for more details.
|
|
17
|
+
#
|
|
18
|
+
# You should have received a copy of the GNU General Public License
|
|
19
|
+
# along with Rio; if not, write to the Free Software
|
|
20
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
21
|
+
# ===============================================================================
|
|
22
|
+
#++
|
|
23
|
+
#
|
|
24
|
+
# To create the documentation for Rio run the command
|
|
25
|
+
# ruby build_doc.rb
|
|
26
|
+
# from the distribution directory.
|
|
27
|
+
#
|
|
28
|
+
# Suggested Reading
|
|
29
|
+
# * RIO::Doc::SYNOPSIS
|
|
30
|
+
# * RIO::Doc::INTRO
|
|
31
|
+
# * RIO::Doc::HOWTO
|
|
32
|
+
# * RIO::Doc::EXAMPLES
|
|
33
|
+
# * RIO::Rio
|
|
34
|
+
#
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
require 'rio/ops/path'
|
|
38
|
+
require 'rio/ops/dir'
|
|
39
|
+
require 'rio/filter/closeoneof'
|
|
40
|
+
require 'rio/ioh'
|
|
41
|
+
module RIO
|
|
42
|
+
module Dir #:nodoc: all
|
|
43
|
+
class Base < State::Base
|
|
44
|
+
include Ops::Path::Str
|
|
45
|
+
def open?() !ioh.nil? end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
class NonExisting < Base
|
|
49
|
+
include Ops::Dir::NonExisting
|
|
50
|
+
def check?() not self.exist? end
|
|
51
|
+
def when_missing(sym,*args) gofigure(sym,*args) end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
class Existing < Base
|
|
55
|
+
include Ops::Dir::Existing
|
|
56
|
+
|
|
57
|
+
def check?() self.directory? end
|
|
58
|
+
def when_missing(sym,*args) dopen() end
|
|
59
|
+
|
|
60
|
+
protected
|
|
61
|
+
|
|
62
|
+
def stream_rl_
|
|
63
|
+
self.rl.dir_rl()
|
|
64
|
+
#RIO::Dir::RL.new(self.to_uri, {:fs => self.fs})
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
public
|
|
68
|
+
|
|
69
|
+
def dopen()
|
|
70
|
+
self.rl = self.stream_rl_
|
|
71
|
+
become 'Dir::Open'
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
class Open < Base
|
|
75
|
+
def check?() true end
|
|
76
|
+
def open(m=nil,*args) open_(*args) end
|
|
77
|
+
def open_(*args)
|
|
78
|
+
unless open?
|
|
79
|
+
self.ioh = self.rl.open()
|
|
80
|
+
end
|
|
81
|
+
self
|
|
82
|
+
end
|
|
83
|
+
def when_missing(sym,*args)
|
|
84
|
+
nobj = open_.dstream()
|
|
85
|
+
return nobj unless nobj.nil?
|
|
86
|
+
gofigure(sym,*args)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def dstream()
|
|
90
|
+
cl = 'Dir::Stream'
|
|
91
|
+
#p "LOOP: retry: #{cx['retrystate'].inspect} => #{cl}"
|
|
92
|
+
return nil if cx['retrystate'] == cl
|
|
93
|
+
cx['retrystate'] = cl
|
|
94
|
+
|
|
95
|
+
become(cl)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
class Stream < Base
|
|
99
|
+
include Ops::Dir::Stream
|
|
100
|
+
def check?() open? end
|
|
101
|
+
def when_missing(sym,*args) retryreset() end
|
|
102
|
+
def base_state() 'Dir::Close' end
|
|
103
|
+
def reset() self.close.softreset() end
|
|
104
|
+
alias :copyclose :reset
|
|
105
|
+
end
|
|
106
|
+
class Close < Base
|
|
107
|
+
def reopen(*args) self.close_.softreset.open(*args) end
|
|
108
|
+
|
|
109
|
+
def close()
|
|
110
|
+
#p callstr('close')+" mode='#{mode?}' ioh=#{self.ioh} open?=#{open?}"
|
|
111
|
+
return self unless self.open?
|
|
112
|
+
self.close_
|
|
113
|
+
cx['retrystate'] = nil
|
|
114
|
+
self
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def close_()
|
|
118
|
+
#p callstr('close_')+" ioh=#{self.ioh} open?=#{open?}"
|
|
119
|
+
return self unless self.open?
|
|
120
|
+
self.clear_selection
|
|
121
|
+
self.ioh.close
|
|
122
|
+
self.ioh = nil
|
|
123
|
+
self.rl.close
|
|
124
|
+
self
|
|
125
|
+
end
|
|
126
|
+
protected :close_
|
|
127
|
+
|
|
128
|
+
CX_ENTRY_SEL_KEYS = %w[nostreamenum entry_sel skip_args ss_skipped]
|
|
129
|
+
def clear_selection()
|
|
130
|
+
CX_ENTRY_SEL_KEYS.each { |k|
|
|
131
|
+
cx.delete(k)
|
|
132
|
+
}
|
|
133
|
+
self
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def check?() true end
|
|
137
|
+
def when_missing(sym,*args)
|
|
138
|
+
# p callstr('when_missing',sym,*args)
|
|
139
|
+
self.close_.retryreset()
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
end # module RIO
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# ===============================================================================
|
|
3
|
+
# Copyright (c) 2005,2006,2007 Christopher Kleckner
|
|
4
|
+
# All rights reserved
|
|
5
|
+
#
|
|
6
|
+
# This file is part of the Rio library for ruby.
|
|
7
|
+
#
|
|
8
|
+
# Rio is free software; you can redistribute it and/or modify
|
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
|
10
|
+
# the Free Software Foundation; either version 2 of the License, or
|
|
11
|
+
# (at your option) any later version.
|
|
12
|
+
#
|
|
13
|
+
# Rio is distributed in the hope that it will be useful,
|
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+
# GNU General Public License for more details.
|
|
17
|
+
#
|
|
18
|
+
# You should have received a copy of the GNU General Public License
|
|
19
|
+
# along with Rio; if not, write to the Free Software
|
|
20
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
21
|
+
# ===============================================================================
|
|
22
|
+
#++
|
|
23
|
+
#
|
|
24
|
+
# To create the documentation for Rio run the command
|
|
25
|
+
# ruby build_doc.rb
|
|
26
|
+
# from the distribution directory.
|
|
27
|
+
#
|
|
28
|
+
# Suggested Reading
|
|
29
|
+
# * RIO::Doc::SYNOPSIS
|
|
30
|
+
# * RIO::Doc::INTRO
|
|
31
|
+
# * RIO::Doc::HOWTO
|
|
32
|
+
# * RIO::Doc::EXAMPLES
|
|
33
|
+
# * RIO::Rio
|
|
34
|
+
#
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
module RIO
|
|
38
|
+
module Doc
|
|
39
|
+
=begin rdoc
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
The following examples are provided without comment
|
|
44
|
+
|
|
45
|
+
array = rio('afile').readlines
|
|
46
|
+
|
|
47
|
+
rio('afile') > rio('acopy')
|
|
48
|
+
|
|
49
|
+
ary = rio('afile').chomp.lines[0...10]
|
|
50
|
+
|
|
51
|
+
rio('adir').rename.all.files('*.htm') do |file|
|
|
52
|
+
file.ext = '.html'
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
A basic familiarity with ruby and shell operations should allow a
|
|
56
|
+
casual reader to guess what these examples will do. How they are being
|
|
57
|
+
performed may not be what a casual reader might expect. I will
|
|
58
|
+
explain these example to illustrate the Rio basics.
|
|
59
|
+
|
|
60
|
+
For many more examples please read the HOWTO document and the rdoc
|
|
61
|
+
documentation.
|
|
62
|
+
|
|
63
|
+
== Example 1.
|
|
64
|
+
|
|
65
|
+
array = rio('afile').readlines
|
|
66
|
+
|
|
67
|
+
This uses IO#readlines to read the lines of 'afile' into an array.
|
|
68
|
+
|
|
69
|
+
=== Creating a Rio
|
|
70
|
+
|
|
71
|
+
Rio extends the module Kernel by adding one function +rio+, which acts
|
|
72
|
+
as a constructor returning a Rio. This constructor builds a
|
|
73
|
+
description of the resource the Rio will access (usually a path). It
|
|
74
|
+
does not open the resource, check for its existance, or do anything
|
|
75
|
+
except remember its specifcation. _rio_ returns the Rio which can be
|
|
76
|
+
chained to a Rio method as in this example or stored in a
|
|
77
|
+
variable. This coud have been written
|
|
78
|
+
|
|
79
|
+
ario = rio('afile')
|
|
80
|
+
array = ario.readlines
|
|
81
|
+
|
|
82
|
+
ario = rio('afile')
|
|
83
|
+
|
|
84
|
+
In this case the resource specified is a relative path. After the
|
|
85
|
+
first line the Rio does know or care whether it is a path to a file
|
|
86
|
+
nor whether it exists. Rio provides many methods that only deal with a
|
|
87
|
+
resource at this level, much as the standard library classes Pathname
|
|
88
|
+
and URI. It should be noted at this point that Rio paths stored
|
|
89
|
+
internally as a URL as specified in RFC 1738 and therefore use slashes
|
|
90
|
+
as separators. A resource can also be specified without separators,
|
|
91
|
+
because _rio_ interprets multiple arguments as parts of a path to be
|
|
92
|
+
joined, and an array as an array of parts to be joined. So the
|
|
93
|
+
following all specify the same resource.
|
|
94
|
+
|
|
95
|
+
rio('adir/afile')
|
|
96
|
+
rio('adir','afile')
|
|
97
|
+
rio(%w/adir afile/)
|
|
98
|
+
|
|
99
|
+
The rio constructor can be used to specify non-file-system resources,
|
|
100
|
+
but for this example we will restrict our discussion to paths to
|
|
101
|
+
entities on file-systems.
|
|
102
|
+
|
|
103
|
+
array = ario.readlines
|
|
104
|
+
|
|
105
|
+
Now that we have a Rio, we can call one of its methods; in this case
|
|
106
|
+
_readlines_. This is an example of using a Rio as a proxy for the
|
|
107
|
+
builtin IO#readlines. Given the method _readlines_, the Rio opens
|
|
108
|
+
'afile' for reading, calls readlines on the resulting IO object,
|
|
109
|
+
closes the IO object, and returns the lines read.
|
|
110
|
+
|
|
111
|
+
== Example 2
|
|
112
|
+
|
|
113
|
+
rio('afile') > rio('acopy')
|
|
114
|
+
|
|
115
|
+
This copies the file 'afile' into the file 'acopy'.
|
|
116
|
+
|
|
117
|
+
The first things that happen here are the creation of the Rios. As
|
|
118
|
+
described in Example 1, when created a Rio simply remembers the
|
|
119
|
+
specifcation of its resource. In this case, a relative path 'afile' on
|
|
120
|
+
the left and a relative path 'acopy' on the right.
|
|
121
|
+
|
|
122
|
+
Next the Rio#> (copy-to) method is called on the 'afile' Rio with the
|
|
123
|
+
'acopy' Rio as its argument. If that looks like a greater-than
|
|
124
|
+
operator to you, think Unix shell, with Rios '>' is the copy-to
|
|
125
|
+
operator.
|
|
126
|
+
|
|
127
|
+
Upon seeing the copy-to operator, the Rio has all the information it
|
|
128
|
+
needs to proceed. It determines that it must be opened for reading,
|
|
129
|
+
that its argument must be opened for writing, and that it's contents
|
|
130
|
+
must be copied to the resource referenced by it' argument -- and that
|
|
131
|
+
is what it does. Then it closes itself and its argument.
|
|
132
|
+
|
|
133
|
+
Consider if we had written this example this way.
|
|
134
|
+
|
|
135
|
+
afile = rio('afile')
|
|
136
|
+
acopy = rio('acopy')
|
|
137
|
+
afile > acopy
|
|
138
|
+
|
|
139
|
+
In this case we would still have variables referencing the Rios, and
|
|
140
|
+
perhaps we would like do things a little differently than described
|
|
141
|
+
above. Be assured that the selection of mode and automatic closing of
|
|
142
|
+
files are the default behaviour and can be changed. Say we wanted
|
|
143
|
+
'afile' to remain open so that we could rewind it and make a second
|
|
144
|
+
copy, we might do something like this:
|
|
145
|
+
|
|
146
|
+
afile = rio('afile').nocloseoneof
|
|
147
|
+
afile > rio('acopy1')
|
|
148
|
+
afile.rewind > rio('acopy2')
|
|
149
|
+
afile.close
|
|
150
|
+
|
|
151
|
+
Actually the 'thinking process' of the Rio when it sees a copy-to
|
|
152
|
+
operator is much more complex than that described above. If its
|
|
153
|
+
argument had been a rio referencing a directory, it would not have
|
|
154
|
+
opened itself for reading, but instead used FileUtils#cp to copy
|
|
155
|
+
itself; if its argument had been a string, its contents would have
|
|
156
|
+
ended up in the string; If its argument had been an array, its lines
|
|
157
|
+
would been elements of that array; if its argument had been a socket,
|
|
158
|
+
the its contents would have been copied to the socket. See the
|
|
159
|
+
documentation for details.
|
|
160
|
+
|
|
161
|
+
== Example 3.
|
|
162
|
+
|
|
163
|
+
array = rio('afile').chomp.lines[0...10]
|
|
164
|
+
|
|
165
|
+
This fills +array+ with the first ten lines of 'afile', with each line chomped
|
|
166
|
+
|
|
167
|
+
The casual observer mentioned above might think that +lines+ returns an array of lines and that this
|
|
168
|
+
is a simple rewording of <tt>array = rio('afile').readlines[0...10]</tt> or even of
|
|
169
|
+
<tt>array = File.new('afile').readlines[0...10]</tt>. They would be wrong.
|
|
170
|
+
|
|
171
|
+
+chomp+ is a configuration method which turns on chomp-mode and returns the Rio. Chomp-mode causes all
|
|
172
|
+
line oriented read operations to perform a String#chomp on each line
|
|
173
|
+
|
|
174
|
+
=== Reading files
|
|
175
|
+
|
|
176
|
+
Rio provides four methods to select which part of the file is read and
|
|
177
|
+
how the file is divided. They are +lines+, +records+, +rows+ and
|
|
178
|
+
+bytes+. Briefly, +lines+ specifies that the file should be read line
|
|
179
|
+
by line and <tt>bytes(n)</tt> specifies that the file should be read
|
|
180
|
+
in _n_ byte chunks. All four take arguments which can be used to
|
|
181
|
+
filter lines or chunks in or out. For simple Rios +records+ and +rows+
|
|
182
|
+
only specify the filter arguments and are provided for use be
|
|
183
|
+
extensions. For example, the CSV extension returns an array of the
|
|
184
|
+
columns in a line when +records+ is used. In the absence of an
|
|
185
|
+
extension +records+ and +rows+ behave like +lines+.
|
|
186
|
+
|
|
187
|
+
First lets rewrite our example as:
|
|
188
|
+
|
|
189
|
+
array = rio('afile').chomp.lines(0...10).to_a
|
|
190
|
+
|
|
191
|
+
The arguments to lines specify which records are to be read.
|
|
192
|
+
Arguments are interpreted based on their class as follows:
|
|
193
|
+
* Range - interpreted as a range of record numbers to be read
|
|
194
|
+
* Integer - interpreted as a one-element range
|
|
195
|
+
* RegExp - only matching records are processed
|
|
196
|
+
* Symbol - sent to each record, which is processed unless the result is false or nil
|
|
197
|
+
* Proc - called for each record, the record is processed unless the return value is false or nil
|
|
198
|
+
See the documentation for details and examples.
|
|
199
|
+
|
|
200
|
+
In our example we have specified the Range (0...10). The +lines+
|
|
201
|
+
method is just configuring the Rio, it does not trigger any IO
|
|
202
|
+
operation. The fact that it was called and the arguments it was called
|
|
203
|
+
with are stored away and the Rio is returned for further configuration
|
|
204
|
+
or an actual IO operation. When an IO operation is called the Range
|
|
205
|
+
will be used to limit processing to the first ten records. For
|
|
206
|
+
example:
|
|
207
|
+
|
|
208
|
+
rio('afile').lines(0...10) { |line| ... } # block will be called for the first 10 records
|
|
209
|
+
rio('afile').lines[0...10] # the first 10 records will be returned in an array
|
|
210
|
+
rio('afile').lines(0...10) > rio('acopy') # the first 10 records will be copied to 'acopy'
|
|
211
|
+
|
|
212
|
+
"But wait", you say, "In our original example the range was an
|
|
213
|
+
argument to the subscript operator, not to +lines+". This works
|
|
214
|
+
because the subscript operator processes its arguments as if they had
|
|
215
|
+
been arguments to the most-recently-called selection method and then
|
|
216
|
+
calls +to_a+ on the rio. So our rewrite of the example does precisely
|
|
217
|
+
the same thing as the original
|
|
218
|
+
|
|
219
|
+
The big difference between the original example and the
|
|
220
|
+
casual-observer's solution is that hers creates an array of the entire
|
|
221
|
+
contents and only returns the first 10 while the original only puts 10
|
|
222
|
+
records into the array.
|
|
223
|
+
|
|
224
|
+
As a sidenote, Rios also have an optimization that can really help in
|
|
225
|
+
certain situations. If records are only selected using Ranges, it
|
|
226
|
+
stops iterating when it is beyond the point where it could possibly
|
|
227
|
+
ever match. This can make a dramatic difference when one is only
|
|
228
|
+
interested in the first few lines of very large files.
|
|
229
|
+
|
|
230
|
+
== Example 4.
|
|
231
|
+
|
|
232
|
+
rio('adir').rename.all.files('*.htm') do |file|
|
|
233
|
+
file.ext = '.html'
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
This changes the extension of all .htm files below 'adir' to '.html'
|
|
237
|
+
|
|
238
|
+
First we create the rio as always.
|
|
239
|
+
|
|
240
|
+
Next we process the +rename+ method. When used as it is here --
|
|
241
|
+
without arguments -- it just turns on rename-mode and returns the Rio.
|
|
242
|
+
|
|
243
|
+
+all+ is another configuration method, which causes directories to be
|
|
244
|
+
processed recursively
|
|
245
|
+
|
|
246
|
+
+files+ is another configuration method. In example 3 we used +lines+
|
|
247
|
+
to select what to process when iterating through a file. +files+ is
|
|
248
|
+
used to select what to process when iterating through directories. The
|
|
249
|
+
arguments to +files+ can be the same as those for +lines+ except that
|
|
250
|
+
Ranges can not be used and globs can.
|
|
251
|
+
|
|
252
|
+
In our example, the argument to +files+ is a string which is treated
|
|
253
|
+
as a glob. As with +lines+, +files+ does not trigger any IO, it just
|
|
254
|
+
configures the Rio.
|
|
255
|
+
|
|
256
|
+
=== There's no action
|
|
257
|
+
|
|
258
|
+
The previous examples had something that triggered IO: +readlines+,
|
|
259
|
+
+to_a+, +each+, <tt>> (copy-to)</tt>. This example does not. This
|
|
260
|
+
example illustrates Rio's 'implied each'. All the configuration
|
|
261
|
+
methods will call each for you if a block is given. So, because a
|
|
262
|
+
block follows the +files+ method, it calls +each+ and passes it the
|
|
263
|
+
block.
|
|
264
|
+
|
|
265
|
+
Let's recap. At this point we have a Rio with a resource specified. We
|
|
266
|
+
have configured with a couple of modes, 'rename', and 'all', and we
|
|
267
|
+
have limited the elements we want to process to entries that are files
|
|
268
|
+
and match the glob '*.htm'. +each+ causes the Rio to open the
|
|
269
|
+
directory and call the block for each entry that is both a file and
|
|
270
|
+
matches the glob. It was also configured with +all+,so it descends
|
|
271
|
+
into subdirectories to find further matches and calles the block for
|
|
272
|
+
each of them. The argument passed to the block is a Rio referencing
|
|
273
|
+
the entry on the file-system.
|
|
274
|
+
|
|
275
|
+
The _rename_mode_ we set has had no effect on our iteration at all, so why is it there? In general,
|
|
276
|
+
configuration options that are not applicable to a Rio are silently ignored, however, for directories
|
|
277
|
+
some of them are passed on to the Rios for each entry when iterating. Since +rename+ is one such option,
|
|
278
|
+
The example could have been written:
|
|
279
|
+
|
|
280
|
+
rio('adir').all.files('*.htm') do |file|
|
|
281
|
+
file.rename.ext = '.html'
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
The rename-with-no-args method affects the behaviour of the <tt>ext=</tt> option. In this case,
|
|
285
|
+
setting it for the directory, rather than for each file in the block seems to make the intent
|
|
286
|
+
of the code more clear, but that is a matter of personal taste. See the documentation for more
|
|
287
|
+
information on the rename-with-no-args method
|
|
288
|
+
|
|
289
|
+
== Suggested Reading
|
|
290
|
+
* RIO::Doc::SYNOPSIS
|
|
291
|
+
* RIO::Doc::INTRO
|
|
292
|
+
* RIO::Doc::HOWTO
|
|
293
|
+
* RIO::Rio
|
|
294
|
+
|
|
295
|
+
=end
|
|
296
|
+
module EXAMPLES
|
|
297
|
+
end
|
|
298
|
+
end
|
|
299
|
+
end
|