rio 0.3.7 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (208) hide show
  1. data/ChangeLog +1273 -1482
  2. data/README +2 -2
  3. data/Rakefile +5 -5
  4. data/VERSION +1 -1
  5. data/{RUNME.1st.rb → build_doc.rb} +4 -10
  6. data/doc/ANNOUNCE +33 -80
  7. data/doc/RELEASE_NOTES +31 -1
  8. data/doc/generators/template/html/rio.rb +3 -3
  9. data/lib/rio/abstract_method.rb +2 -2
  10. data/lib/rio/argv.rb +2 -2
  11. data/lib/rio/arycopy.rb +2 -2
  12. data/lib/rio/assert.rb +2 -2
  13. data/lib/rio/base.rb +2 -2
  14. data/lib/rio/callstr.rb +47 -0
  15. data/lib/rio/const.rb +52 -0
  16. data/lib/rio/construct.rb +6 -24
  17. data/lib/rio/constructor.rb +12 -2
  18. data/lib/rio/context/autoclose.rb +73 -0
  19. data/lib/rio/context/copying.rb +2 -2
  20. data/lib/rio/context/cxx.rb +2 -2
  21. data/lib/rio/context/dir.rb +2 -2
  22. data/lib/rio/context/gzip.rb +2 -2
  23. data/lib/rio/context/methods.rb +6 -34
  24. data/lib/rio/context/skip.rb +2 -2
  25. data/lib/rio/context/stream.rb +2 -2
  26. data/lib/rio/context.rb +17 -2
  27. data/lib/rio/cp.rb +35 -9
  28. data/lib/rio/def.rb +54 -0
  29. data/lib/rio/dir.rb +19 -20
  30. data/lib/rio/doc/HOWTO.rb +23 -7
  31. data/lib/rio/doc/INTRO.rb +57 -23
  32. data/lib/rio/doc/MISC.rb +2 -2
  33. data/lib/rio/doc/OPTIONAL.rb +134 -0
  34. data/lib/rio/doc/SYNOPSIS.rb +11 -4
  35. data/lib/rio/doc.rb +2 -2
  36. data/lib/rio/entrysel.rb +25 -6
  37. data/lib/rio/exception/copy.rb +2 -2
  38. data/lib/rio/exception/notsupported.rb +47 -0
  39. data/lib/rio/exception/open.rb +2 -2
  40. data/lib/rio/exception/state.rb +2 -2
  41. data/lib/rio/exception.rb +2 -2
  42. data/lib/rio/ext/csv.rb +56 -11
  43. data/lib/rio/ext/yaml.rb +2 -2
  44. data/lib/rio/ext/zipfile.rb +91 -0
  45. data/lib/rio/ext.rb +38 -3
  46. data/lib/rio/factory.rb +17 -34
  47. data/lib/rio/file.rb +48 -8
  48. data/lib/rio/filter/closeoneof.rb +36 -16
  49. data/lib/rio/filter/gzip.rb +2 -2
  50. data/lib/rio/filter.rb +2 -2
  51. data/lib/rio/fs/base.rb +42 -0
  52. data/lib/rio/fs/impl.rb +123 -0
  53. data/lib/rio/fs/native.rb +76 -0
  54. data/lib/rio/{record.rb → fs/stream.rb} +21 -18
  55. data/lib/rio/fs/url.rb +64 -0
  56. data/lib/rio/ftp/{ioh.rb → conncache.rb} +38 -39
  57. data/lib/rio/ftp/dir.rb +95 -0
  58. data/lib/rio/ftp/fs.rb +173 -0
  59. data/lib/rio/ftp/ftpfile.rb +20 -0
  60. data/lib/rio/grande.rb +2 -2
  61. data/lib/rio/handle.rb +2 -2
  62. data/lib/rio/if/basic.rb +2 -2
  63. data/lib/rio/if/csv.rb +2 -2
  64. data/lib/rio/if/dir.rb +2 -2
  65. data/lib/rio/if/file.rb +26 -2
  66. data/lib/rio/if/fileordir.rb +44 -49
  67. data/lib/rio/if/grande.rb +32 -10
  68. data/lib/rio/if/grande_entry.rb +12 -2
  69. data/lib/rio/if/grande_stream.rb +17 -28
  70. data/lib/rio/if/internal.rb +2 -2
  71. data/lib/rio/if/path.rb +7 -6
  72. data/lib/rio/if/stream.rb +85 -29
  73. data/lib/rio/if/string.rb +2 -2
  74. data/lib/rio/if/temp.rb +2 -2
  75. data/lib/rio/if/test.rb +37 -4
  76. data/lib/rio/if/yaml.rb +2 -2
  77. data/lib/rio/if.rb +2 -2
  78. data/lib/rio/impl/path.rb +2 -2
  79. data/lib/rio/ioh.rb +17 -6
  80. data/lib/rio/iomode.rb +4 -3
  81. data/lib/rio/ios/fail.rb +107 -0
  82. data/lib/rio/ios/generic.rb +120 -0
  83. data/lib/rio/ios/mode.rb +61 -0
  84. data/lib/rio/ios/null.rb +120 -0
  85. data/lib/rio/iowrap.rb +129 -0
  86. data/lib/rio/kernel.rb +12 -3
  87. data/lib/rio/local.rb +2 -2
  88. data/lib/rio/match.rb +3 -3
  89. data/lib/rio/matchrecord.rb +2 -2
  90. data/lib/rio/no_warn.rb +50 -0
  91. data/lib/rio/{arrayio.rb → nullio.rb} +47 -86
  92. data/lib/rio/open3.rb +2 -2
  93. data/lib/rio/ops/construct.rb +20 -13
  94. data/lib/rio/ops/create.rb +10 -19
  95. data/lib/rio/ops/dir.rb +60 -54
  96. data/lib/rio/ops/either.rb +11 -9
  97. data/lib/rio/ops/file.rb +28 -24
  98. data/lib/rio/ops/path.rb +45 -43
  99. data/lib/rio/ops/stream/input.rb +12 -8
  100. data/lib/rio/ops/stream/output.rb +2 -2
  101. data/lib/rio/ops/stream/read.rb +35 -32
  102. data/lib/rio/ops/stream/write.rb +5 -5
  103. data/lib/rio/ops/stream.rb +7 -3
  104. data/lib/rio/ops/symlink.rb +12 -10
  105. data/lib/rio/path/reset.rb +5 -5
  106. data/lib/rio/path.rb +32 -24
  107. data/lib/rio/piper/cp.rb +2 -2
  108. data/lib/rio/piper.rb +2 -2
  109. data/lib/rio/prompt.rb +2 -2
  110. data/lib/rio/rectype.rb +9 -7
  111. data/lib/rio/rl/base.rb +5 -4
  112. data/lib/rio/rl/builder.rb +17 -5
  113. data/lib/rio/rl/ioi.rb +14 -4
  114. data/lib/rio/rl/path.rb +23 -15
  115. data/lib/rio/rl/pathmethods.rb +12 -2
  116. data/lib/rio/rl/uri.rb +13 -6
  117. data/lib/rio/scheme/aryio.rb +3 -3
  118. data/lib/rio/scheme/cmdio.rb +4 -3
  119. data/lib/rio/scheme/cmdpipe.rb +3 -35
  120. data/lib/rio/scheme/fd.rb +4 -3
  121. data/lib/rio/scheme/ftp.rb +36 -7
  122. data/lib/rio/scheme/http.rb +2 -2
  123. data/lib/rio/{context/closeoneof.rb → scheme/null.rb} +17 -11
  124. data/lib/rio/scheme/path.rb +28 -30
  125. data/lib/rio/scheme/stderr.rb +4 -4
  126. data/lib/rio/scheme/stdio.rb +6 -5
  127. data/lib/rio/scheme/strio.rb +10 -20
  128. data/lib/rio/scheme/sysio.rb +5 -2
  129. data/lib/rio/scheme/tcp.rb +4 -3
  130. data/lib/rio/scheme/temp.rb +14 -1
  131. data/lib/rio/state/error.rb +2 -2
  132. data/lib/rio/state.rb +80 -34
  133. data/lib/rio/stream/base.rb +7 -2
  134. data/lib/rio/stream/duplex.rb +13 -10
  135. data/lib/rio/stream/open.rb +74 -79
  136. data/lib/rio/stream.rb +15 -23
  137. data/lib/rio/symantics.rb +2 -2
  138. data/lib/rio/tempdir.rb +132 -132
  139. data/lib/rio/to_rio/all.rb +40 -0
  140. data/lib/rio/to_rio/array.rb +40 -0
  141. data/lib/rio/to_rio/io.rb +41 -0
  142. data/lib/rio/to_rio/object.rb +43 -0
  143. data/lib/rio/to_rio/string.rb +41 -0
  144. data/lib/rio/to_rio.rb +13 -2
  145. data/lib/rio/uri/file.rb +2 -2
  146. data/lib/rio/util.rb +2 -2
  147. data/lib/rio/version.rb +3 -3
  148. data/lib/rio.rb +16 -25
  149. data/test/bin/count_lines.rb +11 -0
  150. data/test/bin/find_lines.rb +13 -0
  151. data/test/bin/list_dir.rb +14 -0
  152. data/test/ftp/all.rb +9 -0
  153. data/test/ftp/anon_misc.rb +112 -0
  154. data/test/ftp/anon_read.rb +105 -0
  155. data/test/ftp/anon_special.rb +68 -0
  156. data/test/ftp/anon_write.rb +63 -0
  157. data/test/ftp/ftp2ftp.rb +51 -0
  158. data/test/ftp/initftpfiles.rb +14 -0
  159. data/test/ftp/testdef.rb +51 -0
  160. data/test/gem_runtests.rb +15 -15
  161. data/test/runalltests.rb +15 -0
  162. data/test/runftptests.rb +14 -0
  163. data/test/{1.rb → runhttptests.rb} +14 -14
  164. data/test/runtests.rb +14 -14
  165. data/test/tc/all.rb +36 -21
  166. data/test/tc/cmdpipe.rb +18 -15
  167. data/test/tc/copy-from-http.rb +89 -0
  168. data/test/tc/copy-from.rb +1 -52
  169. data/test/tc/copy.rb +19 -17
  170. data/test/tc/csv2.rb +6 -3
  171. data/test/tc/empty.rb +47 -0
  172. data/test/tc/emptyriodir.rb +129 -0
  173. data/test/tc/entsel.rb +110 -0
  174. data/test/tc/files_select.rb +92 -0
  175. data/test/tc/get.rb +7 -6
  176. data/test/tc/getrec.rb +2 -5
  177. data/test/tc/gzip.rb +82 -0
  178. data/test/tc/io_each_byte.rb +60 -0
  179. data/test/tc/io_read.rb +80 -0
  180. data/test/tc/iometh.rb +149 -0
  181. data/test/tc/likeio.rb +112 -0
  182. data/test/tc/methods.rb +10 -9
  183. data/test/tc/misc.rb +1 -37
  184. data/test/tc/null.rb +45 -0
  185. data/test/tc/pid.rb +31 -0
  186. data/test/tc/piper.rb +34 -37
  187. data/test/tc/programs_util.rb +24 -0
  188. data/test/tc/readline.rb +30 -0
  189. data/test/tc/rename.rb +12 -0
  190. data/test/tc/tempfile.rb +14 -0
  191. data/test/tc/testcase.rb +6 -0
  192. data/test/tc/tonl.rb +37 -0
  193. metadata +181 -144
  194. data/ex/colx.rb +0 -8
  195. data/ex/findinruby +0 -16
  196. data/ex/findruby +0 -15
  197. data/ex/passwd_report.rb +0 -8
  198. data/ex/prompt.rb +0 -25
  199. data/ex/rgb.txt.gz +0 -0
  200. data/ex/riocat +0 -35
  201. data/ex/riogunzip +0 -31
  202. data/ex/riogzip +0 -24
  203. data/ex/rioprompt.rb +0 -6
  204. data/ex/targz2zip +0 -17
  205. data/ex/tolf +0 -11
  206. data/lib/rio/ftp/conn.rb +0 -167
  207. data/lib/rio/ftp.rb +0 -275
  208. data/test/once.rb +0 -7
@@ -0,0 +1,123 @@
1
+ #--
2
+ # ===============================================================================
3
+ # Copyright (c) 2005, 2006 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. Then point your browser at the 'doc/rdoc' directory.
27
+ #
28
+ # Suggested Reading
29
+ # * RIO::Doc::SYNOPSIS
30
+ # * RIO::Doc::INTRO
31
+ # * RIO::Doc::HOWTO
32
+ # * RIO::Rio
33
+ #
34
+ # <b>Rio is pre-alpha software.
35
+ # The documented interface and behavior is subject to change without notice.</b>
36
+
37
+ module RIO
38
+ module FS #:nodoc: all
39
+ module Str
40
+ def fnmatch?(s,globstr,*flags) @file.fnmatch?(globstr,s,*flags) end
41
+ def extname(s,*args) @file.extname(s,*args) end
42
+
43
+ def basename(s,*args) @file.basename(s,*args) end
44
+ def dirname(s,*args) @file.dirname(s,*args) end
45
+ def join(s,*args) @file.join(s,*args) end
46
+ def cleanpath(s,*args) @path.new(s).cleanpath(*args) end
47
+ end
48
+ module File
49
+ def expand_path(s,*args) @file.expand_path(s,*args) end
50
+
51
+
52
+ def ftype(s,*args) @file.ftype(s,*args) end
53
+ def symlink(s,d) @file.symlink(s.to_s,d.to_s) end
54
+
55
+ def stat(s,*args) @file.stat(s,*args) end
56
+
57
+ def atime(s,*args) @file.atime(s,*args) end
58
+ def ctime(s,*args) @file.ctime(s,*args) end
59
+ def mtime(s,*args) @file.mtime(s,*args) end
60
+
61
+ def chmod(mod,s) @file.chmod(mod,s.to_s) end
62
+ def chown(owner_int,group_int,s) @file.chown(owner_int,group_int,s.to_s) end
63
+
64
+ def readlink(s,*args) @file.readlink(s,*args) end
65
+ def lstat(s,*args) @file.lstat(s,*args) end
66
+
67
+ def truncate(s,integer) @file.truncate(s,integer) end
68
+
69
+ end
70
+ module Dir
71
+ def rmdir(s) @dir.rmdir(s.to_s) end
72
+ def mkdir(s,*args) @dir.mkdir(s.to_s,*args) end
73
+ def chdir(s,&block) @dir.chdir(s.to_s,&block) end
74
+ def foreach(s,&block) @dir.foreach(s.to_s,&block) end
75
+ def entries(s) @dir.entries(s.to_s) end
76
+ def glob(gstr,*args,&block) @dir.glob(gstr,*args,&block) end
77
+ def pwd() @dir.pwd end
78
+ def getwd() @dir.getwd end
79
+ end
80
+ module Test
81
+ def blockdev?(s,*args) @test.blockdev?(s,*args) end
82
+ def chardev?(s,*args) @test.chardev?(s,*args) end
83
+ def directory?(s,*args) @test.directory?(s,*args) end
84
+ def dir?(s,*args) @test.directory?(s,*args) end
85
+ def executable?(s,*args) @test.executable?(s,*args) end
86
+ def executable_real?(s,*args) @test.executable_real?(s,*args) end
87
+ def exist?(s,*args) @test.exist?(s,*args) end
88
+ def file?(s,*args) @test.file?(s,*args) end
89
+ def grpowned?(s,*args) @test.grpowned?(s,*args) end
90
+ def owned?(s,*args) @test.owned?(s,*args) end
91
+ def pipe?(s,*args) @test.pipe?(s,*args) end
92
+ def readable?(s,*args) @test.readable?(s,*args) end
93
+ def readable_real?(s,*args) @test.readable_real?(s,*args) end
94
+ def setgid?(s,*args) @test.setgid?(s,*args) end
95
+ def setuid?(s,*args) @test.setuid?(s,*args) end
96
+ def size(s,*args) @test.size(s,*args) end
97
+ def size?(s,*args) @test.size?(s,*args) end
98
+ def socket?(s,*args) @test.socket?(s,*args) end
99
+ def sticky?(s,*args) @test.sticky?(s,*args) end
100
+ def symlink?(s,*args) @test.symlink?(s,*args) end
101
+ def writable?(s,*args) @test.writable?(s,*args) end
102
+ def writable_real?(s,*args) @test.writable_real?(s,*args) end
103
+ def zero?(s,*args) @test.zero?(s,*args) end
104
+ end
105
+ module Path
106
+ require 'pathname'
107
+ def root?(s) @path.new(s).root? end
108
+ def mountpoint?(s) @path.new(s).mountpoint? end
109
+ def realpath(s) @path.new(s).realpath end
110
+ end
111
+ module Util
112
+ # Directory stuff
113
+ def cp_r(s,d) @util.cp_r(s.to_s,d.to_s) end
114
+ def rmtree(s) @util.rmtree(s.to_s) end
115
+ def mkpath(s) @util.mkpath(s.to_s) end
116
+ def rm(s) @util.rm(s.to_s) end
117
+ def touch(s) @util.touch(s.to_s) end
118
+
119
+ # file or dir
120
+ def mv(s,d) @util.mv(s.to_s,d.to_s) end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,76 @@
1
+ #--
2
+ # ===============================================================================
3
+ # Copyright (c) 2005, 2006 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. Then point your browser at the 'doc/rdoc' directory.
27
+ #
28
+ # Suggested Reading
29
+ # * RIO::Doc::SYNOPSIS
30
+ # * RIO::Doc::INTRO
31
+ # * RIO::Doc::HOWTO
32
+ # * RIO::Rio
33
+ #
34
+ # <b>Rio is pre-alpha software.
35
+ # The documented interface and behavior is subject to change without notice.</b>
36
+
37
+ require 'rio/fs/impl'
38
+ require 'rio/fs/base'
39
+
40
+ module RIO
41
+ module FS
42
+ class Native < Base
43
+ require 'singleton'
44
+ include Singleton
45
+ attr_reader :file,:dir
46
+ def initialize(*args)
47
+ @file = ::File
48
+ @test = ::FileTest
49
+ @dir = ::Dir
50
+ require 'pathname'
51
+ @path = ::Pathname
52
+ require 'fileutils'
53
+ @util = ::FileUtils
54
+ end
55
+
56
+ def self.create(*args)
57
+ instance(*args)
58
+ end
59
+ def root()
60
+ require 'rio/local'
61
+ ::RIO::Local::ROOT_DIR
62
+ end
63
+ def cwd()
64
+ self.getwd()
65
+ end
66
+
67
+ include Str
68
+ include File
69
+ include Dir
70
+ include Path
71
+ include Test
72
+ include Util
73
+
74
+ end
75
+ end
76
+ end
@@ -1,6 +1,6 @@
1
1
  #--
