net-ftp-list 0.5 → 0.7
Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile
CHANGED
data/lib/net/ftp/list.rb
CHANGED
@@ -4,6 +4,7 @@ require 'net/ftp/list/parser'
|
|
4
4
|
# The order here is important for the time being. Corse grained parsers should appear before specializations because
|
5
5
|
# the whole thing is searched in reverse order.
|
6
6
|
require 'net/ftp/list/unix'
|
7
|
+
require 'net/ftp/list/microsoft'
|
7
8
|
|
8
9
|
module Net #:nodoc:
|
9
10
|
class FTP #:nodoc:
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'net/ftp/list/parser'
|
2
|
+
|
3
|
+
module Net
|
4
|
+
class FTP
|
5
|
+
module List
|
6
|
+
|
7
|
+
# Parse M$ like FTP LIST entries.
|
8
|
+
#
|
9
|
+
# == MATCHES
|
10
|
+
#
|
11
|
+
# 06-25-07 01:08PM <DIR> etc
|
12
|
+
# 11-27-07 08:45PM 23437 README.TXT
|
13
|
+
#
|
14
|
+
# == SYNOPSIS
|
15
|
+
#
|
16
|
+
# entry = Net::FTP::List::Microsoft.new('06-25-07 01:08PM <DIR> etc')
|
17
|
+
# entry.dir? # => true
|
18
|
+
# entry.basename # => 'etc'
|
19
|
+
class Microsoft < Parser
|
20
|
+
|
21
|
+
# Stolen straight from the ASF's commons Java FTP LIST parser library.
|
22
|
+
# http://svn.apache.org/repos/asf/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/
|
23
|
+
REGEXP = %r{
|
24
|
+
^\s*
|
25
|
+
(\S+)\s+(\S+)\s+
|
26
|
+
(?:(<DIR>)|([0-9]+))\s+
|
27
|
+
(\S.*)
|
28
|
+
\s*$
|
29
|
+
}x
|
30
|
+
|
31
|
+
# Parse a M$ like FTP LIST entries.
|
32
|
+
def initialize(raw)
|
33
|
+
super(raw)
|
34
|
+
match = REGEXP.match(raw.strip) or raise ParserError
|
35
|
+
|
36
|
+
if match[3] == '<DIR>'
|
37
|
+
@dir = true
|
38
|
+
else
|
39
|
+
@file = true
|
40
|
+
end
|
41
|
+
|
42
|
+
# TODO: Permissions, users, groups, date/time.
|
43
|
+
|
44
|
+
@basename = match[5]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/net/ftp/list/unix.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'net/ftp/list'
|
3
|
+
|
4
|
+
class TestNetFTPListMicrosoft < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
# DATE TIME DIR SIZE NAME
|
8
|
+
@dir = Net::FTP::List.parse('06-25-07 01:08PM <DIR> etc')
|
9
|
+
@file = Net::FTP::List.parse('11-27-07 08:45PM 23437 README.TXT')
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_parse_new
|
13
|
+
assert_instance_of Net::FTP::List::Microsoft, @dir, 'LIST M$ directory'
|
14
|
+
assert_instance_of Net::FTP::List::Microsoft, @file, 'LIST M$ file'
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_rubbish_lines
|
18
|
+
assert_instance_of Net::FTP::List::Unknown, Net::FTP::List.parse("++ bah! ++")
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_ruby_microsoft_like_dir
|
22
|
+
assert_equal 'etc', @dir.basename
|
23
|
+
assert @dir.dir?
|
24
|
+
assert !@dir.file?
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_ruby_microsoft_like_file
|
28
|
+
assert_equal 'README.TXT', @file.basename
|
29
|
+
assert @file.file?
|
30
|
+
assert !@file.dir?
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: net-ftp-list
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: "0.
|
7
|
-
date: 2008-
|
6
|
+
version: "0.7"
|
7
|
+
date: 2008-04-15 00:00:00 +10:00
|
8
8
|
summary: Parse FTP LIST command output.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -30,10 +30,12 @@ authors:
|
|
30
30
|
- Shane Hanna
|
31
31
|
files:
|
32
32
|
- Rakefile
|
33
|
+
- lib/net/ftp/list/microsoft.rb
|
33
34
|
- lib/net/ftp/list/parser.rb
|
34
35
|
- lib/net/ftp/list/unix.rb
|
35
36
|
- lib/net/ftp/list.rb
|
36
|
-
- test/
|
37
|
+
- test/test_net_ftp_list_microsoft.rb
|
38
|
+
- test/test_net_ftp_list_unix.rb
|
37
39
|
- README.txt
|
38
40
|
test_files: []
|
39
41
|
|