You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by se...@apache.org on 2017/06/22 09:53:24 UTC

[whimsy] branch master updated: Convert remaining code to use mlist utility module

This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git


The following commit(s) were added to refs/heads/master by this push:
     new cb9fefd  Convert remaining code to use mlist utility module
cb9fefd is described below

commit cb9fefd27e5224a2b44241ce9c3b0a6871586308
Author: Sebb <se...@apache.org>
AuthorDate: Thu Jun 22 10:52:41 2017 +0100

    Convert remaining code to use mlist utility module
---
 lib/whimsy/asf/mlist.rb        | 37 +++++++++++++++++++++++++++++++++++--
 www/roster/main.rb             |  2 --
 www/roster/models/committee.rb | 17 ++---------------
 www/roster/models/ppmc.rb      | 16 ++--------------
 4 files changed, 39 insertions(+), 33 deletions(-)

diff --git a/lib/whimsy/asf/mlist.rb b/lib/whimsy/asf/mlist.rb
index b5c3e7c..7579ba9 100644
--- a/lib/whimsy/asf/mlist.rb
+++ b/lib/whimsy/asf/mlist.rb
@@ -80,8 +80,38 @@ module ASF
       end
       response
     end
-    # roster/models/committee: for a mail domain, extract lists and their moderators
-    # roster/models/committer:
+
+    def self.list_moderators(mail_domain, podling=false)
+      # for a mail domain, extract related lists and their moderators
+      # also returns the time when the data was last checked
+      # If podling==true, then also check for old-style podling names
+
+      return nil, nil unless File.exist? LIST_MODS
+
+      moderators = File.read(LIST_MODS).split(/\n\n/).map do |stanza|
+        # list names can include '-': empire-db
+        m = stanza.match(/\/(?'domain'[-\w]+)\.apache\.org\/(?'sublist'.*?)\//)
+        # normal tlp style:
+        #/home/apmail/lists/commons.apache.org/dev/mod
+        # possible podling styles (new, old):
+        #/home/apmail/lists/batchee.apache.org/dev/mod
+        #/home/apmail/lists/incubator.apache.org/blur-dev/mod
+        next unless m # did not parse
+        # drop infra test lists
+        next if m['sublist'] =~ /^infra-[a-z]$/
+        next if m['domain'] == 'incubator.apache.org' && m['sublist'] =~ /^infra-dev2?$/
+        # if podling, also check for old-style names
+        # we need to check for incubator domain to avoid spurious matches, e.g. with
+        # /home/apmail/lists/db.apache.org/commons-dev/mod
+
+        next unless m['domain'] == mail_domain or
+            (podling && m['domain'] == 'incubator' && m['sublist'] =~ /^#{mail_domain}-/)
+ 
+        ["#{m['sublist']}@#{m['domain']}.apache.org", stanza.scan(/^(.*@.*)/).flatten.sort]
+      end
+      return moderators.compact.to_h, File.mtime(LIST_MODS)
+    end
+
     private
 
     MEMBERS_SUBSCRIPTIONS = '/srv/subscriptions/members'
@@ -94,3 +124,6 @@ module ASF
 
   end
 end
+#if __FILE__ == $0
+#p  ASF::MLIST.list_moderators(ARGV.shift||'blur', true)
+#end
diff --git a/www/roster/main.rb b/www/roster/main.rb
index 753a12c..11ce200 100755
--- a/www/roster/main.rb
+++ b/www/roster/main.rb
@@ -23,8 +23,6 @@ require_relative 'models'
 
 ASF::Mail.configure
 
-LIST_MODS = '/srv/subscriptions/list-mods'
-
 get '/' do
   if env['REQUEST_URI'].end_with? '/'
     @committers = ASF::Person.list
diff --git a/www/roster/models/committee.rb b/www/roster/models/committee.rb
index f78c55b..7e46e4d 100644
--- a/www/roster/models/committee.rb
+++ b/www/roster/models/committee.rb
@@ -23,21 +23,8 @@ class Committee
     moderators = nil
 
     if pmc.roster.include? env.user or ASF::Person.find(env.user).asf_member?
-      if File.exist? LIST_MODS
-         modtime = File.mtime(LIST_MODS)
-         mail_list = "#{pmc.mail_list}.apache.org"
-         moderators = File.read(LIST_MODS).split(/\n\n/).map do |stanza|
-           # list names can include '-': empire-db
-           list = stanza.match(/\/([-\w]+\.apache\.org)\/(.*?)\//)
-           next unless list and list[1] == mail_list
-           # Drop the infra test lists
-           next if list[2] =~ /^infra-[a-z]$/
-           next if list[1] == 'incubator.apache.org' && list[2] =~ /^infra-dev2?$/
- 
-           ["#{list[2]}@#{list[1]}", stanza.scan(/^(.*@.*)/).flatten.sort]
-        end
-        moderators = moderators.compact.to_h
-      end
+      require 'whimsy/asf/mlist'
+      moderators, modtime = ASF::MLIST.list_moderators(pmc.mail_list)
     else
       lists = lists.select {|list, mode| mode == 'public'}
     end
diff --git a/www/roster/models/ppmc.rb b/www/roster/models/ppmc.rb
index 380018a..439b99a 100644
--- a/www/roster/models/ppmc.rb
+++ b/www/roster/models/ppmc.rb
@@ -10,20 +10,8 @@ class PPMC
 
     user = ASF::Person.find(env.user)
     if user.asf_member? or ppmc.members.include? user
-      if File.exist? LIST_MODS
-         modtime = File.mtime(LIST_MODS)
-         mail_list = ppmc.mail_list
-         moderators = File.read(LIST_MODS).split(/\n\n/).map do |stanza|
-           # list names can include '-': empire-db
-           list = stanza.match(/\/([-\w]+)\.apache\.org\/(.*?)\//)
-           next unless list and 
-             (list[1] == mail_list or list[2] =~ /^#{mail_list}-/)
- 
-           ["#{list[2]}@#{list[1]}.apache.org", 
-             stanza.scan(/^(.*@.*)/).flatten.sort]
-        end
-        moderators = moderators.compact.to_h
-      end
+      require 'whimsy/asf/mlist'
+      moderators, modtime = ASF::MLIST.list_moderators(ppmc.mail_list, true)
     else
       lists = lists.select {|list, mode| mode == 'public'}
     end

-- 
To stop receiving notification emails like this one, please contact
['"commits@whimsical.apache.org" <co...@whimsical.apache.org>'].