2
2
  # ===============================================================================
3
- # Copyright (c) 2005, Christopher Kleckner
3
+ # Copyright (c) 2005, 2006 Christopher Kleckner
4
4
  # All rights reserved
5
5
  #
6
6
  # This file is part of the Rio library for ruby.
@@ -22,7 +22,7 @@
22
22
  #++
23
23
  #
24
24
  # To create the documentation for Rio run the command
25
- # rake rdoc
25
+ # ruby build_doc.rb
26
26
  # from the distribution directory. Then point your browser at the 'doc/rdoc' directory.
27
27
  #
28
28
  # Suggested Reading
@@ -34,26 +34,29 @@
34
34
  # <b>Rio is pre-alpha software.
35
35
  # The documented interface and behavior is subject to change without notice.</b>
36
36
 
37
+ require 'rio/fs/impl'
38
+ require 'rio/fs/base'
37
39
 
38
- # T-Mobile HotSpot 1.877.822.SPOT
39
40
  module RIO
40
- module Record #:nodoc: all
41
- class Base < ::String
42
- attr_accessor :recno
43
- def initialize(recno,*args)
44
- @recno = recno
45
- super(*args)
41
+ module FS
42
+ class Stream < Base
43
+ require 'singleton'
44
+ include Singleton
45
+ attr_reader :file,:dir
46
+ def initialize(*args)
47
+ @file = nil
48
+ @test = nil
49
+ @dir = nil
50
+ @path = nil
51
+ @util = nil
46
52
  end
47
- def =~(obj)
48
- case obj
49
- when ::Integer then @recno == obj
50
- when ::Range then obj.include?(@recno)
51
- else super
52
- end
53
+
54
+ def self.create(*args)
55
+ instance(*args)
53
56
  end
54
- def to_s() self end
55
- def to_rec(mode=nil) to_s end
56
- def to_row() to_s end
57
+ def symlink?(s) false end
58
+ def directory?(s) false end
59
+
57
60
  end
58
61
  end
59
62
  end
data/lib/rio/fs/url.rb ADDED
@@ -0,0 +1,64 @@
1
+ #--
2
+ # ===============================================================================
3
+ # Copyright (c) 2005, 2006 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. Then point your browser at the 'doc/rdoc' directory.
27
+ #
28
+ # Suggested Reading
29
+ # * RIO::Doc::SYNOPSIS
30
+ # * RIO::Doc::INTRO
31
+ # * RIO::Doc::HOWTO
32
+ # * RIO::Rio
33
+ #
34
+ # <b>Rio is pre-alpha software.
35
+ # The documented interface and behavior is subject to change without notice.</b>
36
+
37
+ require 'rio/fs/impl'
38
+ require 'rio/fs/base'
39
+
40
+ module RIO
41
+ module FS
42
+ class URL < Base
43
+ require 'singleton'
44
+ include Singleton
45
+ attr_reader :file,:dir
46
+ def initialize(*args)
47
+ @file = ::File
48
+ @test = nil
49
+ @dir = nil
50
+ @path = nil
51
+ @util = nil
52
+ end
53
+
54
+ def self.create(*args)
55
+ instance(*args)
56
+ end
57
+ include Str
58
+ include File
59
+ def symlink?(s) false end
60
+ def directory?(s) false end
61
+
62
+ end
63
+ end
64
+ end
@@ -1,6 +1,6 @@
1
1
  #--
