Class: Rget

Inherits:
Object
  • Object
show all
Extended by:
Logging
Defined in:
lib/rget.rb

Overview

A download manager.

Constant Summary collapse

@@log =
init_logger(STDOUT, Logger::INFO)

Instance Method Summary collapse

Methods included from Logging

init_logger, log_level=, log_target=

Methods included from File_Checking

#file_check, file_check

Constructor Details

#initializeRget

reads commandline-options, organizes, reads or updates the download-queue, cuts and washes the vegetables, irons my shirts and starts the download.


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/rget.rb', line 42

def initialize()	
	@log = @@log
	options = ArgParser.parse(ARGV)
	@log.level = $log_level
	@log.debug('options are ' << options.to_s)

	# create the history only after the options have been read.
	$HISTORY = DownloadHistory.instance
	if(options.list_only)
		show_queue
		exit true
	end

	if(options.queued_item)
		@log.debug('queued item is ' << options.queued_item)
		dw = $HISTORY[options.queued_item]
		@log.debug('from queue: ' << dw.to_s)
		@url = $HISTORY[options.queued_item].url
		@file = $HISTORY[options.queued_item].local_file
	end

	@url ||= ARGV.first
	@file ||= ARGV.last if ARGV.length > 1
	if !@url || @url.strip.empty?
		@log.warn('No URL to download!')
		@log.info('Call with option "-h" to see some usage information')
		exit false
	else
		@log.debug('URL to download: ' << @url) 
		if(@file)
			@log.debug('Requested file to write: ' << @file) 
		else
			@file = File.basename(@url)
			@log.debug('Derived file to write: ' << @file) 
		end
		verify_file
	end
	@continue = options.continue
	
	#do it
	download
end