vortex_client 0.7.0 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,7 +1,8 @@
1
1
  = Vortex Client
2
2
 
3
- A set of utilities for managing content in the web content management system "Vortex":http://www.usit.uio.no/it/vortex/.
4
- All operations are done by using the webdav protocol.
3
+ A Ruby API for the "Vortex":http://www.usit.uio.no/it/vortex/ Content Management System developed at the
4
+ University of Oslo in Norway by IT Services department.
5
+ The Ruby API uses the WebDAV protocol, supported by Vortex, to manage content.
5
6
 
6
7
 
7
8
  = Publishing content
@@ -50,11 +51,11 @@ If your'e having problems installing the xml parser nokogiri on is x: http://wi
50
51
  Also how to compile ruby 1.9.1 on os x http://wonko.com/post/how-to-compile-ruby-191
51
52
  On ubuntu openssl can be an issue http://blog.maxaller.name/2009/02/ruby-19-and-openssl-on-ubuntu/
52
53
 
53
- = Using KeyChain authentication on OS X
54
+ = Storing passwords in KeyChain on OS X
54
55
 
55
- To retrieve password from KeyChain on OS X, use the option :use_osx_keychain => true.
56
+ To retrieve password from KeyChain on OS X, use the option :osx_keychain => true.
56
57
 
57
- vortex = Vortex::Connection.new("https://www-dav.server.com", :use_osx_keychain => true)
58
+ vortex = Vortex::Connection.new("https://www-dav.server.com", :osx_keychain => true)
58
59
 
59
60
  When running for the first time, ruby prompts for the password. Username must be
60
61
  the same both locally and on the server.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.0
1
+ 0.7.2
@@ -131,7 +131,7 @@ end
131
131
 
132
132
  # src_url = 'https://nyweb3-dav.uio.no/konv/ubo/'
133
133
  src_url = 'https://nyweb1-dav.uio.no/personer/genererte-presentasjoner/econ/'
134
- @vortex = Vortex::Connection.new(src_url, :use_osx_keychain => true)
134
+ @vortex = Vortex::Connection.new(src_url, :osx_keychain => true)
135
135
 
136
136
  # puts "Restore from backup..."
137
137
  # delete(src_url)
@@ -1,7 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'vortex_client'
3
3
 
4
- vortex = Vortex::Connection.new('https://nyweb2-dav.uio.no/', :use_osx_keychain => true)
4
+ vortex = Vortex::Connection.new('https://nyweb2-dav.uio.no/', :osx_keychain => true)
5
5
  # url = 'https://nyweb2-dav.uio.no/for-ansatte/aktuelt/hf-aktuelt-mod/utg2/index.html'
6
6
  url = '/for-ansatte/aktuelt/hf-aktuelt-mod/utg2/index.html'
7
7
  snippet = '<hideAdditionalContent xmlns="http://www.uio.no/vrtx/__vrtx/ns/structured-resources">true</hideAdditionalContent>'
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'vortex_client'
3
+ require 'open-uri'
4
+ require 'uri'
5
+ require 'pathname'
6
+
7
+ # Download and upload a binary file to Vortex
8
+
9
+ url = 'http://www.hlsenteret.no/248/267/Bakgrunn_Rwanda.pdf'
10
+ content = open(url).read
11
+
12
+ filename = Pathname.new( URI.parse(url).path ).basename.to_s
13
+
14
+ vortex = Vortex::Connection.new("https://vortex-dav.uio.no/")
15
+ vortex.cd('/brukere/thomasfl/')
16
+ vortex.put_string(filename, content)
@@ -12,7 +12,7 @@ class MigrateSuicidologi
12
12
  attr :vortex, :uri
13
13
 
14
14
  def initialize(url)
15
- @vortex = Vortex::Connection.new(url,:use_osx_keychain => true)
15
+ @vortex = Vortex::Connection.new(url,:osx_keychain => true)
16
16
  @uri = URI.parse(url)