2
2
  # ===============================================================================
3
- # Copyright (c) 2005, Christopher Kleckner
3
+ # Copyright (c) 2005, 2006 Christopher Kleckner
4
4
  # All rights reserved
5
5
  #
6
6
  # This file is part of the Rio library for ruby.
@@ -22,7 +22,7 @@
22
22
  #++
23
23
  #
24
24
  # To create the documentation for Rio run the command
25
- # rake rdoc
25
+ # ruby build_doc.rb
26
26
  # from the distribution directory. Then point your browser at the 'doc/rdoc' directory.
27
27
  #
28
28
  # Suggested Reading
@@ -36,53 +36,52 @@
36
36
 
37
37
 
38
38
  require 'net/ftp'
39
- require 'rio/ioh'
39
+ require 'uri'
40
+ require 'singleton'
41
+
40
42
  module RIO
41
43
  module FTP
42
- class IOH < RIO::IOH::Base
43
- def each(&block)
44
- names.each do |s|
45
- yield s
46
- end
47
- self
48
- end
49
- def close()
50
- @ios.close unless closed?
51
- @ios = nil
52
- end
53
- def closed?() @ios.nil? end
54
- def chdir(dir,&block)
55
- if block_given?
56
- wd = @ios.pwd
57
- @ios.chdir(dir) unless dir == wd
58
- rtn = yield self
59
- @ios.chdir(wd) unless dir == wd
60
- return rtn
44
+ class Connection
45
+ attr_reader :uri,:netftp,:remote_root
46
+ def initialize(uri)
47
+ @uri = uri.clone
48
+ @netftp = ::Net::FTP.new()
49
+ @netftp.connect(@uri.host,@uri.port)
50
+ if @uri.user
51
+ @netftp.login(@uri.user,@uri.password)
61
52
  else
