wget 1.0.30

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