webdavtools 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/bin/wdav CHANGED
@@ -25,13 +25,17 @@ if(command == "-v" or command =~ /version/ ) then
25
25
  exit
26
26
  end
27
27
 
28
+ $args_array = ARGV
29
+
28
30
  case command
29
31
  when "ls" then
30
32
  require 'webdavtools/wdav_ls'
33
+ WDav.ls(ARGV[1..200])
31
34
  when "pwd"
32
35
  require 'webdavtools/wdav_pwd'
33
36
  when "cd"
34
37
  require 'webdavtools/wdav_cd'
38
+ WDav.cd(ARGV[1..200])
35
39
  when "props"
36
40
  require 'webdavtools/wdav_props'
37
41
  # when "put"
@@ -29,6 +29,7 @@ module WebDAV
29
29
 
30
30
  # Returns current working url. Used by command line utilites
31
31
  def self.CWURL
32
+ return $CWURL if($CWURL) # Used by tests
32
33
  cwurl = nil
33
34
  filename = cwurl_filename
34
35
  if(File.exists?(filename))
@@ -39,6 +40,7 @@ module WebDAV
39
40
 
40
41
  # Sets current working url
41
42
  def self.CWURL=(url)
43
+ $CWURL = url # Used by tests
42
44
  File.open(cwurl_filename, 'w') {|f| f.write(url) }
43
45
  end
44
46
 
@@ -3,14 +3,17 @@
3
3
  require 'rubygems'
4
4
  require 'hpricot'
5
5
 
6
- # Extensions to hpricot xml parser
6
+ # Extensions to the Hpricot XML parser.
7
7
  module Hpricot
8
8
 
9
9
 
10
- # TODO: url method as alias for href
11
10
 
12
11
  class Elem
13
12
 
13
+ # Makes properties available as simple method calls.
14
+ #
15
+ # Example:
16
+ # print item.creationdate()
14
17
  def method_missing(method_name, *args)
15
18
  if(args.size == 0) then
16
19
  return property(method_name.to_s)
@@ -18,10 +21,12 @@ module Hpricot
18
21
  raise "Method missing"
19
22
  end
20
23
 
24
+ # Resource url
21
25
  def href()
22
26
  self.at("d:href").innerText
23
27
  end
24
28
 
29
+ # Returns true of resource is a collection, i.e. a folder and not a file.
25
30
  def isCollection?()
26
31
  self.at("d:collection") != nil
27
32
  end
@@ -1,27 +1,52 @@
1
- # Handle 'wdav cd URL' commands
1
+ # WebDav cd command line utility
2
+ # Synopsis:
3
+ # wdav cd [url|foldername|..]
4
+ #
5
+
2
6
  require 'rubygems'
3
7
  require 'webdavtools'
4
8
 
5
- url = ARGV[1]
6
- if(url =~ /^http/)then
7
- resource = WebDAV.propfind(url)
8
- if(resource and resource.isCollection?)then
9
- WebDAV.CWURL = url
10
- puts "Set WebDAV URL: " + url
11
- else
12
- puts "Error: URL is not a WebDAV collection."
9
+ module WDav
10
+
11
+ def self.cd(args)
12
+ url = args[0]
13
+ if(url =~ /^http/)then
14
+ set_cwurl(url)
15
+ else
16
+ if(url)then
17
+ if(url == "..")then
18
+ # TODO: Standard-lib 'File' class can handle
19
+ # proabably handle cd ../.. etc. better
20
+ url = WebDAV.CWURL.sub(/[^\/]*\/$/, "")
21
+ set_cwurl(url)
22
+ else
23
+ url = WebDAV.CWURL + url
24
+ set_cwurl(url)
25
+ end
26
+ else
27
+ puts "usage: "
28
+ end
29
+ end
13
30
  end
14
- elsif(url)then
15
- cwurl = WebDAV.CWURL
16
- if(not cwurl =~ /\/$/)then
17
- cwurl += "/"
31
+
32
+ private
33
+
34
+ def self.set_cwurl(url)
35
+ if(not(url =~ /\/$/))then
36
+ url += "/"
37
+ end
38
+ resource = WebDAV.propfind(url)
39
+ if(resource and resource.isCollection?)then
40
+ WebDAV.CWURL = url
41
+ puts "Set WebDAV URL: " + url
42
+ else
43
+ puts "Error: URL is not a WebDAV collection."
44
+ end
18
45
  end
19
46
 
20
- item = WebDAV.propfind(cwurl)
21
- require 'pp'
22
- # pp item
23
- type = item.collection?
24
- puts "DEBUG: type:" + type.to_s
25
47
  end
26
48
 
27
- # TODO Should take a folder name as parameter as well
49
+ # Make this script file executable
50
+ if $0 == __FILE__
51
+ WDav.cd(ARGV)
52
+ end
@@ -1,58 +1,79 @@
1
- # Handle command 'wdav ls [url]'
1
+ # WebDav ls command line utility
2
+ # Synopsis:
3
+ # wdav ls [options][url]
4
+ #
2
5
  require 'rubygems'
3
6
  require 'webdavtools'
4
7
  require 'optparse'
5
- options = {}
6
8
 
7
- optparse = OptionParser.new do|opts|
8
- opts.banner = "Usage: #{$0} ls [options] url"
9
+ module WDav
9
10
 
10
- opts.on( '-h', '--help', 'Display this screen' ) do
11
- puts opts
12
- exit
13
- end
11
+ def self.ls(args)
12
+ options = read_options(args)
13
+ url = args[0]
14
+ if(not url)then
15
+ url = WebDAV.CWURL
16
+ if(not url)then
17
+ puts "wdav ls: no current working url"
18
+ puts "Usage: Use 'wdav open url' or 'wdav cd [url|dir] to set current working url"
19
+ exit
20
+ end
21
+ else
22
+ WebDAV.CWURL = url
23
+ end
14
24
 
15
- options[:longFormat] = false
16
- opts.on( '-l', "List in long format" ) do
17
- options[:longFormat] = true
18
- end
25
+ WebDAV.find(url, :recursive => false ) do |item|
26
+ if(options[:showUrl])then
27
+ puts item.href
28
+ elsif(options[:longFormat])
19
29
 
20
- options[:showUrl] = false
21
- opts.on('-a', "Include full url in names.") do
22
- options[:showUrl] = true
30
+ else
31
+ print item.basename
32
+ print "/" if item.isCollection?
33
+ puts
34
+ end
35
+ end
23
36
  end
24
37
 
25
- end
38
+ private
26
39
 
27
- begin
28
- optparse.parse!
29
- rescue
30
- puts "Error: " + $!
31
- puts optparse
32
- exit
33
- end
40
+ def self.read_options(args)
41
+ options = {}
34
42
 
43
+ optparse = OptionParser.new do|opts|
44
+ opts.banner = "Usage: #{$0} ls [options] url"
35
45
 
36
- url = ARGV[1]
37
- if(not url)then
38
- url = WebDAV.CWURL
39
- if(not url)then
40
- puts "wdav ls: no current working url"
41
- puts "Usage: Use 'wdav open url' or 'wdav cd [url|dir] to set current working url"
42
- exit
43
- end
44
- end
46
+ opts.on( '-h', '--help', 'Display this screen' ) do
47
+ puts opts
48
+ exit
49
+ end
45
50
 
46
- WebDAV.find(url, :recursive => false ) do |item|
47
- if(options[:showUrl])then
48
- puts item.href
49
- elsif(options[:longFormat])
51
+ options[:longFormat] = false
52
+ opts.on( '-l', "List in long format" ) do
53
+ options[:longFormat] = true
54
+ end
50
55
 
51
- else
52
- print item.basename
53
- print "/" if item.isCollection?
54
- puts
56
+ options[:showUrl] = false
57
+ opts.on('-a', "Include full url in names.") do
58
+ options[:showUrl] = true
59
+ end
60
+
61
+ end
62
+
63
+ begin
64
+ optparse.parse! args
65
+ rescue
66
+ puts "Error: " + $!
67
+ puts optparse
68
+ exit
69
+ end
70
+
71
+ return options
55
72
  end
73
+
56
74
  end
57
75
 
58
- # TODO only works on collections, should give som info about resources too.
76
+ # Make this file an executable script
77
+ if $0 == __FILE__
78
+ WDav.ls(ARGV)
79
+ end
@@ -7,16 +7,16 @@ options = {}
7
7
 
8
8
  title = nil
9
9
  optparse = OptionParser.new do|opts|
10
- opts.banner = "Usage: #{$0} [options] url"
10
+ opts.banner = "Usage: #{$0} props [options] url"
11
11
 
12
12
  opts.on( '-h', '--help', 'Display this screen' ) do
13
13
  puts opts
14
14
  exit
15
15
  end
16
16
 
17
- options[:xml] = false
18
- opts.on( '-x', '--xml', "Return full xml" ) do
19
- options[:xml] = true
17
+ options[:xml] = true
18
+ opts.on( '-p', '--pretty', "Pretty print output instead of returning xml" ) do
19
+ options[:xml] = false
20
20
  end
21
21
 
22
22
  options[:children] = false
@@ -36,7 +36,10 @@ end
36
36
 
37
37
  url = ARGV[1]
38
38
  if(not(url)) then
39
- # TODO: Use CWURL if not set
39
+ url = WebDAV.CWURL
40
+ end
41
+
42
+ if(not(url)) then
40
43
  puts "Error: Missing mandatory url"
41
44
  puts optparse
42
45
  exit
@@ -54,7 +57,7 @@ prev_url = nil
54
57
  WebDAV.find(url, :children => options[:children]) do | url, item |
55
58
  if(prev_url != url) then
56
59
  puts
57
- puts "url = " + url
60
+ puts "url = " + url.to_s
58
61
  prev_url = url
59
62
  end
60
63
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webdavtools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Flemming
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-27 00:00:00 +02:00
12
+ date: 2009-08-28 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,6 +22,16 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: "0.6"
24
24
  version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: zentest
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "3.5"
34
+ version:
25
35
  description: WebDAV client written in Ruby for managing content on webservers that support the WebDAV extensions.
26
36
  email: thomas.flemming@gmail.com
27
37
  executables: