class Wget
#¶ ↑
require 'wget/toplevel_methods.rb'
#¶ ↑
#¶ ↑
require 'wget/version/version.rb'
#¶ ↑
Constants
- BACKUP_DIR
#¶ ↑
BACKUP_DIR
¶ ↑#¶ ↑
- LAST_DOWNLOADED_FILE
#¶ ↑
LAST_DOWNLOADED_FILE
¶ ↑The next line tells us where we keep our last downloaded file.
#¶ ↑
- VERSION
#¶ ↑
Wget::VERSION
¶ ↑#¶ ↑
Public Class Methods
check_if_remote_file_exists(this_file)
click to toggle source
#¶ ↑
Wget.check_if_remote_file_exists
¶ ↑
This method will return a boolean value - true if the remote website (remote URL) exists, and false otherwise. The functionality depends on the availability of wget.
The first argument is the target file.
Invocation example:
Wget.does_this_remote_website_exist? 'http://shevegen.square7.ch/rbt_changelog.html'
#¶ ↑
# File lib/wget/toplevel_methods.rb, line 30 def self.check_if_remote_file_exists(this_file) # ======================================================================= # # Use wget --spider to check if the remote file exists. # ======================================================================= # _ = "wget --spider -v #{this_file} 2>&1" result = `#{_}` if result.include?('Remote file exists') or # Yes, the remote file exists. result =~ /File '.+' exists./ remote_file_exists = true else remote_file_exists = false end if result.include? '/404' remote_file_exists = false end return remote_file_exists end
download(this_file)
click to toggle source
download_to?()
click to toggle source
new( download_this = nil, run_already = true ) { || ... }
click to toggle source
#¶ ↑
initialize¶ ↑
#¶ ↑
# File lib/wget/wget.rb, line 62 def initialize( download_this = nil, run_already = true ) register_sigint reset set_url(download_this) case run_already.to_s when 'dont','do_not','dont_connect','do_not_connect' run_already = false end if block_given? yielded = yield if yielded.is_a?(Hash) and yielded.has_key?(:namespace) @pass_this_to_opn = yielded.delete(:namespace) end end run if run_already end
Public Instance Methods
backup_existing_file(i = local_target?)
click to toggle source
check_if_remote_file_exists()
click to toggle source
#¶ ↑
check_if_remote_file_exists
¶ ↑
This method will set the variable @remote_file_exists appropriately.
#¶ ↑
# File lib/wget/wget.rb, line 238 def check_if_remote_file_exists @remote_file_exists = Wget.check_if_remote_file_exists(url?) end
Also aliased as: does_this_remote_website_exist?
consider_downloading_original_file_via_wget()
click to toggle source
consider_making_a_backup()
click to toggle source
download_last_url()
click to toggle source
#¶ ↑
download_last_url
¶ ↑
This will try to download the last saved URL.
#¶ ↑
# File lib/wget/wget.rb, line 184 def download_last_url _ = LAST_DOWNLOADED_FILE if File.exist? _ where = File.readlines(_).first # ======================================================================= # # where may include a '#' character such as in # "/Depot/jj/pygtksourceview-2.3.0.tar.bz2 # 2015-01-05 02:37:12 +0100" # We will eliminate this part next. # ======================================================================= # where = where[0, where.index('#')] where = where.strip return where else e 'The file at '+sfile(_)+' does not exist.' end end
Also aliased as: downloaded_where?
local_target?()
click to toggle source
#¶ ↑
local_target?¶ ↑
#¶ ↑
# File lib/wget/wget.rb, line 161 def local_target? rds(Dir.pwd+'/'+File.basename(@url)) end
Also aliased as: local_file?
log_this_file_was_downloaded(i)
click to toggle source
#¶ ↑
log_this_file_was_downloaded
¶ ↑
#¶ ↑
# File lib/wget/wget.rb, line 126 def log_this_file_was_downloaded(i) opnn; e "Next storing #{simp(i)}" opnn; e 'in '+sfile(LAST_DOWNLOADED_FILE) # ======================================================================= # # As of 17.09.2014 we also add the time: # ======================================================================= # i << " # #{Time.now}" save_what_into(i, LAST_DOWNLOADED_FILE) end
opnn(optional_pass_this = @pass_this_to_opn)
click to toggle source
rds(i)
click to toggle source
register_sigint()
click to toggle source
remote_file_exists?()
click to toggle source
#¶ ↑
remote_file_exists
?¶ ↑
#¶ ↑
# File lib/wget/wget.rb, line 211 def remote_file_exists? @remote_file_exists end
Also aliased as: remote_file_exists
reset()
click to toggle source
#¶ ↑
reset¶ ↑
#¶ ↑
# File lib/wget/wget.rb, line 93 def reset # ======================================================================= # # === @remote_file_exists # ======================================================================= # @remote_file_exists = true # ======================================================================= # # === @pass_this_to_opn # ======================================================================= # @pass_this_to_opn = nil # Whether to pass something to Opn.opn() end
run()
click to toggle source
saving_last_downloaded_file()
click to toggle source
#¶ ↑
saving_last_downloaded_file
¶ ↑
#¶ ↑
# File lib/wget/wget.rb, line 114 def saving_last_downloaded_file # ======================================================================= # # If the file was successfully downloaded, we will log this. # ======================================================================= # if File.exist?(local_target?) log_this_file_was_downloaded(local_target?) end end
set_url(i = nil)
click to toggle source
#¶ ↑
set_url
¶ ↑
#¶ ↑
# File lib/wget/wget.rb, line 252 def set_url(i = nil) i = i.first if i.is_a? Array if i.nil? opnn; e 'Wget: We are missing an URL.' opnn; e 'Usage: wget [URL]' exit end case i # case tag # ======================================================================= # # === wget --query # ======================================================================= # when 'QUERY?','?','--query' opnn; e 'The last downloaded URL is at '+sfancy(download_last_url)+'.' exit when 'LAST' i = download_last_url end i = i.to_s.dup i.strip! if i.end_with? '/' or i.end_with? ':' i.chop! end @url = i end
try_to_report_where_we_downloaded_the_file()
click to toggle source