webarchive 0.1.1 → 0.1.2

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
  SHA256:
3
- metadata.gz: 3ea626a8537199a8b4f730e4ab84eee077ca1e25f313e9d462ecee76a4092f56
4
- data.tar.gz: 60947d9c28e327f0d13dffbc3bfab081c9abe6f6159a6ede5862a2b018ae6435
3
+ metadata.gz: 6b8de1dbf19298def2d098e10af00c9e0f7a01b69720af1edd73622a8ecea35c
4
+ data.tar.gz: 76963d9744f2105055dda1e4b82482c6c63b78f570033c6437e1990958a6ab9b
5
5
  SHA512:
6
- metadata.gz: 7c562804e40aa5974ba89431bdccc6d539e9b29779bf5eb081f62e9a8c852c0ba189a5e2f8d4bd85d085b3ff125a851f939426bfe86fe6317badee455e979290
7
- data.tar.gz: 30f27ce0947b62e359f91f9c0507742a3e829fdb90cd5a2cfbd585f8f0d0740e085b23342b97a9fb3c30341f1895552b1de61b5593dfc94da61496b945ac60ec
6
+ metadata.gz: 51c74e71a5594e9d7380b38196077af19e31687ab471dc510797c6f5399c6842c24cc700364a17112cdb60d22ce130418b812d1e3f969178ac19a327ddf0ba02
7
+ data.tar.gz: 9a9ad84a61416fc8975e3120e5ab933b33fcf1001ef725d3f71bf93081d5695d4b5bedbd7272fe2bdf3bf0d21ea7a79ba624747c2ec2d06bb7741ce78780b38f
@@ -7,16 +7,18 @@ require 'optparse'
7
7
  wait = 4.0
8
8
  debug = false
9
9
  verbose = false
10
+ history = true
10
11
  Version = WebArchive::VERSION
11
12
  OptionParser.new do |opt|
12
13
  opt.on('-w', '--wait=SECS', 'wait for SECS before sending a request') { |v| wait = v.to_f }
13
14
  opt.on('-d', '--debug', 'add debug output, implies verbose') { debug = true }
15
+ opt.on('--[no-]history', 'record history (enabled by default)') { |v| history = v }
14
16
  opt.on('--verbose') { verbose = true }
15
- opt.on('--version') {
16
- puts opt.ver
17
+ opt.on('-h', '--help', 'show help') do
18
+ puts opt
17
19
  exit
18
- }
20
+ end
19
21
  end.parse!(ARGV)
20
22
 
21
23
  warn "#{WebArchive} #{WebArchive::VERSION}" if verbose
22
- WebArchive.launch(wait_secs: wait, debug: debug, verbose: verbose)
24
+ WebArchive.launch(wait_secs: wait, debug: debug, verbose: verbose, history: history)
@@ -43,7 +43,9 @@ module WebArchive
43
43
  begin
44
44
  yield uri
45
45
  rescue StandardError => e
46
- WebArchive.warn_archive_fail(uri, name, ([e.inspect] + e.backtrace).join("\n"))
46
+ WebArchive.warn_archive_fail(
47
+ uri, name, ([e.inspect] + e.backtrace).join("\n")
48
+ )
47
49
  ensure
48
50
  @in_process -= 1
49
51
  break if @all_sent && self.empty?
@@ -124,8 +126,7 @@ module WebArchive
124
126
  @trie.add x.strip
125
127
  end
126
128
  else
127
- File.open(@file, 'w', encoding: 'utf-8') do |f|
128
- end
129
+ File.new(@file, 'w', encoding: 'utf-8').flush
129
130
  end
130
131
  @lastupdate = Time.now
131
132
  end
@@ -136,15 +137,25 @@ module WebArchive
136
137
  @trie.children(s)
137
138
  end
138
139
  end
140
+
141
+ def append_to_history(str)
142
+ File.open(@file, mode: 'a', encoding: 'utf-8') do |f|
143
+ f.puts str
144
+ end
145
+ end
139
146
  end
140
147
 
141
148
  HISTORY_FILE = '~/.webarchive_history'
142
149
 
143
- def self.launch(wait_secs: 1, debug: false, verbose: false, redirect: false, canonical_uri: true)
150
+ def self.launch(wait_secs: 1, debug: false, verbose: false, redirect: false, canonical_uri: true, history: true)
144
151
  verbose = true if debug
145
152
  Thread.abort_on_exception = true
146
- Readline.completion_proc = Completer.new(HISTORY_FILE).to_proc
147
- Readline.completion_append_character = ''
153
+ completer = nil
154
+ if history
155
+ completer = Completer.new(HISTORY_FILE)
156
+ Readline.completion_proc = completer.to_proc
157
+ Readline.completion_append_character = ''
158
+ end
148
159
 
149
160
  queues = []
150
161
 
@@ -223,9 +234,7 @@ module WebArchive
223
234
  warn "skipping canonical/redirect for #{uri}: #{e.message}"
224
235
  end
225
236
 
226
- File.open(File.expand_path(HISTORY_FILE), mode: 'a', encoding: 'utf-8') do |f|
227
- f.puts uri
228
- end
237
+ completer.append_to_history(uri) if completer
229
238
  end
230
239
 
231
240
  queues.each(&:done_sending)
@@ -1,3 +1,3 @@
1
1
  module WebArchive
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webarchive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yusuke Matsubara