62
- @ios.chdir(dir)
53
+ @netftp.login
63
54
  end
64
- self
55
+ @remote_root = @netftp.pwd
65
56
  end
66
- def list()
67
- @ios.list
57
+ def method_missing(sym,*args,&block)
58
+ @netftp.__send__(sym,*args,&block)
68
59
  end
69
- def nlst()
70
- @ios.nlst
60
+ end
61
+ class ConnCache
62
+ include Singleton
63
+ def initialize()
64
+ @conns = {}
65
+ @count = {}
66
+ end
67
+ def urikey(uri)
68
+ key_uri = uri.clone
69
+ key_uri.path = ''
70
+ key_uri.to_s
71
71
  end
72
- def names()
73
- begin
74
- @ios.nlst
75
- rescue ::Net::FTPTempError
76
- []
72
+ def connect(uri)
73
+ key = urikey(uri)
74
+ unless @conns.has_key?(key)
75
+ @conns[key] = Connection.new(uri)
76
+ @count[key] = 0
77
77
  end
78
+ @count[key] += 1
79
+ @conns[key]
78
80
  end
79
- extend Forwardable
80
- def_instance_delegators(:handle,:pwd,:mkdir,:rename,:put,:delete,:rmdir,:mdtm,:mtime,:root_dir)
81
-
82
- def callstr(func,*args)
83
- self.class.to_s+'['+self.to_s+']'+'.'+func.to_s+'('+args.join(',')+')'
81
+ def close(uri)
82
+ key = urikey(uri)
83
+ @count[key] -= 1
84
84
  end
85
-
86
85
  end
87
86
  end
88
87
  end
@@ -0,0 +1,95 @@
1
+ #--
2
+ # ===============================================================================
3
+ # Copyright (c) 2005, 2006 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. Then point your browser at the 'doc/rdoc' directory.
27
+ #
28
+ # Suggested Reading
29
+ # * RIO::Doc::SYNOPSIS
30
+ # * RIO::Doc::INTRO
31
+ # * RIO::Doc::HOWTO
32
+ # * RIO::Rio
33
+ #
34
+ # <b>Rio is pre-alpha software.
35
+ # The documented interface and behavior is subject to change without notice.</b>
36
+
37
+ require 'net/ftp'
38
+ require 'uri'
39
+ require 'rio/fs/native'
40
+ require 'rio/ftp/conncache'
41
+
42
+ module RIO
43
+ module FTP
44
+ module Dir
45
+ class Stream
46
+ attr_reader :uri,:netftp,:remote_root
47
+ def initialize(uri)
48
+ @uri = uri.clone
49
+ @conn = ConnCache.instance.connect(uri)
50
+ @remote_root = @conn.remote_root
51
+ @remote_root = '' if @remote_root == '/'
52
+ @names = nil
53
+ @entidx = 0
54
+ end
55
+ def url_root()
56
+ root_uri = @uri.clone
57
+ root_uri.path = ''
58
+ root_uri.to_s
59
+ end
60
+ def close()
61
+ ConnCache.instance.close(uri)
62
+ end
63
+ def remote_path()
64
+ self.remote_root+@uri.path
65
+ end
66
+ def names()
67
+ @names ||= begin
68
+ @conn.nlst(remote_path())
69
+ rescue ::Net::FTPPermError
70
+ []
71
+ end
72
+ end
73
+ def entpath(ent)
74
+ ent.sub(/^#{remote_path}/,'')
75
+ end
76
+ def read()
77
+ name = names[@entidx]
78
+ if name
79
+ rtn = entpath(name)
80
+ @entidx +=1
81
+ rtn
82
+ end
83
+ end
84
+ def each(&block)
85
+ p "Hello Mr. Phelps"
86
+ names.each { |ent|
87
+ @entidx += 1
88
+ yield entpath(ent)
89
+ }
90
+ self
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
data/lib/rio/ftp/fs.rb ADDED
@@ -0,0 +1,173 @@
1
+ #--
2
+ # ===============================================================================
3
+ # Copyright (c) 2005, 2006 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. Then point your browser at the 'doc/rdoc' directory.
27
+ #
28
+ # Suggested Reading
29
+ # * RIO::Doc::SYNOPSIS
30
+ # * RIO::Doc::INTRO
31
+ # * RIO::Doc::HOWTO
32
+ # * RIO::Rio
33
+ #
34
+ # <b>Rio is pre-alpha software.
35
+ # The documented interface and behavior is subject to change without notice.</b>
36
+
37
+ require 'net/ftp'
38
+ require 'uri'
39
+ require 'rio/fs/native'
40
+ require 'rio/ftp/conncache'
41
+
42
+ module RIO
43
+ module FTP
44
+ class FS
45
+ attr_reader :uri,:conn,:remote_root
46
+ def initialize(uri)
47
+ @uri = uri.clone
48
+ @conn = ConnCache.instance.connect(@uri)
49
+ @remote_root = @conn.remote_root
50
+ @remote_root = '' if @remote_root == '/'
51
+ @file = ::File
52
+ end
53
+ def self.create(*args)
54
+ new(*args)
55
+ end
56
+ def root()
57
+ uri = @uri.clone
58
+ uri.path = '/'
59
+ uri.to_s
60
+ end
61
+ include RIO::FS::Str
62
+
63
+
64
+ def pwd() @conn.pwd end
65
+ def getwd()
66
+ self.pwd
67
+ end
68
+ def cwd()
69
+ remote_wd = self.pwd
70
+ remote_rel = remote_wd.sub(/^#{@remote_root}/,'')
71
+ wduri = uri.clone
72
+ wduri.path = remote_rel
73
+ wduri.to_s
74
+ end
75
+ def remote_path(url)
76
+ self.remote_root+URI(url).path
77
+ end
78
+ def chdir(url,&block)
79
+ if block_given?
80
+ wd = @conn.pwd
81
+ @conn.chdir(remote_path(url))
82
+ begin
83
+ rtn = yield remote_path(url)
84
+ ensure
85
+ @conn.chdir(wd)
86
+ end
87
+ return rtn
88
+ else
89
+ @conn.chdir(remote_path(url))
90
+ end
91
+ end
92
+ def mkdir(url)
93
+ @conn.mkdir(remote_path(url))
94
+ end
95
+ def mv(src_url,dst_url)
96
+ @conn.rename(remote_path(src_url),remote_path(dst_url))
97
+ end
98
+ def size(url)
99
+ @conn.size(remote_path(url))
100
+ end
101
+ def zero?(url)
102
+ size(url) == 0
103
+ end
104
+ def mtime(url)
105
+ @conn.mtime(remote_path(url))
106
+ end
107
+ def rmdir(url)
108
+ @conn.rmdir(remote_path(url))
109
+ end
110
+ def rm(url)
111
+ @conn.delete(remote_path(url))
112
+ end
113
+
114
+ def get_ftype(url)
115
+ pth = remote_path(url)
116
+ ftype = nil
117
+ begin
118
+ @conn.mdtm(pth)
119
+ ftype = 'file'
120
+ rescue Net::FTPPermError
121
+ wd = @conn.pwd
122
+ begin
123
+ @conn.chdir(pth)
124
+ ftype = 'dir'
125
+ rescue Net::FTPPermError
126
+ ftype = 'nada'
127
+ ensure
128
+ @conn.chdir(wd)
129
+ end
130
+ end
131
+ ftype
132
+ end
133
+ def file?(url)
134
+ get_ftype(url) == 'file'
135
+ end
136
+ def directory?(url)
137
+ get_ftype(url) == 'dir'
138
+ end
139
+ def exist?(url)
140
+ get_ftype(url) != 'nada'
141
+ end
142
+ def symlink?(url)
143
+ false
144
+ end
145
+ def mkpath(url)
146
+ tpath = rio(url)
147
+ tmprio = tpath.root
148
+ pathparts = tpath.path.split('/')[1..-1]
149
+ pathparts.each do |part|
150
+ tmprio.join!(part)
151
+ tmprio.mkdir
152
+ end
153
+ end
154
+ def rmtree(url)
155
+ ario = rio(url)
156
+ _rment(ario)
157
+ end
158
+
159
+ private
160
+
161
+ def _rment(ario)
162
+ if ario.file?
163
+ ario.rm
164
+ else
165
+ ario.each do |ent|
166
+ _rment(ent)
167
+ end
168
+ ario.rmdir
169
+ end
170
+ end
171
+ end
172
+ end
173
+ end