net-ftp-list 2.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
6
+ .idea/*
7
+ .idea/**/*
data/README.txt CHANGED
@@ -30,13 +30,15 @@ See the RFC for more guff on LIST and NLST: http://www.ietf.org/rfc/rfc0959.txt
30
30
  ftp = Net::FTP.open('somehost.com', 'user', 'pass')
31
31
  ftp.list('/some/path') do |e|
32
32
  entry = Net::FTP::List.parse(e)
33
-
33
+
34
34
  # Ignore everything that's not a file (so symlinks, directories and devices etc.)
35
35
  next unless entry.file?
36
36
 
37
37
  # If entry isn't a kind_of Net::FTP::List::Unknown then there is a bug in Net::FTP::List if this isn't the
38
38
  # same name as ftp.nlist('/some/path') would have returned.
39
- puts entry.basename
39
+ # Format the entry showing its file size and modification time
40
+ puts "#{entry.basename}, #{entry.filesize}, #{entry.mtime}"
41
+
40
42
  end
41
43
 
42
44
  == CREDITS
data/Rakefile CHANGED
@@ -1,51 +1,52 @@
1
- # -*- ruby -*-
1
+ require 'rubygems'
2
2
  require 'rake'
3
- require 'rake/clean'
4
- require 'rake/gempackagetask'
5
- require 'rake/testtask'
6
-
7
- NAME = 'net-ftp-list'
8
- VERS = '2.0'
9
-
10
- CLEAN.include ['**/*.log', '*.gem']
11
- CLOBBER.include ['**/*.log']
12
3
 
13
- spec = Gem::Specification.new do |s|
14
- s.name = NAME
15
- s.version = VERS
16
- s.platform = Gem::Platform::RUBY
17
- s.has_rdoc = true
18
- s.extra_rdoc_files = ["README.txt"]
19
- s.summary = 'Parse FTP LIST command output.'
20
- s.description = s.summary
21
- s.author = 'Shane Hanna'
22
- s.email = 'shane@statelesssystems.com'
23
- s.homepage = 'http://statelesssystems.com'
24
-
25
- s.files = FileList['Rakefile', '**/*.{rb,txt}'].to_a
26
- s.test_files = FileList['tests/*.rb'].to_a
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "net-ftp-list"
8
+ gem.summary = %Q{Parse FTP LIST command output.}
9
+ gem.email = "enquiries@statelesssystems.com"
10
+ gem.homepage = "http://github.com/stateless-systems/net-ftp-list"
11
+ gem.authors = ["Stateless Systems"]
12
+ end
13
+ rescue LoadError
14
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
27
15
  end
28
16
 
29
- desc 'Default: Run unit tests.'
30
- task :default => :test
31
-
32
- Rake::GemPackageTask.new(spec) do |p|
33
- p.need_tar = true
34
- p.gem_spec = spec
17
+ require 'rake/testtask'
18
+ Rake::TestTask.new(:test) do |test|
19
+ test.libs << 'lib' << 'test'
20
+ test.pattern = 'test/**/*_test.rb'
21
+ test.verbose = true
35
22
  end
36
23
 
37
- desc 'Run the unit tests.'
38
- Rake::TestTask.new do |t|
39
- t.verbose = true
24
+ begin
25
+ require 'rcov/rcovtask'
26
+ Rcov::RcovTask.new do |test|
27
+ test.libs << 'test'
28
+ test.pattern = 'test/**/*_test.rb'
29
+ test.verbose = true
30
+ end
31
+ rescue LoadError
32
+ task :rcov do
33
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
34
+ end
40
35
  end
41
36
 
