changeset 1842:e8bada5aaae0

Merge main
author Johannes Berg <johannes AT sipsolutions DOT net>
date Tue, 27 Feb 2007 22:29:44 +0100
parents aed7438f264f (current diff) 7f4f997c7e6e (diff)
children b978764e1234
files
diffstat 4 files changed, 121 insertions(+), 94 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/Page.py	Tue Feb 27 22:28:39 2007 +0100
+++ b/MoinMoin/Page.py	Tue Feb 27 22:29:44 2007 +0100
@@ -34,7 +34,8 @@
         """
         self.name = name
         self.cache = {}
-        self.log_pos = None
+        self.log_pos = None # TODO: initialize this to EOF pos of log
+                            # to avoid reading in the whole log on first request
         self.requests = 0
         self.hits = 0
 
@@ -81,7 +82,8 @@
         """
         from MoinMoin.logfile import editlog
         elog = editlog.EditLog(request)
-        self.log_pos, items = elog.news(self.log_pos)
+        old_pos = self.log_pos
+        new_pos, items = elog.news(old_pos)
         if items:
             if self.name == 'meta':
                 for item in items:
@@ -93,6 +95,8 @@
             elif self.name == 'pagelists':
                 logging.debug("cache: clearing pagelist cache")
                 self.cache = {}
+        self.log_pos = new_pos # important to do this at the end -
+                               # avoids threading race conditions
 
 
 class Page:
--- a/MoinMoin/logfile/__init__.py	Tue Feb 27 22:28:39 2007 +0100
+++ b/MoinMoin/logfile/__init__.py	Tue Feb 27 22:29:44 2007 +0100
@@ -78,7 +78,7 @@
     Overwrite .parser() and .add() to customize this class to special log files
     """
 
-    def __init__(self, filename, buffer_size=65536):
+    def __init__(self, filename, buffer_size=4096):
         """
         @param filename: name of the log file
         @param buffer_size: approx. size of one buffer in bytes
--- a/MoinMoin/logfile/editlog.py	Tue Feb 27 22:28:39 2007 +0100
+++ b/MoinMoin/logfile/editlog.py	Tue Feb 27 22:29:44 2007 +0100
@@ -126,7 +126,7 @@
 
 class EditLog(LogFile):
 
-    def __init__(self, request, filename=None, buffer_size=65536, **kw):
+    def __init__(self, request, filename=None, buffer_size=4096, **kw):
         if filename is None:
             rootpagename = kw.get('rootpagename', None)
             if rootpagename:
--- a/MoinMoin/macro/SystemInfo.py	Tue Feb 27 22:28:39 2007 +0100
+++ b/MoinMoin/macro/SystemInfo.py	Tue Feb 27 22:29:44 2007 +0100
@@ -5,6 +5,7 @@
     This macro shows some info about your wiki, wiki software and your system.
 
     @copyright: 2006 MoinMoin:ThomasWaldmann
+                2007 ReimarBauer
     @license: GNU GPL, see COPYING for details.
 """
 
@@ -18,9 +19,14 @@
 from MoinMoin.logfile import editlog, eventlog
 from MoinMoin.Page import Page
 
-def execute(Macro, args):
-    """ show SystemInfo: wiki infos, wiki sw version, space usage infos """
-    def _formatInReadableUnits(size):
+class SystemInfo:
+    def __init__(self, macro, args):
+        self.macro = macro
+        self.request = macro.request
+        self.formatter = macro.formatter
+        self.args = args
+
+    def formatInReadableUnits(self, size):
         size = float(size)
         unit = u' Byte'
         if size > 9999:
@@ -34,7 +40,7 @@
             size /= 1024
         return u"%.1f %s" % (size, unit)
 
-    def _getDirectorySize(path):
+    def getDirectorySize(self, path):
         try:
             dirsize = 0
             for root, dummy, files in os.walk(path):
@@ -43,101 +49,118 @@
             dirsize = -1
         return dirsize
 
-    _ = Macro._
-    request = Macro.request
-
-    # check for 4XSLT
-    try:
-        import Ft
-        ftversion = Ft.__version__
-    except ImportError:
-        ftversion = None
-    except AttributeError:
-        ftversion = 'N/A'
-
-    t_count = None
-    try:
-        from threading import activeCount
-        t_count = activeCount()
-    except ImportError:
-        pass
-
-    # Get the full pagelist in the wiki
-    pagelist = request.rootpage.getPageList(user='')
-    totalsize = reduce(operator.add, [Page(request, name).size()
-                                      for name in pagelist])
-
-    buf = StringIO()
-    row = lambda label, value, buf=buf: buf.write(
-        u'<dt>%s</dt><dd>%s</dd>' % (label, value))
-
-    buf.write(u'<dl>')
-    row(_('Python Version'), sys.version)
-    row(_('MoinMoin Version'), _('Release %s [Revision %s]') % (version.release, version.revision))
-    if ftversion:
-        row(_('4Suite Version'), ftversion)
-
-    systemPages = [page for page in pagelist
-                   if wikiutil.isSystemPage(request, page)]
-    row(_('Number of pages'), str(len(pagelist)-len(systemPages)))
-    row(_('Number of system pages'), str(len(systemPages)))
+    def render(self):
+        _ = self.request.getText
+        return self.formatter.rawHTML(self.getInfo())
 
-    row(_('Accumulated page sizes'), _formatInReadableUnits(totalsize))
-    data_dir = request.cfg.data_dir
-    row(_('Disk usage of %(data_dir)s/pages/') % {'data_dir': data_dir},
-        _formatInReadableUnits(_getDirectorySize(os.path.join(data_dir, 'pages'))))
-    row(_('Disk usage of %(data_dir)s/') % {'data_dir': data_dir},
-        _formatInReadableUnits(_getDirectorySize(data_dir)))
-
-    edlog = editlog.EditLog(request)
-    row(_('Entries in edit log'), "%s (%s)" % (edlog.lines(), _formatInReadableUnits(edlog.size())))
-
-    # This puts a heavy load on the server when the log is large
-    eventlogger = eventlog.EventLog(request)
-    nonestr = _("NONE")
-    row('Event log', _formatInReadableUnits(eventlogger.size()))
-
-    row(_('Global extension macros'), ', '.join(macro.modules) or nonestr)
-    row(_('Local extension macros'),
-        ', '.join(wikiutil.wikiPlugins('macro', Macro.cfg)) or nonestr)
+    def getInfo(self):
+        _ = self.request.getText
+        request = self.request
 
-    glob_actions = [x for x in action.modules
-                    if not x in request.cfg.actions_excluded]
-    row(_('Global extension actions'), ', '.join(glob_actions) or nonestr)
-    loc_actions = [x for x in wikiutil.wikiPlugins('action', Macro.cfg)
-                   if not x in request.cfg.actions_excluded]
-    row(_('Local extension actions'), ', '.join(loc_actions) or nonestr)
+        try:
+            import Ft
+            ftversion = Ft.__version__
+        except ImportError:
+            ftversion = None
+        except AttributeError:
+            ftversion = 'N/A'
 
-    row(_('Global parsers'), ', '.join(parser.modules) or nonestr)
-    row(_('Local extension parsers'),
-        ', '.join(wikiutil.wikiPlugins('parser', Macro.cfg)) or nonestr)
+        t_count = None
+        try:
+            from threading import activeCount
+            t_count = activeCount()
+        except ImportError:
+            pass
 
-    from MoinMoin.search.builtin import Search
-    xapState = (_('Disabled'), _('Enabled'))
-    idxState = (_('index available'), _('index unavailable'))
-    xapRow = xapState[request.cfg.xapian_search]
+        # Get the full pagelist in the wiki
 
-    if request.cfg.xapian_search:
-        idx = Search._xapianIndex(request)
-        available = idx and idxState[0] or idxState[1]
-        mtime = _('last modified: %s') % (idx and
+        buf = StringIO()
+
+        row = lambda label, value, buf=buf: buf.write(u'<dt>%s</dt><dd>%s</dd>' % (label, value))
+
+        buf.write(u'<dl>')
+        row(_('Python Version'), sys.version)
+        row(_('MoinMoin Version'), _('Release %s [Revision %s]') % (version.release, version.revision))
+        if not request.user.valid:
+            # for an anonymous user it ends here.
+            buf.write(u'</dl>')
+            return buf.getvalue()
+
+        if request.user.isSuperUser():
+            # superuser gets all page dependent stuff only
+            if ftversion:
+                row(_('4Suite Version'), ftversion)
+
+            pagelist = request.rootpage.getPageList(user='')
+            systemPages = []
+            totalsize = 0
+            for page in pagelist:
+                if wikiutil.isSystemPage(request, page):
+                    systemPages.append(page)
+                totalsize += Page(request, page).size()
+
+            row(_('Number of pages'), str(len(pagelist)-len(systemPages)))
+            row(_('Number of system pages'), str(len(systemPages)))
+
+            row(_('Accumulated page sizes'), self.formatInReadableUnits(totalsize))
+            data_dir = request.cfg.data_dir
+            row(_('Disk usage of %(data_dir)s/pages/') % {'data_dir': data_dir},
+                self.formatInReadableUnits(self.getDirectorySize(os.path.join(data_dir, 'pages'))))
+            row(_('Disk usage of %(data_dir)s/') % {'data_dir': data_dir},
+            self.formatInReadableUnits(self.getDirectorySize(data_dir)))
+
+            edlog = editlog.EditLog(request)
+            row(_('Entries in edit log'), "%s (%s)" % (edlog.lines(), self.formatInReadableUnits(edlog.size())))
+
+        # This puts a heavy load on the server when the log is large
+            eventlogger = eventlog.EventLog(request)
+            nonestr = _("NONE")
+            row('Event log', self.formatInReadableUnits(eventlogger.size()))
+
+        # a valid user gets info about all installed extensions
+        row(_('Global extension macros'), ', '.join(macro.modules) or nonestr)
+        row(_('Local extension macros'),
+            ', '.join(wikiutil.wikiPlugins('macro', self.macro.cfg)) or nonestr)
+
+        glob_actions = [x for x in action.modules
+                        if not x in request.cfg.actions_excluded]
+        row(_('Global extension actions'), ', '.join(glob_actions) or nonestr)
+        loc_actions = [x for x in wikiutil.wikiPlugins('action', self.macro.cfg)
+                       if not x in request.cfg.actions_excluded]
+        row(_('Local extension actions'), ', '.join(loc_actions) or nonestr)
+
+        row(_('Global parsers'), ', '.join(parser.modules) or nonestr)
+        row(_('Local extension parsers'),
+            ', '.join(wikiutil.wikiPlugins('parser', self.macro.cfg)) or nonestr)
+
+        from MoinMoin.search.builtin import Search
+        xapState = (_('Disabled'), _('Enabled'))
+        idxState = (_('index available'), _('index unavailable'))
+        xapRow = xapState[request.cfg.xapian_search]
+
+        if request.cfg.xapian_search:
+            idx = Search._xapianIndex(request)
+            available = idx and idxState[0] or idxState[1]
+            mtime = _('last modified: %s') % (idx and
                 request.user.getFormattedDateTime(
                     wikiutil.version2timestamp(idx.mtime())) or
                     _('N/A'))
-        xapRow += ', %s, %s' % (available, mtime)
-
-    try:
-        import xapian
-        xapVersion = xapian.xapian_version_string()
-    except ImportError:
-        xapVersion = _('Xapian and/or Python Xapian bindings not installed')
+            xapRow += ', %s, %s' % (available, mtime)
 
-    row(_('Xapian search'), xapRow)
-    row(_('Xapian Version'), xapVersion)
-    row(_('Xapian stemming'), xapState[request.cfg.xapian_stemming])
+        try:
+            import xapian
+            xapVersion = xapian.xapian_version_string()
+        except ImportError:
+            xapVersion = _('Xapian and/or Python Xapian bindings not installed')
 
-    row(_('Active threads'), t_count or _('N/A'))
-    buf.write(u'</dl>')
+        row(_('Xapian search'), xapRow)
+        row(_('Xapian Version'), xapVersion)
+        row(_('Xapian stemming'), xapState[request.cfg.xapian_stemming])
 
-    return Macro.formatter.rawHTML(buf.getvalue())
+        row(_('Active threads'), t_count or _('N/A'))
+        buf.write(u'</dl>')
 
+        return buf.getvalue()
+
+def execute(macro, args):
+        return SystemInfo(macro, args).render()