Class: LsCLI

Inherits:
Object
  • Object
show all
Defined in:
lib/davclient/dav-ls.rb

Class Method Summary collapse

Class Method Details

.ls(args) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/davclient/dav-ls.rb', line 15

def self.ls(args)
  options = read_options(args)
  url = args[0]
  tmp_cwurl = WebDAV.CWURL
  if(not url)then
    url = WebDAV.CWURL
    if(not url)then
      puts "#{$0} ls: no current working url"
      puts "Usage: Use '#{$0} cd [url|dir] to set current working url"
      exit
    end
  else
    WebDAV.cd(url)  # TODO Hva er denne til?. Crasher 'dav-ls filnavn.html'!
  end

  url = WebDAV.CWURL
  names = []
  items_data = { }

  WebDAV.find(url, :recursive => false ) do |item|
    if(options[:showUrl])then
      puts item.href

    elsif(options[:longFormat])
      locked = item.search("d:lockdiscovery").search("d:owner").inner_text
      items_data.merge!(item.basename => [item.href,
                                          locked,
                                          item.getlastmodified,
                                          item.getcontentlength])

    else
      # Collect all names in a folder and show them with multiple columns

      name = item.basename
      if(item.isCollection?)
        path = item.href.sub(/#{name}\/$/,"")
      else
        path = item.href.sub(/#{name}$/,"")
      end

      name +=  "/" if item.isCollection?

      # puts name.ljust(35) + path
      names << name
    end
  end

  if(options[:oneColumn])
    puts names.sort.join("\n")

  elsif(options[:longFormat])
    max_key_size = max_string_size(items_data.keys)
    items_data.keys.sort.each do |key|
      locked = ""
      locked = "Locked by: " + items_data[key][1] if(items_data[key][1] != "")
      puts key.ljust(max_key_size) + "  " + items_data[key][2] +
        "  " + items_data[key][3].rjust(12) +
        "  " + locked
    end

  else
    multicolumn_print(names.sort)
  end

  # Restore CWURL
  WebDAV.cd(tmp_cwurl)
end