comparison MoinMoin/wikimacro.py @ 510:e1990b501b22

human readable SystemInfo, added disk usage imported from: moin--main--1.5--patch-514
author Thomas Waldmann <tw@waldmann-edv.de>
date Sun, 26 Mar 2006 18:52:11 +0000
parents c85132ab35e3
children b918cb0263bf
comparison
equal deleted inserted replaced
509:9f5ebd0b9be2 510:e1990b501b22
10 10
11 @copyright: 2000-2004 by Jürgen Hermann <jh@web.de> 11 @copyright: 2000-2004 by Jürgen Hermann <jh@web.de>
12 @license: GNU GPL, see COPYING for details. 12 @license: GNU GPL, see COPYING for details.
13 """ 13 """
14 14
15 import re, time 15 import re, time, os
16 from MoinMoin import action, config, macro, util 16 from MoinMoin import action, config, macro, util
17 from MoinMoin import wikiutil, wikiaction, i18n 17 from MoinMoin import wikiutil, wikiaction, i18n
18 from MoinMoin.Page import Page 18 from MoinMoin.Page import Page
19 from MoinMoin.util import pysupport 19 from MoinMoin.util import pysupport
20 20
345 buf.write('<dd><tt>%s</tt></dd>' % url) 345 buf.write('<dd><tt>%s</tt></dd>' % url)
346 buf.write('</dl>') 346 buf.write('</dl>')
347 347
348 return self.formatter.rawHTML(buf.getvalue()) 348 return self.formatter.rawHTML(buf.getvalue())
349 349
350
351 def _macro_SystemInfo(self, args): 350 def _macro_SystemInfo(self, args):
352 import operator, sys 351 import operator, sys
353 from StringIO import StringIO 352 from StringIO import StringIO
354 from MoinMoin import parser, processor, version 353 from MoinMoin import parser, processor, version
355 from MoinMoin.logfile import editlog, eventlog 354 from MoinMoin.logfile import editlog, eventlog
355 def _formatInReadableUnits(size):
356 size = float(size)
357 unit = u' Byte'
358 if size > 9999:
359 unit = u' KiB'
360 size /= 1024
361 if size > 9999:
362 unit = u' MiB'
363 size /= 1024
364 if size > 9999:
365 unit = u' GiB'
366 size /= 1024
367 return u"%.1f %s" % (size, unit)
368
369 def _getDirectorySize(path):
370 try:
371 dirsize = 0
372 for root, dirs, files in os.walk(path):
373 dirsize += sum(os.path.getsize(os.path.join(root, name)) for name in files)
374 except EnvironmentError, e:
375 dirsize = -1
376 return dirsize
377
356 _ = self._ 378 _ = self._
357 # check for 4XSLT 379 # check for 4XSLT
358 try: 380 try:
359 import Ft 381 import Ft
360 ftversion = Ft.__version__ 382 ftversion = Ft.__version__
382 buf.write(u'<dl>') 404 buf.write(u'<dl>')
383 row(_('Python Version'), sys.version) 405 row(_('Python Version'), sys.version)
384 row(_('MoinMoin Version'), _('Release %s [Revision %s]') % (version.release, version.revision)) 406 row(_('MoinMoin Version'), _('Release %s [Revision %s]') % (version.release, version.revision))
385 if ftversion: 407 if ftversion:
386 row(_('4Suite Version'), ftversion) 408 row(_('4Suite Version'), ftversion)
387 row(_('Number of pages'), str(len(pagelist)))
388 systemPages = [page for page in pagelist 409 systemPages = [page for page in pagelist
389 if wikiutil.isSystemPage(self.request, page)] 410 if wikiutil.isSystemPage(self.request, page)]
411 row(_('Number of pages'), str(len(pagelist)-len(systemPages)))
390 row(_('Number of system pages'), str(len(systemPages))) 412 row(_('Number of system pages'), str(len(systemPages)))
391 row(_('Accumulated page sizes'), str(totalsize)) 413 row(_('Accumulated page sizes'), _formatInReadableUnits(totalsize))
414 data_dir = self.request.cfg.data_dir
415 row(_('Disk usage of %(data_dir)s/pages/') % {'data_dir': data_dir},
416 _formatInReadableUnits(_getDirectorySize(os.path.join(data_dir, 'pages'))))
417 row(_('Disk usage of %(data_dir)s/') % {'data_dir': data_dir},
418 _formatInReadableUnits(_getDirectorySize(data_dir)))
392 419
393 edlog = editlog.EditLog(self.request) 420 edlog = editlog.EditLog(self.request)
394 row(_('Entries in edit log'), 421 row(_('Entries in edit log'), "%s (%s)" % (edlog.lines(), _formatInReadableUnits(edlog.size())))
395 _("%(logcount)s (%(logsize)s bytes)") %
396 {'logcount': edlog.lines(), 'logsize': edlog.size()})
397 422
398 # This puts a heavy load on the server when the log is large 423 # This puts a heavy load on the server when the log is large
399 eventlogger = eventlog.EventLog(self.request) 424 eventlogger = eventlog.EventLog(self.request)
400 nonestr = _("NONE") 425 nonestr = _("NONE")
401 row('Event log', "%s bytes" % eventlogger.size()) 426 row('Event log', _formatInReadableUnits(eventlogger.size()))
402 row(_('Global extension macros'), ', '.join(macro.extension_macros) or nonestr) 427 row(_('Global extension macros'), ', '.join(macro.extension_macros) or nonestr)
403 row(_('Local extension macros'), 428 row(_('Local extension macros'),
404 ', '.join(wikiutil.wikiPlugins('macro', self.cfg)) or nonestr) 429 ', '.join(wikiutil.wikiPlugins('macro', self.cfg)) or nonestr)
405 ext_actions = [x for x in action.extension_actions 430 ext_actions = [x for x in action.extension_actions
406 if not x in self.request.cfg.actions_excluded] 431 if not x in self.request.cfg.actions_excluded]