wget 1.0.32
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of wget might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/doc/USAGE.md +3 -0
- data/lib/wget/toplevel_methods.rb +56 -0
- data/lib/wget/version/version.rb +14 -0
- data/lib/wget/wget.rb +303 -0
- data/lib/wget.rb +1 -0
- data/wget.gemspec +43 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ad31778ad08cc8108dcf5cdfeefc022cf7568581138e6a9bfe6052c7ba8f248d
|
4
|
+
data.tar.gz: 12bc4475b3332e1e335662861fb26917c21819af41e9c0c6612d093b087f3efa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bf4360c29c0254e8ca7b6907cf3bc0285b6de2494c434029b4f63e2b8f32acf163f6a6f0954949f1e6576df908724f0582f7744e5531f160e6e65f746ae1fa15
|
7
|
+
data.tar.gz: fc70df81e7b78edb1466bfd2653f4a22d460d7d4fdf926593b1830fd4e7882f037f82bd7274248cf4d6a560b3c38f640e175374956e1dac95687f3addb101a37
|
data/doc/USAGE.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'wget/toplevel_methods.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
class Wget
|
8
|
+
|
9
|
+
# ========================================================================= #
|
10
|
+
# === Wget.download_to?
|
11
|
+
# ========================================================================= #
|
12
|
+
def self.download_to?
|
13
|
+
LAST_DOWNLOADED_FILE
|
14
|
+
end
|
15
|
+
|
16
|
+
# ========================================================================= #
|
17
|
+
# === Wget.check_if_remote_file_exists
|
18
|
+
#
|
19
|
+
# This method will return a boolean value - true if the remote website
|
20
|
+
# (remote URL) exists, and false otherwise. The functionality depends
|
21
|
+
# on the availability of wget.
|
22
|
+
#
|
23
|
+
# The first argument is the target file.
|
24
|
+
#
|
25
|
+
# Invocation example:
|
26
|
+
#
|
27
|
+
# Wget.does_this_remote_website_exist? 'http://shevegen.square7.ch/rbt_changelog.html'
|
28
|
+
#
|
29
|
+
# ========================================================================= #
|
30
|
+
def self.check_if_remote_file_exists(this_file)
|
31
|
+
# ======================================================================= #
|
32
|
+
# Use wget --spider to check if the remote file exists.
|
33
|
+
# ======================================================================= #
|
34
|
+
_ = "wget --spider -v #{this_file} 2>&1"
|
35
|
+
result = `#{_}`
|
36
|
+
if result.include?('Remote file exists') or # Yes, the remote file exists.
|
37
|
+
result =~ /File '.+' exists./
|
38
|
+
remote_file_exists = true
|
39
|
+
else
|
40
|
+
remote_file_exists = false
|
41
|
+
end
|
42
|
+
if result.include? '/404'
|
43
|
+
remote_file_exists = false
|
44
|
+
end
|
45
|
+
return remote_file_exists
|
46
|
+
end; self.instance_eval { alias does_this_remote_website_exist? check_if_remote_file_exists } # === Wget.does_this_remote_website_exist?
|
47
|
+
|
48
|
+
# ========================================================================= #
|
49
|
+
# === Wget.download
|
50
|
+
# ========================================================================= #
|
51
|
+
def self.download(this_file)
|
52
|
+
_ = Wget.new(this_file)
|
53
|
+
_.try_to_report_where_we_downloaded_the_file
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'wget/version/version.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
class Wget
|
8
|
+
|
9
|
+
# ========================================================================= #
|
10
|
+
# === Wget::VERSION
|
11
|
+
# ========================================================================= #
|
12
|
+
VERSION = '1.0.32'
|
13
|
+
|
14
|
+
end
|
data/lib/wget/wget.rb
ADDED
@@ -0,0 +1,303 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === Wget
|
6
|
+
#
|
7
|
+
# This ruby file is a wrapper over wget.
|
8
|
+
#
|
9
|
+
# Right now this class offers this functionality:
|
10
|
+
#
|
11
|
+
# (1) download a remote file via wget
|
12
|
+
# (2) store the location of this download in a general file.
|
13
|
+
#
|
14
|
+
# Usage example:
|
15
|
+
#
|
16
|
+
# Wget.new(ARGV)
|
17
|
+
#
|
18
|
+
# =========================================================================== #
|
19
|
+
# require 'wget'
|
20
|
+
# =========================================================================== #
|
21
|
+
require 'wget/toplevel_methods.rb'
|
22
|
+
require 'wget/version/version.rb'
|
23
|
+
|
24
|
+
class Wget # === Wget.new
|
25
|
+
|
26
|
+
require 'fileutils'
|
27
|
+
|
28
|
+
begin
|
29
|
+
require 'opn'
|
30
|
+
rescue LoadError; end
|
31
|
+
|
32
|
+
begin
|
33
|
+
require 'cliner/module'
|
34
|
+
include Cliner
|
35
|
+
rescue LoadError; end
|
36
|
+
|
37
|
+
begin
|
38
|
+
require 'colours'
|
39
|
+
include Colours
|
40
|
+
rescue LoadError; end
|
41
|
+
|
42
|
+
begin
|
43
|
+
require 'save_file/module'
|
44
|
+
include SaveFile
|
45
|
+
rescue LoadError; end
|
46
|
+
|
47
|
+
# ========================================================================= #
|
48
|
+
# === BACKUP_DIR
|
49
|
+
# ========================================================================= #
|
50
|
+
BACKUP_DIR = '/home/Temp/'
|
51
|
+
|
52
|
+
# ========================================================================= #
|
53
|
+
# === LAST_DOWNLOADED_FILE
|
54
|
+
#
|
55
|
+
# The next line tells us where we keep our last downloaded file.
|
56
|
+
# ========================================================================= #
|
57
|
+
LAST_DOWNLOADED_FILE = ENV['HOME'].to_s+'/LAST_DOWNLOADED_FILE.md'
|
58
|
+
|
59
|
+
# ========================================================================= #
|
60
|
+
# === initialize
|
61
|
+
# ========================================================================= #
|
62
|
+
def initialize(
|
63
|
+
download_this = nil,
|
64
|
+
run_already = true
|
65
|
+
)
|
66
|
+
register_sigint
|
67
|
+
reset
|
68
|
+
set_url(download_this)
|
69
|
+
case run_already.to_s
|
70
|
+
when 'dont','do_not','dont_connect','do_not_connect'
|
71
|
+
run_already = false
|
72
|
+
end
|
73
|
+
if block_given?
|
74
|
+
yielded = yield
|
75
|
+
if yielded.is_a?(Hash) and
|
76
|
+
yielded.has_key?(:namespace)
|
77
|
+
@pass_this_to_opn = yielded.delete(:namespace)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
run if run_already
|
81
|
+
end
|
82
|
+
|
83
|
+
# ========================================================================= #
|
84
|
+
# === register_sigint
|
85
|
+
# ========================================================================= #
|
86
|
+
def register_sigint
|
87
|
+
Signal.trap('SIGINT') { e; exit }
|
88
|
+
end
|
89
|
+
|
90
|
+
# ========================================================================= #
|
91
|
+
# === reset
|
92
|
+
# ========================================================================= #
|
93
|
+
def reset
|
94
|
+
# ======================================================================= #
|
95
|
+
# === @remote_file_exists
|
96
|
+
# ======================================================================= #
|
97
|
+
@remote_file_exists = true
|
98
|
+
# ======================================================================= #
|
99
|
+
# === @pass_this_to_opn
|
100
|
+
# ======================================================================= #
|
101
|
+
@pass_this_to_opn = nil # Whether to pass something to Opn.opn()
|
102
|
+
end
|
103
|
+
|
104
|
+
# ========================================================================= #
|
105
|
+
# === rds
|
106
|
+
# ========================================================================= #
|
107
|
+
def rds(i)
|
108
|
+
i.squeeze('/')
|
109
|
+
end
|
110
|
+
|
111
|
+
# ========================================================================= #
|
112
|
+
# === saving_last_downloaded_file
|
113
|
+
# ========================================================================= #
|
114
|
+
def saving_last_downloaded_file
|
115
|
+
# ======================================================================= #
|
116
|
+
# If the file was successfully downloaded, we will log this.
|
117
|
+
# ======================================================================= #
|
118
|
+
if File.exist?(local_target?)
|
119
|
+
log_this_file_was_downloaded(local_target?)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
# ========================================================================= #
|
124
|
+
# === log_this_file_was_downloaded
|
125
|
+
# ========================================================================= #
|
126
|
+
def log_this_file_was_downloaded(i)
|
127
|
+
opnn; e "Next storing #{simp(i)}"
|
128
|
+
opnn; e 'in '+sfile(LAST_DOWNLOADED_FILE)
|
129
|
+
# ======================================================================= #
|
130
|
+
# As of 17.09.2014 we also add the time:
|
131
|
+
# ======================================================================= #
|
132
|
+
i << " # #{Time.now}"
|
133
|
+
save_what_into(i, LAST_DOWNLOADED_FILE)
|
134
|
+
end
|
135
|
+
|
136
|
+
# ========================================================================= #
|
137
|
+
# === consider_making_a_backup
|
138
|
+
# ========================================================================= #
|
139
|
+
def consider_making_a_backup
|
140
|
+
if remote_file_exists? and File.exist?(local_file?)
|
141
|
+
opnn; e "We will first backup the existing file at `"\
|
142
|
+
"#{sfile(local_file?)}`."
|
143
|
+
backup_existing_file(local_file?)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
# ========================================================================= #
|
148
|
+
# === backup_existing_file
|
149
|
+
# ========================================================================= #
|
150
|
+
def backup_existing_file(i = local_target?)
|
151
|
+
new_target = BACKUP_DIR+File.basename(i)
|
152
|
+
opnn; e 'Now moving existing file from '+sfile(i)+
|
153
|
+
' to '+sfile(new_target)+'.'
|
154
|
+
FileUtils.mv(i, new_target)
|
155
|
+
File.delete(i) if File.exist? i
|
156
|
+
end
|
157
|
+
|
158
|
+
# ========================================================================= #
|
159
|
+
# === local_target?
|
160
|
+
# ========================================================================= #
|
161
|
+
def local_target?
|
162
|
+
rds(Dir.pwd+'/'+File.basename(@url))
|
163
|
+
end; alias local_file? local_target? # === local_file?
|
164
|
+
|
165
|
+
# ========================================================================= #
|
166
|
+
# === consider_downloading_original_file_via_wget
|
167
|
+
#
|
168
|
+
# Simply use wget to download a remote file, but only if it actually
|
169
|
+
# exists.
|
170
|
+
# ========================================================================= #
|
171
|
+
def consider_downloading_original_file_via_wget
|
172
|
+
if remote_file_exists?
|
173
|
+
_ = "wget #{@url}"
|
174
|
+
opnn; e _
|
175
|
+
system(_)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
# ========================================================================= #
|
180
|
+
# === download_last_url
|
181
|
+
#
|
182
|
+
# This will try to download the last saved URL.
|
183
|
+
# ========================================================================= #
|
184
|
+
def download_last_url
|
185
|
+
_ = LAST_DOWNLOADED_FILE
|
186
|
+
if File.exist? _
|
187
|
+
where = File.readlines(_).first
|
188
|
+
# ======================================================================= #
|
189
|
+
# where may include a '#' character such as in
|
190
|
+
# "/Depot/jj/pygtksourceview-2.3.0.tar.bz2 # 2015-01-05 02:37:12 +0100"
|
191
|
+
# We will eliminate this part next.
|
192
|
+
# ======================================================================= #
|
193
|
+
where = where[0, where.index('#')]
|
194
|
+
where = where.strip
|
195
|
+
return where
|
196
|
+
else
|
197
|
+
e 'The file at '+sfile(_)+' does not exist.'
|
198
|
+
end
|
199
|
+
end; alias downloaded_where? download_last_url # === downloaded_where?
|
200
|
+
|
201
|
+
# ========================================================================= #
|
202
|
+
# === url?
|
203
|
+
# ========================================================================= #
|
204
|
+
def url?
|
205
|
+
@url
|
206
|
+
end; alias input? url? # === input?
|
207
|
+
|
208
|
+
# ========================================================================= #
|
209
|
+
# === remote_file_exists?
|
210
|
+
# ========================================================================= #
|
211
|
+
def remote_file_exists?
|
212
|
+
@remote_file_exists
|
213
|
+
end; alias remote_file_exists remote_file_exists? # === remote_file_exists
|
214
|
+
|
215
|
+
# ========================================================================= #
|
216
|
+
# === Wget.remote_file_exists?
|
217
|
+
# ========================================================================= #
|
218
|
+
def self.remote_file_exists?(i)
|
219
|
+
_ = Wget.new(i, :dont_run_yet)
|
220
|
+
_.check_if_remote_file_exists
|
221
|
+
return _.remote_file_exists
|
222
|
+
end
|
223
|
+
|
224
|
+
# ========================================================================= #
|
225
|
+
# === try_to_report_where_we_downloaded_the_file
|
226
|
+
# ========================================================================= #
|
227
|
+
def try_to_report_where_we_downloaded_the_file
|
228
|
+
if downloaded_where?.include? input?
|
229
|
+
opnn; e 'We downloaded into: '+sfancy(downloaded_where?)
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
# ========================================================================= #
|
234
|
+
# === check_if_remote_file_exists
|
235
|
+
#
|
236
|
+
# This method will set the variable @remote_file_exists appropriately.
|
237
|
+
# ========================================================================= #
|
238
|
+
def check_if_remote_file_exists
|
239
|
+
@remote_file_exists = Wget.check_if_remote_file_exists(url?)
|
240
|
+
end
|
241
|
+
|
242
|
+
# ========================================================================= #
|
243
|
+
# === url?
|
244
|
+
# ========================================================================= #
|
245
|
+
def url?
|
246
|
+
@url
|
247
|
+
end
|
248
|
+
|
249
|
+
# ========================================================================= #
|
250
|
+
# === set_url
|
251
|
+
# ========================================================================= #
|
252
|
+
def set_url(i = nil)
|
253
|
+
i = i.first if i.is_a? Array
|
254
|
+
if i.nil?
|
255
|
+
opnn; e 'Wget: We are missing an URL.'
|
256
|
+
opnn; e 'Usage: wget [URL]'
|
257
|
+
exit
|
258
|
+
end
|
259
|
+
case i # case tag
|
260
|
+
# ======================================================================= #
|
261
|
+
# === wget --query
|
262
|
+
# ======================================================================= #
|
263
|
+
when 'QUERY?','?','--query'
|
264
|
+
opnn; e 'The last downloaded URL is at '+sfancy(download_last_url)+'.'
|
265
|
+
exit
|
266
|
+
when 'LAST'
|
267
|
+
i = download_last_url
|
268
|
+
end
|
269
|
+
i = i.to_s.dup
|
270
|
+
i.strip!
|
271
|
+
if i.end_with? '/' or i.end_with? ':'
|
272
|
+
i.chop!
|
273
|
+
end
|
274
|
+
@url = i
|
275
|
+
end
|
276
|
+
|
277
|
+
# ========================================================================= #
|
278
|
+
# === opnn
|
279
|
+
# ========================================================================= #
|
280
|
+
def opnn(optional_pass_this = @pass_this_to_opn)
|
281
|
+
if optional_pass_this
|
282
|
+
Opn.opn(optional_pass_this)
|
283
|
+
else
|
284
|
+
Opn.opn
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
# ========================================================================= #
|
289
|
+
# === run (run tag)
|
290
|
+
# ========================================================================= #
|
291
|
+
def run
|
292
|
+
check_if_remote_file_exists
|
293
|
+
consider_making_a_backup
|
294
|
+
consider_downloading_original_file_via_wget
|
295
|
+
saving_last_downloaded_file # We save the last downloaded file, to make further use of that information.
|
296
|
+
end
|
297
|
+
|
298
|
+
end
|
299
|
+
|
300
|
+
if __FILE__ == $PROGRAM_NAME
|
301
|
+
_ = Wget.new(ARGV)
|
302
|
+
_.try_to_report_where_we_downloaded_the_file
|
303
|
+
end # wgetwrapper http://www.bitcoin.pdf/
|
data/lib/wget.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'wget/wget.rb'
|
data/wget.gemspec
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# =========================================================================== #
|
2
|
+
# Gemspec for Project ruby Wget.
|
3
|
+
# =========================================================================== #
|
4
|
+
require 'wget/version/version.rb'
|
5
|
+
|
6
|
+
Gem::Specification.new { |s|
|
7
|
+
|
8
|
+
s.name = 'wget'
|
9
|
+
s.version = Wget::VERSION
|
10
|
+
s.date = Time.now.strftime('%Y-%m-%d')
|
11
|
+
|
12
|
+
s.summary = <<-EOF
|
13
|
+
|
14
|
+
If you have specific suggestions to make this gem more
|
15
|
+
useful for others, please drop me an email at:
|
16
|
+
shevegen@gmail.com
|
17
|
+
Thank you.
|
18
|
+
|
19
|
+
EOF
|
20
|
+
|
21
|
+
s.description = <<-EOF
|
22
|
+
|
23
|
+
This library is called wget.
|
24
|
+
|
25
|
+
EOF
|
26
|
+
|
27
|
+
s.extra_rdoc_files = %w()
|
28
|
+
|
29
|
+
s.authors = ['Robert A. Heiler']
|
30
|
+
s.email = 'shevegen@gmail.com'
|
31
|
+
s.files = Dir['**/*']
|
32
|
+
s.license = 'GPL-2.0'
|
33
|
+
s.homepage = 'http://rubygems.org/gems/wget'
|
34
|
+
|
35
|
+
s.required_ruby_version = '>= '+RUBY_VERSION
|
36
|
+
s.required_rubygems_version = '>= '+Gem::VERSION
|
37
|
+
s.rubygems_version = '>= '+Gem::VERSION
|
38
|
+
|
39
|
+
s.add_dependency 'opn'
|
40
|
+
s.add_dependency 'colours'
|
41
|
+
s.add_dependency 'save_file'
|
42
|
+
|
43
|
+
}
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wget
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.32
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robert A. Heiler
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-11-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: opn
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: colours
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: save_file
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: |2+
|
56
|
+
|
57
|
+
This library is called wget.
|
58
|
+
|
59
|
+
email: shevegen@gmail.com
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- doc/USAGE.md
|
65
|
+
- lib/wget.rb
|
66
|
+
- lib/wget/toplevel_methods.rb
|
67
|
+
- lib/wget/version/version.rb
|
68
|
+
- lib/wget/wget.rb
|
69
|
+
- wget.gemspec
|
70
|
+
homepage: http://rubygems.org/gems/wget
|
71
|
+
licenses:
|
72
|
+
- GPL-2.0
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.7.2
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 3.1.4
|
88
|
+
requirements: []
|
89
|
+
rubygems_version: 3.1.4
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: 'If you have specific suggestions to make this gem more useful for others,
|
93
|
+
please drop me an email at: shevegen@gmail.com Thank you.'
|
94
|
+
test_files: []
|