incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [35/50] [abbrv] git commit: [5453] Moved loop through stats listeners
Date Tue, 05 Mar 2013 22:42:11 GMT
[5453] Moved loop through stats listeners


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/60152d4c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/60152d4c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/60152d4c

Branch: refs/heads/si/5453
Commit: 60152d4c9f66ace9cc923f8f108090855e0cd4a8
Parents: 5a72516
Author: Stefano Invernizzi <stefanoinve@apache.org>
Authored: Sat Jan 19 17:11:42 2013 +0100
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Tue Mar 5 21:39:30 2013 +0000

----------------------------------------------------------------------
 Allura/allura/eventslistener.py           |   36 ++++++++++++++++++++++++
 Allura/allura/lib/app_globals.py          |   19 +++++-------
 Allura/allura/lib/plugin.py               |    3 +-
 Allura/allura/model/artifact.py           |   10 ++----
 Allura/allura/model/auth.py               |    3 +-
 Allura/allura/model/repo_refresh.py       |    3 +-
 ForgeTracker/forgetracker/model/ticket.py |   12 +++----
 7 files changed, 56 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/60152d4c/Allura/allura/eventslistener.py
----------------------------------------------------------------------
diff --git a/Allura/allura/eventslistener.py b/Allura/allura/eventslistener.py
index 15adf00..f508013 100644
--- a/Allura/allura/eventslistener.py
+++ b/Allura/allura/eventslistener.py
@@ -24,4 +24,40 @@ class EventsListener:
     def ticketEvent(self, event_type, ticket, project, user):
         pass
 
+    def addUserToOrganization(self, newMembership):
+        pass
+
+'''This class simply allows to iterate through all the registered listeners,
+so that all of them are called to update statistics.'''
+class PostEvent:
+    def __init__(self, listeners):
+        self.listeners = listeners
+
+    def __iterate(self, event, *d):
+        for l in self.listeners:
+            getattr(l, event)(*d)
+
+    def newArtifact(self, art_type, art_datetime, project, user):
+        self.__iterate('newArtifact', art_type, art_datetime, project, user)
+
+    def modifiedArtifact(self, art_type, art_datetime, project, user):
+        self.__iterate('modifiedArtifact',art_type,art_datetime,project,user)
+
+    def newUser(self, user):
+        self.__iterate('newUser', user)
+
+    def newOrganization(self, organization):
+        self.__iterate('newOrganization', organization)
+
+    def addUserLogin(self, user):
+        self.__iterate('addUserLogin', user)
+
+    def newCommit(self, newcommit, project, user):
+        self.__iterate('newCommit', newcommit, project, user)
+
+    def ticketEvent(self, event_type, ticket, project, user):
+        self.__iterate('ticketEvent', event_type, ticket, project, user)
+
+    def addUserToOrganization(self, organization):
+        self.__iterate('addUserToOrganization', organization)
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/60152d4c/Allura/allura/lib/app_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/app_globals.py b/Allura/allura/lib/app_globals.py
index 1e9019c..71426a6 100644
--- a/Allura/allura/lib/app_globals.py
+++ b/Allura/allura/lib/app_globals.py
@@ -30,6 +30,7 @@ from ming.utils import LazyProperty
 import allura.tasks.event_tasks
 from allura import model as M
 from allura.lib.markdown_extensions import ForgeExtension
+from allura.eventslistener import PostEvent
 
 from allura.lib import gravatar, plugin, utils
 from allura.lib import helpers as h
@@ -165,23 +166,19 @@ class Globals(object):
             theme=_cache_eps('allura.theme'),
             user_prefs=_cache_eps('allura.user_prefs'),
             spam=_cache_eps('allura.spam'),
+            stats=_cache_eps('allura.stats'),
             )
 
         # Zarkov logger
         self._zarkov = None
 
-        self.show_userstats = False
+        self.show_userstats = config.get('user.stats.enable','false')=='true'
         # Set listeners to update stats
-        self.statslisteners = []
-        for ep in pkg_resources.iter_entry_points("allura.stats"):
-            if ep.name.lower() == 'userstats':
-                self.show_userstats = config.get(
-                    'user.stats.enable','false')=='true'
-                if self.show_userstats:
-                    self.statslisteners.append(ep.load()().listener)
-            else:
-                self.statslisteners.append(ep.load()().listener)
-
+        statslisteners = []
+        ep = self.entry_points['stats'].get('userstats')
+        if self.show_userstats and ep:
+            statslisteners.append(ep().listener)
+        self.statsUpdater = PostEvent(statslisteners)
 
     @LazyProperty
     def spam_checker(self):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/60152d4c/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index d71ccdd..dcbc36e 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -98,8 +98,7 @@ class AuthenticationProvider(object):
             self.session['userid'] = user._id
             self.session.save()
             g.zarkov_event('login', user=user)
