zotplus-rakehelper 0.0.35 → 0.0.47

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 17c286f99fa205d3bd90d31612c6b5a8b2dd074c
4
- data.tar.gz: a3a6fb989e31b0cf9fd74c18e679e292b8e8b7e2
3
+ metadata.gz: f6e1837201152a2f2e4ac8d1f61698befaf1e8e4
4
+ data.tar.gz: 9bc9ddfd4ceee2d52d05bfec475d199ad09737c4
5
5
  SHA512:
6
- metadata.gz: 96767ef85bf97b1b8e5f4e4ad1e2f87aa553bb9ac4b01b5200f60f52b1dfc90b6defaf6d8da8ec69dc2f2ae779df1d99deebc12d8556f5430ee7340d476c2050
7
- data.tar.gz: d75fea922ff3a1f4a6fa80ff94df03f72c40b2a4c105cfee13c93300e074b82b075b5652dfc84fc8fc388a0d1d3fadca8e24ad9fc3c55980fcec9c8df1bde791
6
+ metadata.gz: 162789ee4724b5a03bf2220382ec8349576ae47b9c52732657f595ab57c3220e4176829759b977b6c9b510aed9432a40eb47ff9d643fb6b9dd563fba3d0f0879
7
+ data.tar.gz: 7d8603e3d8e425029cf85c6043f98dabc821de009f362131bc8ba105ae62f94fa75eeeb0ae8080afa2a323016f5e77d26cad0fafd44c2c03420b477e68b019bf
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zotplus-rakehelper (0.0.35)
4
+ zotplus-rakehelper (0.0.47)
5
5
  nokogiri
6
6
  rake
7
7
  rickshaw
@@ -1,8 +1,11 @@
1
- require 'typhoeus'
2
1
  require 'nokogiri'
3
2
  require 'zip'
4
3
  require 'rake'
5
4
  require 'rickshaw'
5
+ require 'uri'
6
+ require 'fileutils'
7
+ require 'open-uri'
8
+ require 'ostruct'
6
9
 
7
10
  SOURCES ||= []
8
11
 
@@ -47,13 +50,6 @@ task 'update.rdf' => [XPI, 'install.rdf'] do |t|
47
50
  File.open(t.name, 'w') {|f| rdf.write_xml_to f}
48
51
  end
49
52
 
50
- task :debugbridge do
51
- update = Nokogiri::XML(ZotPlus::RakeHelper.geturl('http://zotplus.github.io/debug-bridge/update.rdf')).at('//em:updateLink').inner_text
52
- debug_bridge = Dir['tmp/zotero-debug-bridge-*.xpi']
53
- debug_bridge.each{|f| File.unlink(f)} if debug_bridge.size != 1 || update.sub(/.*\//, '') != File.basename(debug_bridge[0])
54
- ZotPlus::RakeHelper.download(update, "tmp/#{update.sub(/.*\//, '')}") unless File.file?("tmp/#{update.sub(/.*\//, '')}")
55
- end
56
-
57
53
  task XPI => SOURCES + ['install.rdf'] do
58
54
  puts "Building #{XPI}"
59
55
  Dir["*.xpi"].each{|f| File.unlink(f) }
@@ -107,27 +103,69 @@ end
107
103
 
108
104
  module ZotPlus
109
105
  class RakeHelper
106
+
110
107
  def self.geturl(url)
111
- response = Typhoeus.get(url, {followlocation: true})
112
- raise "Request failed" unless response.success?
113
- return response.body
108
+ return open(url).read
109
+ #OpenURI::HTTPError
114
110
  end
115
111
 
116
112
  def self.download(url, file)
117
113
  puts "Downloading #{url} to #{file}"
118
- target = File.open(file, 'wb')
119
- request = Typhoeus::Request.new(url, {followlocation: true})
120
- request.on_headers do |response|
121
- raise "Request failed: #{response.code.to_s}" unless response.code == 200 # response.success?
122
- end
123
- request.on_body do |chunk|
124
- target.write(chunk)
125
- end
126
- request.on_complete do |response|
127
- target.close
128
- throw "download failed" unless response.success?
114
+ FileUtils.mkdir_p File.dirname(file)
115
+
116
+ data = open(url)
117
+ File.open(file, 'wb'){|f| f.write(data.read) }
118
+ end
119
+
120
+ def self.resolvexpi(source)
121
+ if source =~ /update\.rdf$/
122
+ update_rdf = Nokogiri::XML(self.geturl(source))
123
+ update_rdf.remove_namespaces!
124
+ url = update_rdf.at('//updateLink').inner_text
125
+ elsif source =~ /^https:\/\/addons\.mozilla\.org\//
126
+ page = self.geturl(source)
127
+ page = Nokogiri::HTML(page)
128
+ url = page.at_css('p.install-button').at_css('a')['href']
129
+
130
+ url = URI.join(source, url ).to_s if url !~ /^http/
131
+
132
+ return self.resolvexpi(url) if url =~ /\/contribute\/roadblock\//
133
+
134
+ # AMO uses redirects, so I can't write the file to the final name just yet
135
+ final_uri = nil
136
+ open(url) do |h|
137
+ final_uri = h.base_uri
138
+ end
139
+ url = final_uri.to_s
140
+ elsif source =~ /^file:/ || source =~ /\.xpi(\?|$)/
141
+ url = source
142
+ else
143
+ throw "Unsupported XPI source #{source}"
129
144
  end
130
- request.run
145
+
146
+ return OpenStruct.new(url: url, xpi: url.sub(/.*\//, '').sub(/\?.*$/, ''))
147
+ end
148
+
149
+ def self.getxpis(sources, dir)
150
+ installed = Dir["#{dir}/*.xpi"].collect{|f| File.basename(f) }
151
+
152
+ sources = sources.collect{|s| self.resolvexpi(s) }
153
+
154
+ (installed - sources.collect{|s| s.xpi}).each{|xpi|
155
+ puts "Removing #{xpi}"
156
+ File.unlink("#{dir}/#{xpi}")
157
+ }
158
+ sources.reject{|s| installed.include?(s.xpi) && s.url !~ /^file:/ }.each{|s|
159
+ if s.url =~ /^file:/
160
+ puts "Copying #{s.xpi}"
161
+ path = s.url.sub(/^file:/, '')
162
+ FileUtils.cp(path, "#{dir}/#{s.xpi}")
163
+ else
164
+ puts "Downloading #{s.xpi}"
165
+ self.download(s.url, "#{dir}/#{s.xpi}")
166
+ end
167
+ }
131
168
  end
132
169
  end
170
+
133
171
  end
@@ -1,5 +1,5 @@
1
1
  module ZotPlus
2
2
  class RakeHelper
3
- VERSION = "0.0.35"
3
+ VERSION = "0.0.47"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zotplus-rakehelper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.35
4
+ version: 0.0.47
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emiliano Heyns
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-17 00:00:00.000000000 Z
11
+ date: 2014-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler