module SiteStandards

Encapsulate (most) scans/validations done on website content

Constants

CHECK_CAPTURE
CHECK_DOC
CHECK_POLICY
CHECK_TEXT
CHECK_TYPE
CHECK_VALIDATE
COMMON_CHECKS

Checks done for all podlings|projects

PODLING_CHECKS

Checks done only for Incubator podlings

SITE_FAIL
SITE_PASS
SITE_WARN
TLP_CHECKS

Checks done only for TLPs (i.e. not podlings)

Public Instance Methods

analyze(sites, checks) click to toggle source

Analyze data returned from site-scan.rb by using checks regex

If value =~ CHECK_VALIDATE, SITE_PASS
If value is present (presumably from CHECK_TEXT|CAPTURE), then SITE_WARN
If value not present, SITE_FAIL (i.e. site-scan.rb didn't find it)

@param sites hash of site-scan data collected @param checks to apply to sites to determine status @return [overall counts, description of statuses, success listings]

# File lib/whimsy/sitestandards.rb, line 183
def analyze(sites, checks)
    success = Hash.new { |h, k| h[k] = Hash.new(&h.default_proc) }
    counts = Hash.new { |h, k| h[k] = Hash.new(&h.default_proc) }
    checks.each do |nam, check_data|
      success[nam] = sites.select{ |k, site| site[nam] =~ check_data[SiteStandards::CHECK_VALIDATE]  }.keys
      counts[nam][SITE_PASS] = success[nam].count
      counts[nam][SITE_WARN] = 0 # Reorder output 
      counts[nam][SITE_FAIL] = sites.select{ |k, site| site[nam].nil? }.count
      counts[nam][SITE_WARN] = sites.size - counts[nam][SITE_PASS] - counts[nam][SITE_FAIL]
    end
    
    return [
      counts, {
      SITE_PASS => '# Sites with links to primary ASF page',
      SITE_WARN => '# Sites with link, but not an expected ASF one',
      SITE_FAIL => '# Sites with no link for this topic'
      }, success
    ]
end
get_checks(tlp = true) click to toggle source

Get hash of checks to be done for tlp | podling @param tlp true if project; podling otherwise

# File lib/whimsy/sitestandards.rb, line 144
def get_checks(tlp = true)
  tlp ? (return TLP_CHECKS.merge(COMMON_CHECKS)) : (return PODLING_CHECKS.merge(COMMON_CHECKS))
end
get_filename(tlp = true) click to toggle source

Get filename of check data for tlp | podling @param tlp true if project; podling otherwise

# File lib/whimsy/sitestandards.rb, line 150
def get_filename(tlp = true)
  tlp ? (return 'site-scan.json') : (return 'pods-scan.json')
end
get_sites(tlp = true) click to toggle source

Get check data for tlp | podling

Uses a local_copy if available; w.a.o/public otherwise

@param tlp true if project; podling otherwise @return [hash of site data, crawl_time]

# File lib/whimsy/sitestandards.rb, line 163
def get_sites(tlp = true)
    local_copy = File.expand_path("#{get_url(true)}#{get_filename(tlp)}", __FILE__).untaint
    if File.exist? local_copy
      crawl_time = File.mtime(local_copy).httpdate # show time in same format as last-mod
      sites = JSON.parse(File.read(local_copy))
    else
      response = Net::HTTP.get_response(URI("#{get_url(false)}#{get_filename(tlp)}"))
      crawl_time = response['last-modified']
      sites = JSON.parse(response.body)
    end
  return sites, crawl_time
end
get_url(is_local = true) click to toggle source

Get URL to default filename location on server

# File lib/whimsy/sitestandards.rb, line 155
def get_url(is_local = true)
  is_local ? (return '../../../www/public/') : (return 'https://whimsy.apache.org/public/')
end
label(analysis, links, col, name) click to toggle source

Determine the color of a given table cell, given:

- overall analysis of the sites, in particular the third column
  which is a list projects that successfully matched the check
- list of links for the project in question
- the column in question (which indicates the check being reported on)
- the name of the project
# File lib/whimsy/sitestandards.rb, line 132
def label(analysis, links, col, name)
  if not links[col]
    SITE_FAIL
  elsif analysis[2].include? col and not analysis[2][col].include? name
    SITE_WARN
  else
    SITE_PASS
  end
end