This is an automated email from the ASF dual-hosted git repository. curcuru pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/whimsy.git
commit d84c2cfc46f8b16aac4f1cbbed62688239b5da6d Author: Shane Curcuru <[email protected]> AuthorDate: Mon May 6 09:21:35 2019 -0400 Add scanning for ASF::SVN use --- tools/wwwdocs.rb | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/tools/wwwdocs.rb b/tools/wwwdocs.rb index 238b4cc..09b5169 100755 --- a/tools/wwwdocs.rb +++ b/tools/wwwdocs.rb @@ -1,5 +1,7 @@ #!/usr/bin/env ruby -# Scan all /www scripts for WVisible PAGETITLE and categories +# Utility function to scan various scripts +# Docs: for WVisible PAGETITLE and categories in .cgi +# Repos: for ASF::SVN access in .cgi|rb $LOAD_PATH.unshift '/srv/whimsy/lib' require 'whimsy/asf' SCANDIR = "../www" @@ -12,6 +14,9 @@ AUTHMAP = { # From whimsy-vm4.apache.org.yaml 'ASF Secretarial Team' => 'text-danger' } AUTHPUBLIC = 'glyphicon-eye-open' +IS_PRIVATE = /\A(private|infra\/infrastructure)/ +ASFSVN = 'ASF::SVN' +SCANDIRSVN = "../" # Return [PAGETITLE, [cat,egories] ] after WVisible; or same as !Bogosity error def scan_file(f) @@ -75,3 +80,56 @@ def get_annotated_scan(dir) auth = get_auth() return annotate_scan(scan, auth) end + +# Read repository.yml for all :svn dirs names to scan for +# @return [['private1', 'privrepo2', ...], ['public1', 'pubrepo2', ...] +def read_repository() + svn = YAML.load_file('../repository.yml')[:svn] + repos = [[], []] + svn.each do |repo, data| + data['url'] =~ IS_PRIVATE ? repos[0] << repo : repos[1] << repo + end + return repos +end + +# Build a regex union from ASFSVN and an array +# @return Regexp.union(r...) +def build_regexp(list) + r = [] + list.each do |itm| + r << "#{ASFSVN}\['#{itm}']" + end + return Regexp.union(r) +end + +# Scan file for use of ASF::SVN (private or public) +# @return [["x = ASF::SVN['Meetings'] # Whole line private repo", ...], [] ] +def scan_file_svn(f, regexs) + repos = [[], []] + begin + File.open(f).each_line.map(&:chomp).each do |line| + if line =~ regexs[0] then + repos[0] << line + elsif line =~ regexs[1] then + repos[1] << line + end + end + return repos + rescue Exception => e + return [["#{ISERR}Bogosity! #{e.message[0..255]}", "\t#{e.backtrace.join("\n\t")}"],[]] + end +end + +# Scan directory for use of ASF::SVN (private or public) +# @return { file: [['private line'], []] } +def scan_dir_svn(dir, regexs) + links = {} + Dir["#{dir}/**/*.{cgi,rb}".untaint].each do |f| + l = scan_file_svn(f.untaint, regexs) + if (l[0].length + l[1].length) > 0 + links[f.sub(dir, '')] = l + end + end + return links +end +
