vortex_client 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/bin/vrtx-sync +94 -0
- data/lib/vortex_client.rb +211 -4
- metadata +5 -5
data/Rakefile
CHANGED
@@ -10,6 +10,7 @@ begin
|
|
10
10
|
gem.email = "thomas.flemming@usit.uio.no"
|
11
11
|
gem.homepage = "http://github.com/thomasfl/vortex_client"
|
12
12
|
gem.authors = ["Thomas Flemming"]
|
13
|
+
gem.executables = ["vrtx-sync"]
|
13
14
|
gem.add_dependency "net_dav", ">= 0.4.1"
|
14
15
|
gem.add_dependency "highline", ">= 1.5.1"
|
15
16
|
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
data/bin/vrtx-sync
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'uri'
|
4
|
+
require 'vortex_client'
|
5
|
+
|
6
|
+
# vrtx-sync: keep local files synced with webdav content
|
7
|
+
#
|
8
|
+
# Author: Thomas Flemming, thomasfl(at)usit.uio.no
|
9
|
+
# MIT License 2010
|
10
|
+
|
11
|
+
def print_usage
|
12
|
+
puts "usage: #{$0} URI [URI2 URI3..]"
|
13
|
+
puts ""
|
14
|
+
puts "Downloads resource from webdav server. File is "
|
15
|
+
puts "uploaded back to webdav server when file us updated"
|
16
|
+
puts "on local disk. "
|
17
|
+
exit
|
18
|
+
end
|
19
|
+
|
20
|
+
def download(url, vortex)
|
21
|
+
filename = url[/[^\/]*$/,0]
|
22
|
+
file = File.new(filename, "w")
|
23
|
+
begin
|
24
|
+
file.puts vortex.get(url).to_s
|
25
|
+
rescue Net::HTTPServerException => e
|
26
|
+
puts "Server error: " + e.to_s + " " + url
|
27
|
+
exit
|
28
|
+
end
|
29
|
+
path = file.path
|
30
|
+
file.close
|
31
|
+
return path
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
# Monitor files
|
36
|
+
class FileMon
|
37
|
+
|
38
|
+
def initialize(filenames)
|
39
|
+
@last_mtimes = { }
|
40
|
+
filenames.each do |filename|
|
41
|
+
raise "File does not exist: " + filename unless File.exist?(filename)
|
42
|
+
@last_mtimes[filename] = File.stat(filename).mtime
|
43
|
+
end
|
44
|
+
@filenames = filenames
|
45
|
+
end
|
46
|
+
|
47
|
+
def run(sleep=1, &on_update)
|
48
|
+
loop do
|
49
|
+
Kernel.sleep sleep until file_updated?
|
50
|
+
yield @updated_file
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def file_updated?
|
55
|
+
@filenames.each do |filename|
|
56
|
+
mtime = File.stat(filename).mtime
|
57
|
+
updated = @last_mtimes[filename] < mtime
|
58
|
+
@last_mtimes[filename] = mtime
|
59
|
+
if(updated)
|
60
|
+
@updated_file = filename
|
61
|
+
return true
|
62
|
+
end
|
63
|
+
end
|
64
|
+
return false
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
if $*.size < 1
|
71
|
+
print_usage
|
72
|
+
end
|
73
|
+
|
74
|
+
url = $*[0]
|
75
|
+
if(ENV['DAVUSER'] and ENV['DAVPASS'])
|
76
|
+
vortex = Vortex::Connection.new(url, ENV['DAVUSER'], ENV['DAVPASS'])
|
77
|
+
else
|
78
|
+
vortex = Vortex::Connection.new(url)
|
79
|
+
end
|
80
|
+
|
81
|
+
downloaded_files = { }
|
82
|
+
$*.each do |url|
|
83
|
+
puts "Downloading: " + url
|
84
|
+
filename = download(url, vortex)
|
85
|
+
downloaded_files[filename] = url
|
86
|
+
end
|
87
|
+
|
88
|
+
FileMon.new(downloaded_files.keys).run do |filename|
|
89
|
+
url = downloaded_files[filename]
|
90
|
+
file = File.open(filename, "rb")
|
91
|
+
contents = file.read
|
92
|
+
puts "Uploading " + filename + " => " + url
|
93
|
+
vortex.put_string(url, contents)
|
94
|
+
end
|
data/lib/vortex_client.rb
CHANGED
@@ -63,10 +63,9 @@ module Vortex
|
|
63
63
|
def publish(object)
|
64
64
|
if(object.is_a? HtmlArticle)
|
65
65
|
uri = @uri.merge(object.url)
|
66
|
-
# puts "
|
66
|
+
# puts "DEBUG: '" + object.properties
|
67
67
|
self.put_string(uri, object.content)
|
68
68
|
self.proppatch(uri, object.properties)
|
69
|
-
# puts object.properties
|
70
69
|
return uri.to_s
|
71
70
|
else
|
72
71
|
warn "Unknown vortex resource: " + object.class.to_s
|
@@ -83,6 +82,7 @@ module Vortex
|
|
83
82
|
def create(object)
|
84
83
|
if(object.is_a? ArticleListingCollection)
|
85
84
|
uri = @uri.merge(object.url)
|
85
|
+
# puts "DEBUG: uri: " + uri.to_s
|
86
86
|
self.mkdir(uri)
|
87
87
|
self.proppatch(uri, object.properties)
|
88
88
|
return uri.to_s
|
@@ -128,6 +128,213 @@ module Vortex
|
|
128
128
|
if(@url)
|
129
129
|
@url
|
130
130
|
else
|
131
|
+
if(filename)
|
132
|
+
filename
|
133
|
+
end
|
134
|
+
if(title)
|
135
|
+
StringUtils.create_filename(title) + ".html"
|
136
|
+
else
|
137
|
+
warn "Article must have either a full url or title. "
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def properties
|
143
|
+
props = '<v:resourceType xmlns:v="vrtx">article</v:resourceType>' +
|
144
|
+
'<v:xhtml10-type xmlns:v="vrtx">article</v:xhtml10-type>' +
|
145
|
+
'<v:userSpecifiedCharacterEncoding xmlns:v="vrtx">utf-8</v:userSpecifiedCharacterEncoding>'
|
146
|
+
|
147
|
+
if(@publishedDate and @publishedDate != "")
|
148
|
+
if(@publishedDate.kind_of? Time)
|
149
|
+
@publishedDate = @publishedDate.httpdate.to_s
|
150
|
+
end
|
151
|
+
props += '<v:published-date xmlns:v="vrtx">' + @publishedDate + '</v:published-date>'
|
152
|
+
end
|
153
|
+
|
154
|
+
if(date and date != "")
|
155
|
+
if(date.kind_of? Time)
|
156
|
+
date = @date.httpdate.to_s
|
157
|
+
end
|
158
|
+
if(@publishedDate == nil or @publishedDate != "")
|
159
|
+
props += '<v:published-date xmlns:v="vrtx">' + date + '</v:published-date>'
|
160
|
+
end
|
161
|
+
props += '<d:getlastmodified>' + date + '</d:getlastmodified>' +
|
162
|
+
'<v:contentLastModified xmlns:v="vrtx">' + date + '</v:contentLastModified>' +
|
163
|
+
'<v:propertiesLastModified xmlns:v="vrtx">' + date + '</v:propertiesLastModified>' +
|
164
|
+
'<v:creationTime xmlns:v="vrtx">' + date + '</v:creationTime>'
|
165
|
+
end
|
166
|
+
if(title)
|
167
|
+
props += '<v:userTitle xmlns:v="vrtx">' + title + '</v:userTitle>'
|
168
|
+
end
|
169
|
+
if(owner)
|
170
|
+
props += '<owner xmlns="vrtx">' + owner + '</owner>'
|
171
|
+
end
|
172
|
+
if(introduction and introduction != "")
|
173
|
+
props += '<introduction xmlns="vrtx">' + introduction + '</introduction>'
|
174
|
+
end
|
175
|
+
if(author and author != "")
|
176
|
+
props += '<v:authors xmlns:v="vrtx">' +
|
177
|
+
'<vrtx:values xmlns:vrtx="http://vortikal.org/xml-value-list">' +
|
178
|
+
'<vrtx:value>' + author + '</vrtx:value>' +
|
179
|
+
'</vrtx:values>' +
|
180
|
+
'</v:authors>'
|
181
|
+
end
|
182
|
+
|
183
|
+
if(tags and tags.kind_of?(Array) and tags.size > 0)
|
184
|
+
props += '<v:tags xmlns:v="vrtx">' +
|
185
|
+
'<vrtx:values xmlns:vrtx="http://vortikal.org/xml-value-list">'
|
186
|
+
tags.each do |tag|
|
187
|
+
props += "<vrtx:value>#{tag}</vrtx:value>"
|
188
|
+
end
|
189
|
+
props += '</vrtx:values></v:tags>'
|
190
|
+
end
|
191
|
+
|
192
|
+
return props
|
193
|
+
end
|
194
|
+
|
195
|
+
def content
|
196
|
+
content = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ' +
|
197
|
+
'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' +
|
198
|
+
'<html xmlns="http://www.w3.org/1999/xhtml"><head><title>' + title + '</title>' +
|
199
|
+
' <link href="http://www.uio.no/profil/kupu/kupucontentstyles.css" type="text/css" rel="stylesheet"/>' +
|
200
|
+
'</head><body>'
|
201
|
+
if(body)
|
202
|
+
content += body
|
203
|
+
end
|
204
|
+
content += '</body></html>'
|
205
|
+
end
|
206
|
+
|
207
|
+
end
|
208
|
+
|
209
|
+
|
210
|
+
# Plain HTML files with title, introduction and keywords set as webdav properties.
|
211
|
+
#
|
212
|
+
# Examples:
|
213
|
+
#
|
214
|
+
# article = HtmlArticle.new(:title => "Sample Title",
|
215
|
+
# :introduction => "Introduction",
|
216
|
+
# :body => "<p>Hello world</p>")
|
217
|
+
# vortex.publish(article)
|
218
|
+
class HtmlArticle < PlainFile
|
219
|
+
|
220
|
+
attr_accessor :title, :introduction, :body, :filename, :modifiedDate, :publishedDate, :owner, :url, :author, :date, :tags
|
221
|
+
|
222
|
+
# Create a new article of type html-article: plain html file with introduction stored as a webdav property.
|
223
|
+
def initialize(options={})
|
224
|
+
options.each{|k,v|send("#{k}=",v)}
|
225
|
+
end
|
226
|
+
|
227
|
+
def url
|
228
|
+
if(@url)
|
229
|
+
@url
|
230
|
+
else
|
231
|
+
if(filename)
|
232
|
+
filename
|
233
|
+
end
|
234
|
+
if(title)
|
235
|
+
StringUtils.create_filename(title) + ".html"
|
236
|
+
else
|
237
|
+
warn "Article must have either a full url or title. "
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
def properties
|
243
|
+
props = '<v:resourceType xmlns:v="vrtx">article</v:resourceType>' +
|
244
|
+
'<v:xhtml10-type xmlns:v="vrtx">article</v:xhtml10-type>' +
|
245
|
+
'<v:userSpecifiedCharacterEncoding xmlns:v="vrtx">utf-8</v:userSpecifiedCharacterEncoding>'
|
246
|
+
|
247
|
+
if(@publishedDate and @publishedDate != "")
|
248
|
+
if(@publishedDate.kind_of? Time)
|
249
|
+
@publishedDate = @publishedDate.httpdate.to_s
|
250
|
+
end
|
251
|
+
props += '<v:published-date xmlns:v="vrtx">' + @publishedDate + '</v:published-date>'
|
252
|
+
end
|
253
|
+
|
254
|
+
if(date and date != "")
|
255
|
+
if(date.kind_of? Time)
|
256
|
+
date = @date.httpdate.to_s
|
257
|
+
end
|
258
|
+
if(@publishedDate == nil or @publishedDate != "")
|
259
|
+
props += '<v:published-date xmlns:v="vrtx">' + date + '</v:published-date>'
|
260
|
+
end
|
261
|
+
props += '<d:getlastmodified>' + date + '</d:getlastmodified>' +
|
262
|
+
'<v:contentLastModified xmlns:v="vrtx">' + date + '</v:contentLastModified>' +
|
263
|
+
'<v:propertiesLastModified xmlns:v="vrtx">' + date + '</v:propertiesLastModified>' +
|
264
|
+
'<v:creationTime xmlns:v="vrtx">' + date + '</v:creationTime>'
|
265
|
+
end
|
266
|
+
if(title)
|
267
|
+
props += '<v:userTitle xmlns:v="vrtx">' + title + '</v:userTitle>'
|
268
|
+
end
|
269
|
+
if(owner)
|
270
|
+
props += '<owner xmlns="vrtx">' + owner + '</owner>'
|
271
|
+
end
|
272
|
+
if(introduction and introduction != "")
|
273
|
+
props += '<introduction xmlns="vrtx">' + introduction + '</introduction>'
|
274
|
+
end
|
275
|
+
if(author and author != "")
|
276
|
+
props += '<v:authors xmlns:v="vrtx">' +
|
277
|
+
'<vrtx:values xmlns:vrtx="http://vortikal.org/xml-value-list">' +
|
278
|
+
'<vrtx:value>' + author + '</vrtx:value>' +
|
279
|
+
'</vrtx:values>' +
|
280
|
+
'</v:authors>'
|
281
|
+
end
|
282
|
+
|
283
|
+
if(tags and tags.kind_of?(Array) and tags.size > 0)
|
284
|
+
props += '<v:tags xmlns:v="vrtx">' +
|
285
|
+
'<vrtx:values xmlns:vrtx="http://vortikal.org/xml-value-list">'
|
286
|
+
tags.each do |tag|
|
287
|
+
props += "<vrtx:value>#{tag}</vrtx:value>"
|
288
|
+
end
|
289
|
+
props += '</vrtx:values></v:tags>'
|
290
|
+
end
|
291
|
+
|
292
|
+
return props
|
293
|
+
end
|
294
|
+
|
295
|
+
def content
|
296
|
+
content = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ' +
|
297
|
+
'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' +
|
298
|
+
'<html xmlns="http://www.w3.org/1999/xhtml"><head><title>' + title + '</title>' +
|
299
|
+
' <link href="http://www.uio.no/profil/kupu/kupucontentstyles.css" type="text/css" rel="stylesheet"/>' +
|
300
|
+
'</head><body>'
|
301
|
+
if(body)
|
302
|
+
content += body
|
303
|
+
end
|
304
|
+
content += '</body></html>'
|
305
|
+
end
|
306
|
+
|
307
|
+
end
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
# Event
|
312
|
+
#
|
313
|
+
# Examples:
|
314
|
+
#
|
315
|
+
# event = HtmlEvent.new(:title => "Sample Event",
|
316
|
+
# :introduction => "Introduction",
|
317
|
+
# :body => "<p>Hello world</p>",
|
318
|
+
# :startDatetime => Time.now,
|
319
|
+
# :endDatetime => Time.now + (60*60*60),
|
320
|
+
# :venue => "Vilhelm Bjerkes hus, Rom 207" )
|
321
|
+
# vortex.publish(article)
|
322
|
+
class HtmlEvent < PlainFile
|
323
|
+
|
324
|
+
attr_accessor :title, :introduction, :body, :filename, :modifiedDate, :publishedDate, :owner, :url, :author, :date, :tags
|
325
|
+
|
326
|
+
# Create a new article of type html-article: plain html file with introduction stored as a webdav property.
|
327
|
+
def initialize(options={})
|
328
|
+
options.each{|k,v|send("#{k}=",v)}
|
329
|
+
end
|
330
|
+
|
331
|
+
def url
|
332
|
+
if(@url)
|
333
|
+
@url
|
334
|
+
else
|
335
|
+
if(filename)
|
336
|
+
filename
|
337
|
+
end
|
131
338
|
if(title)
|
132
339
|
StringUtils.create_filename(title) + ".html"
|
133
340
|
else
|
@@ -177,7 +384,7 @@ module Vortex
|
|
177
384
|
'</v:authors>'
|
178
385
|
end
|
179
386
|
|
180
|
-
if(tags and tags.kind_of?(Array))
|
387
|
+
if(tags and tags.kind_of?(Array) and tags.size > 0)
|
181
388
|
props += '<v:tags xmlns:v="vrtx">' +
|
182
389
|
'<vrtx:values xmlns:vrtx="http://vortikal.org/xml-value-list">'
|
183
390
|
tags.each do |tag|
|
@@ -204,7 +411,7 @@ module Vortex
|
|
204
411
|
end
|
205
412
|
|
206
413
|
|
207
|
-
# Vortex article stored as JSON data.
|
414
|
+
# Vortex article stored as JSON data. This is just a stub.
|
208
415
|
class StructuredArticle < PlainFile
|
209
416
|
|
210
417
|
attr_accessor :title, :introduction, :content, :filename, :modifiedDate, :publishedDate, :owner, :url
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vortex_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Flemming
|
@@ -9,8 +9,8 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
13
|
-
default_executable:
|
12
|
+
date: 2010-01-21 00:00:00 +01:00
|
13
|
+
default_executable: vrtx-sync
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: net_dav
|
@@ -44,8 +44,8 @@ dependencies:
|
|
44
44
|
version:
|
45
45
|
description: Utility for managing content on Vortex web content management system through webdav
|
46
46
|
email: thomas.flemming@usit.uio.no
|
47
|
-
executables:
|
48
|
-
|
47
|
+
executables:
|
48
|
+
- vrtx-sync
|
49
49
|
extensions: []
|
50
50
|
|
51
51
|
extra_rdoc_files:
|