forked from nomovok-opensource/cutedriver-sut_qt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webdav.rb
152 lines (118 loc) · 3.8 KB
/
webdav.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env ruby
############################################################################
##
## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
## All rights reserved.
## Contact: Nokia Corporation ([email protected])
##
## This file is part of TDriver.
##
## If you have questions regarding the use of this file, please contact
## Nokia at [email protected] .
##
## This library is free software; you can redistribute it and/or
## modify it under the terms of the GNU Lesser General Public
## License version 2.1 as published by the Free Software Foundation
## and appearing in the file LICENSE.LGPL included in the packaging
## of this file.
##
############################################################################
# net_digest_auth.rb
require 'digest/md5'
require 'net/http'
begin
require 'net/https'
$webdav_upload_disabled = true
rescue LoadError
#apt-get install libopenssl-ruby
warn("Warning: Disabling WebDAV uploading due to net/https module not available; install libopenssl-ruby libraries or similar depending of the OS")
end
require 'uri'
class DavUpload
attr_accessor :http
def initialize(proxy_host,proxy_port,target_host,target_port)
@http = Net::HTTP::Proxy(proxy_host, proxy_port).new(target_host,target_port)
@http.use_ssl = true
end
def upload_file(src, target)
file=File.open(src)
if file.respond_to? :read
file.rewind
stream = file
length = File.size file.path
else
stream = File.open(file,"rb")
length = File.size file
end
req = Net::HTTP::Put.new(target)
req.basic_auth(@username, @password)
#req.body_stream = stream
req.content_length = length
p length
req["Content-Type"] = "application/octet-stream"
req['Transfer-Encoding'] = 'chunked'
resp = @http.request(req,File.open(src,"rb").read)
p resp.code
p resp.message
end
def create_dir(target)
req = Net::HTTP::Mkcol.new(target)
req.basic_auth(@username, @password)
response = @http.request(req)
end
def move_dir(target, new_target)
req = Net::HTTP::Move.new(target)
req.basic_auth(@username, @password)
response = @http.request(req, new_target)
end
def remove_dir(target)
req = Net::HTTP::Delete.new(target)
req.basic_auth(@username, @password)
resp = @http.request(req)
p resp.code
p resp.message
end
def upload_dir(src, target)
Dir.foreach(src) do |file|
if((file == ".") or (file == ".."))
next
end
new_src = src+ "/" + file
new_target = target + "/" + file
new_target.gsub!(/ /,'%20')
puts new_src
puts new_target
if(File.directory? new_src)
puts "dir detected"
create_dir(new_target)
upload_dir(new_src, new_target)
else
upload_file(new_src, new_target)
end
end
end
def auth(username, password)
@username = username
@password = password
end
end
module DocumentDavupload
def initialize_public_address
@proxy_port = 8080
@target_host = 'projects.forum.nokia.com'
@target_port = '443'
end
def upload_doc_to_public_dav(username,password,doc,version,proxy)
puts "Initialize connection attributes..."
@proxy_host=proxy
initialize_public_address()
trgt_fldr = "/dav/Testabilitydriver/doc/api/#{doc}"
puts "Initialize connection..."
dav = DavUpload.new(@proxy_host, @proxy_port, @target_host, @target_port)
dav.auth(username,password)
puts "Moving old documentation from #{trgt_fldr} to /dav/Testabilitydriver/release/#{version}/doc/api/#{doc}..."
dav.move_dir(trgt_fldr,"/dav/Testabilitydriver/release/#{version}/doc/api/#{doc}")
puts "Uploading new documentation to #{trgt_fldr}"
dav.upload_dir("/doc/output",trgt_fldr)
end
end