-            for l in g.statslisteners:
-                l.addUserLogin(user)
+            g.statsUpdater.addUserLogin(user)
             return user
         except exc.HTTPUnauthorized:
             self.logout()

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/60152d4c/Allura/allura/model/artifact.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/artifact.py b/Allura/allura/model/artifact.py
index bce0720..6d6c162 100644
--- a/Allura/allura/model/artifact.py
+++ b/Allura/allura/model/artifact.py
@@ -375,13 +375,11 @@ class VersionedArtifact(Artifact):
                  self.version, self.__class__)
         if update_stats: 
             if self.version > 1:
-                for l in g.statslisteners:
-                    l.modifiedArtifact(
-                        self.type_s, self.mod_date, self.project, c.user)
+                g.statsUpdater.modifiedArtifact(
+                    self.type_s, self.mod_date, self.project, c.user)
             else :
-                for l in g.statslisteners:
-                    l.newArtifact(
-                        self.type_s, self.mod_date, self.project, c.user)
+                g.statsUpdater.newArtifact(
+                    self.type_s, self.mod_date, self.project, c.user)
         return ss
 
     def get_version(self, n):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/60152d4c/Allura/allura/model/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py
index cb9bdfb..9ed7067 100644
--- a/Allura/allura/model/auth.py
+++ b/Allura/allura/model/auth.py
@@ -593,8 +593,7 @@ class User(MappedClass, ActivityNode, ActivityObject):
         if user and 'display_name' in doc:
             user.set_pref('display_name', doc['display_name'])
         if user:
-            for l in g.statslisteners:
-                l.newUser(user)
+            g.statsUpdater.newUser(user)
         if user and make_project:
             n = M.Neighborhood.query.get(name='Users')
             n.register_project(auth_provider.user_project_shortname(user),

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/60152d4c/Allura/allura/model/repo_refresh.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repo_refresh.py b/Allura/allura/model/repo_refresh.py
index 1993f57..63e2bb0 100644
--- a/Allura/allura/model/repo_refresh.py
+++ b/Allura/allura/model/repo_refresh.py
@@ -117,8 +117,7 @@ def refresh_repo(repo, all_commits=False, notify=True):
         if user is None:
             user = User.by_username(new.committed.name)
         if user is not None:
-            for l in g.statslisteners:
-                l.newCommit(new, repo.app_config.project, user)
+            g.statsUpdater.newCommit(new, repo.app_config.project, user)
 
     log.info('Refresh complete for %s', repo.full_fs_path)
     g.post_event(

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/60152d4c/ForgeTracker/forgetracker/model/ticket.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/model/ticket.py b/ForgeTracker/forgetracker/model/ticket.py
index c2b15c7..c03662b 100644
--- a/ForgeTracker/forgetracker/model/ticket.py
+++ b/ForgeTracker/forgetracker/model/ticket.py
@@ -435,8 +435,7 @@ class Ticket(VersionedArtifact, ActivityObject, VotableArtifact):
                 ('Status', old.status, self.status) ]
             if old.status != self.status and self.status in c.app.globals.set_of_closed_status_names:
                 h.log_action(log, 'closed').info('')
-                for l in g.statslisteners:
-                    l.ticketEvent("closed", self, self.project, self.assigned_to)
+                g.statsUpdater.ticketEvent("closed", self, self.project, self.assigned_to)
             for key in self.custom_fields:
                 fields.append((key, old.custom_fields.get(key, ''), self.custom_fields[key]))
             for title, o, n in fields:
@@ -449,9 +448,9 @@ class Ticket(VersionedArtifact, ActivityObject, VotableArtifact):
                 changes.append('Owner updated: %r => %r' % (
                         o and o.username, n and n.username))
                 self.subscribe(user=n)
-                for l in g.statslisteners :
-                    l.ticketEvent("assigned", self, self.project, n)
-                    if o: l.ticketEvent("revoked", self, self.project, o)
+                g.statsUpdater.ticketEvent("assigned", self, self.project, n)
+                if o: 
+                    g.statsUpdater.ticketEvent("revoked", self, self.project, o)
             if old.description != self.description:
                 changes.append('Description updated:')
                 changes.append('\n'.join(
@@ -465,8 +464,7 @@ class Ticket(VersionedArtifact, ActivityObject, VotableArtifact):
             self.subscribe()
             if self.assigned_to_id:
                 user = User.query.get(_id=self.assigned_to_id)
-                for l in g.statslisteners :
-                    l.ticketEvent("assigned", self, self.project, user)
+                g.statsUpdater.ticketEvent("assigned", self, self.project, user)
                 self.subscribe(user=user)
             description = ''
             subject = self.email_subject


Mime
View raw message