ls_all 0.0.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/bin/ls_all ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
4
+
5
+ require 'rubygems'
6
+ require 'ls_all'
7
+
8
+ options = LsAll::LsAllOpts.parse(ARGV)
9
+ list = LsAll::LsAll.new( options.depth, options.count )
10
+
11
+ files = Dir.glob(options.path + '/*')
12
+ list.list_files( files )
data/lib/ls_all.rb ADDED
@@ -0,0 +1,10 @@
1
+ #ls_all.rb
2
+
3
+ module LsAll
4
+
5
+ VERSION = "0.0.1"
6
+
7
+ end
8
+
9
+ require 'ls_all/ls_all'
10
+ require 'ls_all/ls_all_opts'
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ module LsAll
4
+ class LsAll
5
+
6
+ def initialize( max_depth=0, count=false )
7
+ @max_depth = max_depth
8
+ @count = count
9
+ end
10
+
11
+ def list_files( files, spacer='', path='.', depth=1)
12
+ path = File.expand_path( path )
13
+
14
+ files.each do |f|
15
+ if File.directory?( f )
16
+
17
+ file_string= f + '/'
18
+ if (not @max_depth == 0) and (depth == @max_depth) and (@count == true)
19
+ puts spacer + file_string.ljust(20) + ' Count: ' + file_count( f )
20
+ else
21
+ puts spacer + file_string
22
+ end
23
+
24
+
25
+ recursive_path=File.expand_path( f )
26
+ Dir.chdir( recursive_path )
27
+ recursive_files = Dir.glob('*')
28
+ recursive_spacer = spacer + ' '
29
+
30
+ if (@max_depth == 0) or (depth < @max_depth)
31
+ rec_depth=depth+1
32
+ list_files(recursive_files, recursive_spacer, recursive_path, rec_depth)
33
+ else
34
+ #
35
+ end
36
+ else
37
+ puts spacer + f
38
+ end
39
+ Dir.chdir( path )
40
+ end
41
+
42
+ end
43
+
44
+ def file_count( path )
45
+ recursive_files = Dir.glob(path + '/*')
46
+ recursive_files.size.to_s
47
+ end
48
+ end
49
+ end
50
+
51
+ if $0 == __FILE__
52
+
53
+ require File.join(File.dirname(__FILE__), "ls_all_opts")
54
+
55
+ options = LsAll::LsAllOpts.parse(ARGV)
56
+ list = LsAll::LsAll.new( options.depth, options.count )
57
+
58
+ files = Dir.glob(options.path + '/*')
59
+ list.list_files( files )
60
+ end
61
+
62
+
@@ -0,0 +1,62 @@
1
+ require 'optparse'
2
+ require 'ostruct'
3
+
4
+ module LsAll
5
+ class LsAllOpts
6
+ #
7
+ # Return a structure describing the options.
8
+ #
9
+ def self.parse(args)
10
+ #VERSION is held in top level LSAll::VERSION
11
+ @VERSION = VERSION
12
+
13
+ # The options specified on the command line will be collected in *options*.
14
+ # We set default values here.
15
+ options = OpenStruct.new
16
+
17
+ options.sort = :normal
18
+ options.depth = 0
19
+ options.count = false
20
+ options.path = '.'
21
+
22
+ opts = OptionParser.new do |opts|
23
+ opts.banner = "Usage: #{__FILE__} [options]"
24
+ opts.separator ""
25
+ opts.separator "Common options:"
26
+
27
+ # No argument, shows at tail. This will print an options summary.
28
+ opts.on("-h", "--help", "Show this message") do
29
+ puts opts
30
+ exit
31
+ end
32
+
33
+ # Another typical switch to print the version.
34
+ opts.on("--version", "Show version") do
35
+ puts "Version #{@VERSION}"
36
+ exit
37
+ end
38
+ opts.separator ""
39
+ opts.separator "Specific options:"
40
+
41
+ opts.on("-d", "--max-depth N", Integer, "Maximum traversal depth") do |n|
42
+ options.depth = n
43
+ end
44
+
45
+ opts.on("-c", "--count", "return file count for max depth of folder" ) do |n|
46
+ options.count = n
47
+ end
48
+ end
49
+
50
+ options.leftovers = opts.parse!(args)
51
+ if options.leftovers.size > 0
52
+ if File.exists?( File.expand_path( options.leftovers[0] ) )
53
+ options.path = File.expand_path( options.leftovers[0] )
54
+ end
55
+ end
56
+
57
+ return options
58
+
59
+ end
60
+ end
61
+ end
62
+
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ls_all
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Morgan Prior
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-03 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: ls_all is an executable (command line) tool used to hierarchically list a folders contents.
23
+ email: ls_all_gem@amaras-tech.co.uk
24
+ executables:
25
+ - ls_all
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - lib/ls_all/ls_all.rb
32
+ - lib/ls_all/ls_all_opts.rb
33
+ - lib/ls_all.rb
34
+ - bin/ls_all
35
+ has_rdoc: true
36
+ homepage: http://amaras-tech.co.uk/software/ls_all
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options: []
41
+
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ hash: 3
50
+ segments:
51
+ - 0
52
+ version: "0"
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.3.7
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: ls_all is a command line tool to list folder contents to a specific depth
69
+ test_files: []
70
+