allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject git commit: [#4832] Don't assume scm tools are installed
Date Tue, 29 Jan 2013 17:23:28 GMT
Updated Branches:
  refs/heads/tv/4832 b0077398a -> cf328622a


[#4832] Don't assume scm tools are installed


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

Branch: refs/heads/tv/4832
Commit: cf328622a9676d6b8ee6c077bb599ad47aac42ce
Parents: b007739
Author: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Authored: Tue Jan 29 17:23:12 2013 +0000
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Tue Jan 29 17:23:12 2013 +0000

----------------------------------------------------------------------
 Allura/allura/lib/custom_middleware.py |   48 ++++++++++++++-------------
 1 files changed, 25 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/cf328622/Allura/allura/lib/custom_middleware.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/custom_middleware.py b/Allura/allura/lib/custom_middleware.py
index 709e688..093af17 100644
--- a/Allura/allura/lib/custom_middleware.py
+++ b/Allura/allura/lib/custom_middleware.py
@@ -1,6 +1,7 @@
 import os
 import re
 import logging
+from contextlib import contextmanager
 
 import tg
 import pkg_resources
@@ -193,36 +194,37 @@ class AlluraTimerMiddleware(TimerMiddleware):
         return stat_record
 
     def scm_lib_timers(self):
-        import forgesvn
-        timers = [Timer('svn', forgesvn.model.svn.SVNLibWrapper, 'checkout', 'add',
-                    'checkin', 'info2', 'log', 'cat', 'list')]
-        try:
+        timers = []
+        with pass_on_exc(ImportError):
+            import forgesvn
+            timers.append(Timer('svn', forgesvn.model.svn.SVNLibWrapper, 'checkout', 'add',
+                        'checkin', 'info2', 'log', 'cat', 'list'))
+        with pass_on_exc(ImportError):
             import git
             timers.append(Timer('git', git.Repo, 'rev_parse', 'iter_commits', 'commit'))
-        except ImportError:
-            pass
-        try:
+        with pass_on_exc(ImportError):
             import mercurial
             timers.append(Timer('hg', mercurial.hg.localrepo.localrepository, 'heads',
                 'branchtags', 'tags'))
-        except ImportError:
-            pass
         return timers
 
     def repo_impl_timers(self):
-        from forgegit.model.git_repo import GitImplementation
-        from forgesvn.model.svn import SVNImplementation
-
-        repo_impl_timers = [
-            Timer('git_impl', GitImplementation, '*'),
-            Timer('svn_impl', SVNImplementation, '*'),
-        ]
-
-        try:
+        timers= []
+        with pass_on_exc(ImportError):
+            from forgegit.model.git_repo import GitImplementation
+            timers.append(Timer('git_impl', GitImplementation, '*'))
+        with pass_on_exc(ImportError):
+            from forgesvn.model.svn import SVNImplementation
+            timers.append(Timer('svn_impl', SVNImplementation, '*'))
+        with pass_on_exc(ImportError):
             from forgehg.model.hg import HgImplementation
-            repo_impl_timers.append(
-                    Timer('hg_impl', HgImplementation, '*'))
-        except ImportError:
-            pass
+            timers.append(Timer('hg_impl', HgImplementation, '*'))
+        return timers
+
 
-        return repo_impl_timers
+@contextmanager
+def pass_on_exc(exc):
+    try:
+        yield
+    except exc:
+        pass


Mime
View raw message