17
17
  end
18
18
 
@@ -0,0 +1,50 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'rubygems'
3
+ require 'nokogiri'
4
+ require 'vortex_client'
5
+ require 'pathname'
6
+ require 'json'
7
+
8
+ def make_links_relative(dav_url)
9
+ vortex = Vortex::Connection.new(dav_url, :osx_keychain => true)
10
+ vortex.cd(URI.parse(dav_url).path.to_s)
11
+ count = 0
12
+ vortex.find('.', :recursive => true, :filename=>/\.html$/) do |item|
13
+ count = count + 1
14
+ puts "Checking : " + count.to_s + ": " + item.url.to_s
15
+
16
+ json_data = JSON.parse(item.content)
17
+ content = json_data["properties"]["content"]
18
+ dirty = false
19
+ doc = Nokogiri::HTML(content)
20
+ doc.css('a').each do |element|
21
+ href = element['href']
22
+ if(href and href[/^\//])then
23
+ pathname_from = Pathname.new( URI.parse(item.url.to_s).path.to_s )
24
+ pathname_to = Pathname.new( URI.parse(href.to_s).path.to_s )
25
+ new_href = pathname_to.relative_path_from(pathname_from.parent).to_s
26
+ element['href'] = new_href
27
+ puts " " + href + " => " + new_href
28
+ dirty = true
29
+ end
30
+ end
31
+ if(dirty)then
32
+ json_data["properties"]["content"] = doc.to_s
33
+ item.content = json_data.to_json
34
+ puts "Updating : " + item.url.to_s
35
+ puts
36
+ end
37
+ end
38
+
39
+ end
40
+
41
+ url = ARGV[0]
42
+ if(not(url))then
43
+ puts "Usage: make_links_relative URL"
44
+ puts
45
+ puts "Example: make_links_relative https://www-dav.vortex-demo.uio.no/tmp/relativiser/ "
46
+ puts "Looks for links in vortex documents stored as json. Takes a vortex webdav url as"
47
+ puts "parameter. Searches recursively through subfolders."
48
+ else
49
+ make_links_relative(url)
50
+ end
@@ -1,7 +1,8 @@
1
1
  require 'rubygems'
2
2
  require 'vortex_client'
3
3
 
4
- vortex = Vortex::Connection.new("https://www-dav.vortex-demo.uio.no/", :use_osx_keychain => true)
4
+ vortex = Vortex::Connection.new("https://www-dav.vortex-demo.uio.no/", :osx_keychain => true)
5
5
  props = vortex.propfind('/index.html')
6
+ puts props
6
7
 
7
8
  vortex.proppatch('/index.html','<v:title xmlns:v="vrtx">Forside vortex demo</v:title>')
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ require 'vortex_client'
3
+ require 'json'
4
+
5
+ vortex = Vortex::Connection.new("https://vortex-dav.uio.no/", :osx_keychain => true)
6
+
7
+ data = {
8
+ :resourcetype => "structured-article",
9
+ :properties => {
10
+ :title => "Hello world",
11
+ :introduction => "Short introduction",
12
+ :content => "<p>Longer body</p>",
13
+ :author => "Thomas Flemming"}
14
+ }
15
+
16
+ uri = URI.parse('/brukere/thomasfl/nyheter/json_test.html')
17
+ vortex.put_string(uri,data.to_json)
18
+
19
+ vortex.proppatch(uri, '<v:publish-date xmlns:v="vrtx">' + Time.now.httpdate.to_s + '</v:publish-date>')
20
+
@@ -26,7 +26,7 @@ require 'pp'
26
26
  # - Hvorfor konverteres og publiseres /konv/kunnskapsbasen/-a-hrefhttp-.html
27
27
  # - Håndtere /konv/kunnskapsbasen/hl-senterets-kunnskapsbase.html spesielt?
28
28
 
29
- @vortex = Vortex::Connection.new("https://nyweb4-dav.uio.no", :use_osx_keychain => true)
29
+ @vortex = Vortex::Connection.new("https://nyweb4-dav.uio.no", :osx_keychain => true)
30
30
 
31
31
  # Simple logger
32
32
  def log(str)
@@ -252,7 +252,6 @@ EOF
252
252
  end
253
253
 
254
254
  def scrape_article(url)
255
- # puts "Scraping article: " + url
256
255
  doc = Nokogiri::HTML.parse(open(url))
257
256
  doc.encoding = 'utf-8'
258
257
  if(doc.css(".article .title").size() == 0)then
@@ -5,7 +5,7 @@ require 'vortex_client'
5
5
  #
6
6
  # Find all files recursively under '/people' with name 'index.html', and set "unpublished-date" to now.
7
7
 
8
- @vortex = Vortex::Connection.new("https://nyweb2-dav.uio.no/", :use_osx_keychain => true)
8
+ @vortex = Vortex::Connection.new("https://nyweb2-dav.uio.no/", :osx_keychain => true)
9
9
  @vortex.find('/people/', :recursive => true, :filename=>/\.html$/) do |item|
10
10
  item.proppatch('<v:unpublish-date xmlns:v="vrtx">'+Time.now.httpdate.to_s+'</v:unpublish-date>')
11
11
  end
data/lib/vortex_client.rb CHANGED
@@ -2,6 +2,7 @@
2
2
  require 'net/dav'
3
3
  require 'vortex_client/string_utils'
4
4
  require 'vortex_client/person'
5
+ require 'vortex_client/utilities'
5
6
  require 'highline/import'
6
7
  require 'time'
7
8
 
@@ -165,6 +166,46 @@ module Vortex
165
166
  end
166
167
  end
167
168
 
169
+ # Create path - create all folders in the given path if they do not exist.
170
+ #
171
+ # Default is article-listing folder and the foldername used as title.
172
+ #
173
+ # Example:
174
+ #
175
+ # create_path('/folders/to/be/created/')
176
+ # create_path('/folders/to/be/created/', :type => "event-listing", :title => "Testing")
177
+ def create_path(dest_path, *args)
178
+ title = nil
179
+ if(args.size > 0)then
180
+ type = args[0][:type]
181
+ title = args[0][:title]
182
+ end
183
+ if(not(type))then
184
+ type = "article-listing"
185
+ end
186
+
187
+ destination_path = "/"
188
+ dest_path.split("/").each do |folder|
189
+ if(folder != "")then
190
+ folder = folder.downcase
191
+ destination_path = destination_path + folder + "/"
192
+ if( not(exists?(destination_path)) )then
193
+ mkdir(destination_path)
194
+ proppatch(destination_path,'<v:collection-type xmlns:v="vrtx">' + type + '</v:collection-type>')
195
+ if(title)then
196
+ proppatch(destination_path,'<v:userTitle xmlns:v="vrtx">' + title.to_s + '</v:userTitle>')
197
+ end
198
+ end
199
+ end
200
+ end
201
+ return destination_path
202
+ end
203
+
204
+ # Returns current working directory on vortex/webdav server as string.
205
+ def cwd
206
+ return cd("").to_s
207
+ end
208
+
168
209
  private
169
210
 
170
211
  # Disable Net::DAV.credentials
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vortex_client
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 0
10
- version: 0.7.0
9
+ - 2
10
+ version: 0.7.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Thomas Flemming
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-30 00:00:00 +02:00
18
+ date: 2011-07-12 00:00:00 +02:00
19
19
  default_executable: vrtx-sync
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -86,13 +86,16 @@ files:
86
86
  - examples/create_personpresentations.rb
87
87
  - examples/dice.gif
88
88
  - examples/disable_right_column.rb
89
+ - examples/download_and_upload_pdf.rb
89
90
  - examples/import_static_site.rb
90
91
  - examples/ldap_util.rb
92
+ - examples/make_links_relative.rb
91
93
  - examples/no_right_margin.rb
92
94
  - examples/person_presentation.rb
93
95
  - examples/propfind_proppatch.rb
94
96
  - examples/publish_article.rb
95
97
  - examples/publish_event.rb
98
+ - examples/publish_json.rb
96
99
  - examples/scrape_hero_publications.rb
97
100
  - examples/scrape_holocaust.rb
98
101
  - examples/scrape_holocaust_related_links.rb
@@ -117,10 +120,6 @@ files:
117
120
  - test/test_vortex_pic.rb
118
121
  - test/test_vortex_tags.rb
119
122
  - test/test_vortex_utils.rb
120
- - examples/replace_spike.rb
121
- - examples/search_replace_documents_frontpage.rb
122
- - examples/test_searc_replace.rb
123
- - examples/upload_image_flymake.rb
124
123
  has_rdoc: true
125
124
  homepage: http://github.com/thomasfl/vortex_client
126
125
  licenses: []
@@ -160,25 +159,24 @@ test_files:
160
159
  - examples/create_collection.rb
161
160
  - examples/create_personpresentations.rb
162
161
  - examples/disable_right_column.rb
162
+ - examples/download_and_upload_pdf.rb
163
163
  - examples/import_static_site.rb
164
164
  - examples/ldap_util.rb
165
+ - examples/make_links_relative.rb
165
166
  - examples/no_right_margin.rb
166
167
  - examples/person_presentation.rb
167
168
  - examples/propfind_proppatch.rb
168
169
  - examples/publish_article.rb
169
170
  - examples/publish_event.rb
170
- - examples/replace_spike.rb
171
+ - examples/publish_json.rb
171
172
  - examples/scrape_hero_publications.rb
172
173
  - examples/scrape_holocaust.rb
173
174
  - examples/scrape_holocaust_related_links.rb
174
175
  - examples/scrape_vortex_search.rb
175
176
  - examples/search_replace_documents.rb
176
- - examples/search_replace_documents_frontpage.rb
177
177
  - examples/sitemap.rb
178
- - examples/test_searc_replace.rb
179
178
  - examples/unpublish.rb
180
179
  - examples/upload_image.rb
181
- - examples/upload_image_flymake.rb
182
180
  - test/helper.rb
183
181
  - test/test_acl.rb
184
182
  - test/test_date_conversion.rb
@@ -1,42 +0,0 @@
1
- require 'rubygems'
2
- require 'vortex_client'
3
- require 'json'
4
- require 'scrape_vortex_search'
5
- require 'pp'
6
- require 'uri'
7
-
8
- # Replace text in json document on server
9
- # Optional resourcetype can
10
- def replace(host, path, from, to, *resourcetype)
11
- verbose = false
12
- host = host.sub(/\/$/,'')
13
- uri = URI.parse(path)
14
- url = host + uri.path
15
- url = url.sub(/\/$/,'/index.html')
16
-
17
- vortex = Vortex::Connection.new(host,:use_osx_keychain => true)
18
- vortex.find(url) do |item|
19
-
20
- data = nil
21
- begin
22
- data = JSON.parse(item.content)
23
- rescue
24
- if(verbose)then
25
- puts "Warning. Bad document. Not json: " + item.uri.to_s
26
- end
27
- return 0
28
- end
29
-
30
- if(resourcetype[0] and resourcetype[0].class == String and data["resourcetype"] != resourcetype[0] )then
31
- if(verbose)then
32
- puts "Warning: resourcetype not: " + resourcetype[0]
33
- end
34
- return 0
35
- end
36
-
37
- puts "Oppdaterer: " + item.uri.to_s
38
- new_content = item.content.sub(from,to)
39
- item.content = new_content
40
- return 1
41
- end
42
- end
@@ -1,88 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- # Search and replace a set of sentences in a set of folders on vortex webdav server.
3
- #
4
- #
5
- # for alle forside-dokumenter på jus.uio.no, tf.uio.no, hf.uio.no, uv.uio.no, sv.uio.no, odontologi.uio.no
6
- #
7
- #
8
- # Author: Thomas Flemming 2010 thomasfl@usit.uio.no
9
-
10
- require 'rubygems'
11
- require 'vortex_client'
12
- require 'json'
13
- require 'scrape_vortex_search'
14
- require 'pp'
15
- require 'uri'
16
-
17
- replacements = {
18
- "Ansettelsesforhold ved UiO" => "Ansettelsesforhold for alle ansatte ved UiO",
19
- "Arbeidsstøtte ved UiO" => "Arbeidsstøtte for alle ansatte ved UiO",
20
- "Drift og servicefunksjoner ved UiO" =>"Drift og servicefunksjoner for alle ansatte ved UiO",
21
- "Kompetanseutvikling ved UiO" => "Kompetanseutvikling for alle ansatte ved UiO"
22
- }
23
-
24
- hosts = [
25
- "https://www-dav.hf.uio.no/",
26
- "https://www-dav.odont.uio.no",
27
- "https://www-dav.jus.uio.no/",
28
- "https://www-dav.tf.uio.no/",
29
- "https://www-dav.uv.uio.no/",
30
- "https://www-dav.sv.uio.no/"
31
- ]
32
-
33
- # Opens a json document in vortex.
34
- #
35
- # Example:
36
- #
37
- # with_json_doc(path) do |dav_item, json_data|
38
- # puts json_data["resourcetype"]
39
- # dav_item.content = dav_item.content.sub('Oxford','UiO')
40
- # end
41
-
42
- def with_json_doc(url)
43
- vortex = Vortex::Connection.new(url,:use_osx_keychain => true)
44
- if(not(vortex.exists?(url)))then
45
- puts "Warning: Can't find " + url
46
- return -1
47
- end
48
- vortex.find(url) do |item|
49
- begin
50
- data = JSON.parse(item.content)
51
- yield item, data
52
- rescue
53
- return -1
54
- end
55
- end
56
- end
57
-
58
- hosts.each do |host|
59
- search_host = host.sub("www-dav","www")
60
- replacements.each do |from, to|
61
- puts "Replacing: '#{from}' => '#{to}'"
62
- search_results = vortex_search(search_host, from)
63
- # TODO remove not( /(\.html)|\// alt untatt '.../' eller 'html'
64
- search_results.delete_if {|x| x =~ /\.pdf$/} # Remove pdf files
65
- count = 0
66
- search_results.each do |path|
67
- if(not(path =~ /\.html$/))then
68
- path = path + "index.html"
69
- end
70
- # count = count + replace(host, path, from, to, "frontpage")
71
- path = path.sub(/^http:/, 'https:').sub(/\/\/www\./,'//www-dav.')
72
- with_json_doc(path) do |item, data|
73
- if(data["resourcetype"] == "frontpage")then
74
- puts "Updating:" + path
75
- item.content = item.content.sub(from,to)
76
-
77
- if(item.content.to_s =~ Regexp.new(from))then
78
- puts "Warning: Not updated."
79
- else
80
- count = count + 1
81
- end
82
- end
83
- end
84
- end
85
- puts "Updated #{count.to_s} documents."
86
- puts
87
- end
88
- end
@@ -1,3 +0,0 @@
1
- require 'rubygems'
2
-
3
- puts 'Start'
@@ -1,8 +0,0 @@
1
- require 'rubygems'
2
- require 'vortex_client'
3
-
4
- # Upload a binary file to Vortex
5
- vortex = Vortex::Connection.new("https://vortex-dav.uio.no/")
6
- vortex.cd('/brukere/thomasfl/')
7
- content = open("dice.gif", "rb") {|io| io.read }
8
- vortex.put_string("dice_6.gif", content)