Class: WCC::Prog

Inherits:
Object
  • Object
show all
Defined in:
lib/wcc.rb

Class Method Summary collapse

Class Method Details

.exit(errno) ⇒ Object

Central exit function, allows wcc a clean shutdown.



422
423
424
# File 'lib/wcc.rb', line 422

def self.exit(errno)
	Kernel::exit errno
end

.load_template(name) ⇒ ERB

Attempts to read the named template file from template.d and converts it into ERB.

Parameters:

  • name (String)

    file name of template file

Returns:

  • (ERB)

    the ERB template or nil when file not found



394
395
396
397
398
399
400
401
402
403
# File 'lib/wcc.rb', line 394

def self.load_template(name)
	t_path = File.join(Conf[:template_dir], name)
	if File.exists?(t_path)
		WCC.logger.debug "Load template '#{name}'"
		t = File.open(t_path, 'r') { |f| f.read }
		# <> omit newline for lines starting with <% and ending in %>
		return ERB.new(t, 0, "<>")
	end
	nil
end

.run!Object



347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
# File 'lib/wcc.rb', line 347

def self.run!
	# make sure logger is correctly configured
	WCC.logger = Logger.new(STDOUT)
	# first use of Conf initializes it
	Conf.instance
	
	create_cache_dir
	clean_cache_dir if Conf[:clean]
	load_filters
	load_timestamps
	
	# stats
	@@stats = {
		'nruns' => 1,
		'nsites' => 0, 'nnotifications' => 0, 'nerrors' => 0,
		'nlines' => 0, 'nhunks' => 0
	}
	
	Conf.sites.each do |site|
		ts_old = get_timestamp(site)
		ts_new = Time.now.to_i
		if (ts_new-ts_old) < site.check_interval*60
			ts_diff = (ts_new-ts_old)/60
			WCC.logger.info "Skipping check for #{site.uri.host.to_s} due to check #{ts_diff} minute#{ts_diff == 1 ? '' : 's'} ago."
			next
		end
		case checkForUpdate(site)
		when :update
			WCC.logger.warn "#{site.uri.host.to_s} has an update!"
		when :noupdate
			WCC.logger.info "#{site.uri.host.to_s} is unchanged"
		when :error
			@@stats['nerrors'] += 1
		end
		update_timestamp(site, ts_new)
	end
	
	save_timestamps
	update_stats if Conf[:stats]
	shut_down_notificators
end

.save_template(name, raw_content) ⇒ Object

Attempts to write the given raw content to the named template file in template.d. This should be used to create initial template files on demand and will work only when file does not already exist.

Parameters:

  • name (String)

    file name of template file

  • raw_content (String)

    content that should be written to template file



411
412
413
414
415
416
417
418
419
# File 'lib/wcc.rb', line 411

def self.save_template(name, raw_content)
	t_path = File.join(Conf[:template_dir], name)
	if File.exists?(t_path)
		WCC.logger.warn "Trying to save template '#{name}' which already exists!"
		return
	end
	WCC.logger.info "Save template '#{name}' to #{t_path}"
	File.open(t_path, 'w') { |f| f.write(raw_content) }
end