Class PutCLI
In: lib/davclient/dav-put.rb
lib/davclient/dav-put.rb
Parent: Object

Methods

put   put  

Public Class methods

[Source]

    # File lib/davclient/dav-put.rb, line 9
 9:   def self.put(args)
10: 
11:     options = read_options(args)
12:     url = args[0]
13:     if(options[:string])then
14: 
15:       # Put string
16:       if(!url.match(/^http.*\/\/([^\/]*)/) and !WebDAV.CWURL)
17:         raise "Error: No current working url set. Use '#{$0} cd url' to set url."
18:       end
19: 
20:       begin
21:         WebDAV.put_string(url,options[:string])
22:       rescue
23:         puts $0 + ": " + $!
24:       end
25:       puts "Published content to: " + url
26:     else
27: 
28:       # Put files(s)
29: 
30:       #  puts "DEBUG: size:" + args.size.to_s
31: 
32:       if(args.size == 1 )
33:         local_file = args[0]
34:         if(not(File.exists?(local_file)))
35:           raise "File not found: #{local_file}"
36:         end
37:         if(!WebDAV.CWURL)
38:           raise "Error: No current working url set. Use '#{$0} cd url' to set url."
39:         end
40: 
41:         WebDAV.put(WebDAV.CWURL, local_file)
42: 
43:       elsif(args.size == 2 and args[1].match(/^http.*\/\/([^\/]*)/) )
44:         local_file = args[0]
45:         url = args[1]
46: 
47:         if(not(File.exists?(local_file)))
48:           raise "File not found: #{local_file}"
49:         end
50: 
51:         if(WebDAV.isCollection?(url))
52:           url += File.basename(local_file)
53:         end
54: 
55:         WebDAV.put(url, local_file)
56: 
57:       else
58: 
59:         # Put more than one file
60: 
61:         if(args.last.match(/^http.*\/\/([^\/]*)/) )
62:            url = args.last
63:            if(!WebDAV.isCollection?(url))
64:              raise "Destination collection not found: " + url
65:            end
66:            args = args[0..(args.size-2)]
67:         else
68:           url = WebDAV.CWURL
69:         end
70: 
71:         count = 0
72:         args.each do | arg|
73:           # puts "arg:" + arg
74:           if(File.ftype(arg) == 'directory')
75:             raise "Upload directories not implemented"
76:           end
77:           if(File.exists?(arg))
78:             basename = File.basename(arg)
79:             WebDAV.put(url + basename, arg)
80:             count = count + 1
81:           else
82:             raise "Error: File not found " + arg
83:           end
84:         end
85:         puts "Published #{count} files to #{url}"
86:       end
87:     end
88: 
89:   end

[Source]

    # File lib/davclient/dav-put.rb, line 9
 9:   def self.put(args)
10: 
11:     options = read_options(args)
12:     url = args[0]
13:     if(options[:string])then
14: 
15:       # Put string
16:       if(!url.match(/^http.*\/\/([^\/]*)/) and !WebDAV.CWURL)
17:         raise "Error: No current working url set. Use '#{$0} cd url' to set url."
18:       end
19: 
20:       begin
21:         WebDAV.put_string(url,options[:string])
22:       rescue
23:         puts $0 + ": " + $!
24:       end
25:       puts "Published content to: " + url
26:     else
27: 
28:       # Put files(s)
29: 
30:       #  puts "DEBUG: size:" + args.size.to_s
31: 
32:       if(args.size == 1 )
33:         local_file = args[0]
34:         if(not(File.exists?(local_file)))
35:           raise "File not found: #{local_file}"
36:         end
37:         if(!WebDAV.CWURL)
38:           raise "Error: No current working url set. Use '#{$0} cd url' to set url."
39:         end
40: 
41:         WebDAV.put(WebDAV.CWURL, local_file)
42: 
43:       elsif(args.size == 2 and args[1].match(/^http.*\/\/([^\/]*)/) )
44:         local_file = args[0]
45:         url = args[1]
46: 
47:         if(not(File.exists?(local_file)))
48:           raise "File not found: #{local_file}"
49:         end
50: 
51:         if(WebDAV.isCollection?(url))
52:           url += File.basename(local_file)
53:         end
54: 
55:         WebDAV.put(url, local_file)
56: 
57:       else
58: 
59:         # Put more than one file
60: 
61:         if(args.last.match(/^http.*\/\/([^\/]*)/) )
62:            url = args.last
63:            if(!WebDAV.isCollection?(url))
64:              raise "Destination collection not found: " + url
65:            end
66:            args = args[0..(args.size-2)]
67:         else
68:           url = WebDAV.CWURL
69:         end
70: 
71:         count = 0
72:         args.each do | arg|
73:           # puts "arg:" + arg
74:           if(File.ftype(arg) == 'directory')
75:             raise "Upload directories not implemented"
76:           end
77:           if(File.exists?(arg))
78:             basename = File.basename(arg)
79:             WebDAV.put(url + basename, arg)
80:             count = count + 1
81:           else
82:             raise "Error: File not found " + arg
83:           end
84:         end
85:         puts "Published #{count} files to #{url}"
86:       end
87:     end
88: 
89:   end

[Validate]