Parent

Methods

Class/Module Index [+]

Quicksearch

LsCLI

Public Class Methods

ls(args) click to toggle source
# 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

[Validate]

Generated with the Darkfish Rdoc Generator 2.