42
- desc 'Package and install as gem.'
43
- task :install do
44
- sh %{rake package}
45
- sh %{sudo gem install pkg/#{NAME}-#{VERS}}
46
- end
37
+ task :default => :test
47
38
 
48
- desc 'Uninstall the gem.'
49
- task :uninstall => [:clean] do
50
- sh %{sudo gem uninstall #{NAME}}
39
+ require 'rake/rdoctask'
40
+ Rake::RDocTask.new do |rdoc|
41
+ if File.exist?('VERSION.yml')
42
+ config = YAML.load(File.read('VERSION.yml'))
43
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
44
+ else
45
+ version = ""
46
+ end
47
+
48
+ rdoc.rdoc_dir = 'rdoc'
49
+ rdoc.title = "net-ftp-list #{version}"
50
+ rdoc.rdoc_files.include('README*')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
52
  end
data/VERSION.yml ADDED
@@ -0,0 +1,5 @@
1
+ ---
2
+ :major: 2
3
+ :minor: 1
4
+ :patch: 1
5
+ :build:
@@ -1,4 +1,5 @@
1
1
  require 'net/ftp/list/parser'
2
+ require 'date'
2
3
 
3
4
  module Net
4
5
  class FTP
@@ -33,9 +34,12 @@ module Net
33
34
  super(raw)
34
35
  match = REGEXP.match(raw.strip) or raise ParserError
35
36
 
37
+ @mtime = DateTime.strptime("#{match[1]} #{match[2]}", "%m-%d-%y %I:%M%p")
38
+
36
39
  if match[3] == '<DIR>'
37
40
  @dir = true
38
41
  else
42
+ @filesize = match[4].to_i
39
43
  @file = true
40
44
  end
41
45
 
@@ -1,4 +1,5 @@
1
1
  require 'net/ftp/list/parser'
2
+ require 'time'
2
3
 
3
4
  module Net
4
5
  class FTP
@@ -33,6 +34,9 @@ module Net
33
34
  super(raw)
34
35
  match = REGEXP.match(raw.strip) or raise ParserError
35
36
 
37
+ @mtime = Time.parse(match[5])
38
+ @filesize = match[4].to_i
39
+
36
40
  if match[1] == 'd'
37
41
  @dir = true
38
42
  else
@@ -43,17 +43,25 @@ module Net
43
43
 
44
44
  # Looks like a directory, try CWD.
45
45
  def dir?
46
- !!@dir ||= false
46
+ !!(@dir ||= false)
47
47
  end
48
48
 
49
49
  # Looks like a file, try RETR.
50
50
  def file?
51
- !!@file ||= false
51
+ !!(@file ||= false)
52
52
  end
53
53
 
54
54
  # Looks like a symbolic link.
55
55
  def symlink?
56
- !!@symlink ||= false
56
+ !!(@symlink ||= false)
57
+ end
58
+
59
+ def mtime
60
+ @mtime
61
+ end
62
+
63
+ def filesize
64
+ @filesize
57
65
  end
58
66
 
59
67
  class << self
@@ -1,3 +1,4 @@
1
+ require 'time'
1
2
  require 'net/ftp/list/parser'
2
3
 
3
4
  module Net
@@ -7,7 +8,7 @@ module Net
7
8
  # Parse Unix like FTP LIST entries.
8
9
  #
9
10
  # == MATCHES
10
- #
11
+ #
11
12
  # drwxr-xr-x 4 steve group 4096 Dec 10 20:23 etc
12
13
  # -rw-r--r-- 1 root other 531 Jan 29 03:26 README.txt
13
14
  #
@@ -46,6 +47,8 @@ module Net
46
47
  end
47
48
 
48
49
  # TODO: Permissions, users, groups, date/time.
50
+ @filesize = match[18].to_i
51
+ @mtime = Time.parse("#{match[19]} #{match[20]}")
49
52
 
50
53
  @basename = match[21].strip
51
54
 
@@ -0,0 +1,53 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{net-ftp-list}
8
+ s.version = "2.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Stateless Systems"]
12
+ s.date = %q{2010-07-30}
13
+ s.email = %q{enquiries@statelesssystems.com}
14
+ s.extra_rdoc_files = [
15
+ "README.txt"
16
+ ]
17
+ s.files = [
18
+ ".gitignore",
19
+ "README.txt",
20
+ "Rakefile",
21
+ "VERSION.yml",
22
+ "lib/net/ftp/list.rb",
23
+ "lib/net/ftp/list/microsoft.rb",
24
+ "lib/net/ftp/list/netware.rb",
25
+ "lib/net/ftp/list/parser.rb",
26
+ "lib/net/ftp/list/unix.rb",
27
+ "net-ftp-list.gemspec",
28
+ "test/test_net_ftp_list_microsoft.rb",
29
+ "test/test_net_ftp_list_netware.rb",
30
+ "test/test_net_ftp_list_unix.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/stateless-systems/net-ftp-list}
33
+ s.rdoc_options = ["--charset=UTF-8"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.5}
36
+ s.summary = %q{Parse FTP LIST command output.}
37
+ s.test_files = [
38
+ "test/test_net_ftp_list_microsoft.rb",
39
+ "test/test_net_ftp_list_unix.rb",
40
+ "test/test_net_ftp_list_netware.rb"
41
+ ]
42
+
43
+ if s.respond_to? :specification_version then
44
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
45
+ s.specification_version = 3
46
+
47
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
48
+ else
49
+ end
50
+ else
51
+ end
52
+ end
53
+
@@ -18,6 +18,11 @@ class TestNetFTPListMicrosoft < Test::Unit::TestCase
18
18
  assert_instance_of Net::FTP::List::Unknown, Net::FTP::List.parse("++ bah! ++")
19
19
  end
20
20
 
21
+ def test_ruby_microsoft_mtime
22
+ assert_equal DateTime.strptime('06-25-07 01:08PM', "%m-%d-%y %I:%M%p"), @dir.mtime
23
+ assert_equal DateTime.strptime('11-27-07 08:45PM', "%m-%d-%y %I:%M%p"), @file.mtime
24
+ end
25
+
21
26
  def test_ruby_microsoft_like_dir
22
27
  assert_equal 'etc', @dir.basename
23
28
  assert @dir.dir?
@@ -30,4 +35,8 @@ class TestNetFTPListMicrosoft < Test::Unit::TestCase
30
35
  assert !@file.dir?
31
36
  end
32
37
 
38
+ def test_filesize
39
+ assert @dir.filesize.nil?
40
+ assert_equal 23437, @file.filesize
41
+ end
33
42
  end
@@ -17,6 +17,11 @@ class TestNetFTPListNetware < Test::Unit::TestCase
17
17
  assert_instance_of Net::FTP::List::Unknown, Net::FTP::List.parse("++ bah! ++")
18
18
  end
19
19
 
20
+ def test_ruby_netware_mtime
21
+ assert_equal @dir.mtime, Time.parse('Jun 27 23:46')
22
+ assert_equal @file.mtime, Time.parse('Jun 22 06:22')
23
+ end
24
+
20
25
  def test_ruby_netware_like_dir
21
26
  assert_equal 'public.www', @dir.basename
22
27
  assert @dir.dir?
@@ -29,4 +34,9 @@ class TestNetFTPListNetware < Test::Unit::TestCase
29
34
  assert !@file.dir?
30
35
  end
31
36
 
37
+ def test_filesize
38
+ assert_equal 512, @dir.filesize
39
+ assert_equal 2767, @file.filesize
40
+ end
41
+
32
42
  end
@@ -4,11 +4,12 @@ require 'net/ftp/list'
4
4
  class TestNetFTPListUnix < Test::Unit::TestCase
5
5
 
6
6
  def setup
7
- @dir = Net::FTP::List.parse 'drwxr-xr-x 4 user group 4096 Dec 10 20:23 etc'
8
- @file = Net::FTP::List.parse '-rw-r--r-- 1 root other 531 Jan 29 03:26 README'
9
- @other_dir = Net::FTP::List.parse 'drwxr-xr-x 8 1791 600 4096 Mar 11 07:57 forums'
10
- @spaces = Net::FTP::List.parse 'drwxrwxr-x 2 danial danial 72 May 23 12:52 spaces suck'
11
- @symlink = Net::FTP::List.parse 'lrwxrwxrwx 1 danial danial 4 Apr 30 15:26 bar -> /etc'
7
+ @dir = Net::FTP::List.parse 'drwxr-xr-x 4 user group 4096 Dec 10 20:23 etc'
8
+ @file = Net::FTP::List.parse '-rw-r--r-- 1 root other 531 Jan 29 03:26 README'
9
+ @other_dir = Net::FTP::List.parse 'drwxr-xr-x 8 1791 600 4096 Mar 11 07:57 forums'
10
+ @spaces = Net::FTP::List.parse 'drwxrwxr-x 2 danial danial 72 May 23 12:52 spaces suck'
11
+ @symlink = Net::FTP::List.parse 'lrwxrwxrwx 1 danial danial 4 Apr 30 15:26 bar -> /etc'
12
+ @older_date = Net::FTP::List.parse '-rwxrwxrwx 1 owner group 154112 Feb 15 2008 participando.xls'
12
13
  end
13
14
 
14
15
  def test_parse_new
@@ -23,6 +24,12 @@ class TestNetFTPListUnix < Test::Unit::TestCase
23
24
  assert_instance_of Net::FTP::List::Unknown, Net::FTP::List.parse("++ bah! ++")
24
25
  end
25
26
 
27
+ def test_ruby_unix_like_date
28
+ assert_equal Time.parse("Mar 11 07:57"), @other_dir.mtime
29
+ assert_equal Time.parse("Apr 30 15:26"), @symlink.mtime
30
+ assert_equal Time.parse("Feb 15 2008"), @older_date.mtime
31
+ end
32
+
26
33
  def test_ruby_unix_like_dir
27
34
  assert_equal 'etc', @dir.basename
28
35
  assert @dir.dir?
@@ -52,4 +59,12 @@ class TestNetFTPListUnix < Test::Unit::TestCase
52
59
  assert !@file.dir?
53
60
  end
54
61
 
62
+ def test_filesize
63
+ assert_equal 4096, @dir.filesize
64
+ assert_equal 531, @file.filesize
65
+ assert_equal 4096, @other_dir.filesize
66
+ assert_equal 72, @spaces.filesize
67
+ assert_equal 4, @symlink.filesize
68
+ assert_equal 154112, @older_date.filesize
69
+ end
55
70
  end
metadata CHANGED
@@ -1,20 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-ftp-list
3
3
  version: !ruby/object:Gem::Version
4
- version: "2.0"
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
- - Shane Hanna
7
+ - Stateless Systems
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-07-04 00:00:00 +10:00
12
+ date: 2010-07-30 00:00:00 +10:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description: Parse FTP LIST command output.
17
- email: shane@statelesssystems.com
16
+ description:
17
+ email: enquiries@statelesssystems.com
18
18
  executables: []
19
19
 
20
20
  extensions: []
@@ -22,21 +22,26 @@ extensions: []
22
22
  extra_rdoc_files:
23
23
  - README.txt
24
24
  files:
25
+ - .gitignore
26
+ - README.txt
25
27
  - Rakefile
28
+ - VERSION.yml
29
+ - lib/net/ftp/list.rb
26
30
  - lib/net/ftp/list/microsoft.rb
27
31
  - lib/net/ftp/list/netware.rb
28
32
  - lib/net/ftp/list/parser.rb
29
33
  - lib/net/ftp/list/unix.rb
30
- - lib/net/ftp/list.rb
34
+ - net-ftp-list.gemspec
31
35
  - test/test_net_ftp_list_microsoft.rb
32
36
  - test/test_net_ftp_list_netware.rb
33
37
  - test/test_net_ftp_list_unix.rb
34
- - README.txt
35
38
  has_rdoc: true
36
- homepage: http://statelesssystems.com
37
- post_install_message:
38
- rdoc_options: []
39
+ homepage: http://github.com/stateless-systems/net-ftp-list
40
+ licenses: []
39
41
 
42
+ post_install_message:
43
+ rdoc_options:
44
+ - --charset=UTF-8
40
45
  require_paths:
41
46
  - lib
42
47
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -54,9 +59,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
59
  requirements: []
55
60
 
56
61
  rubyforge_project:
57
- rubygems_version: 1.1.1
62
+ rubygems_version: 1.3.5
58
63
  signing_key:
59
- specification_version: 2
64
+ specification_version: 3
60
65
  summary: Parse FTP LIST command output.
61
- test_files: []
62
-
66
+ test_files:
67
+ - test/test_net_ftp_list_microsoft.rb
68
+ - test/test_net_ftp_list_unix.rb
69
+ - test/test_net_ftp_list_netware.rb