1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 18:41:03 +00:00

Plugin moinmoin_pages: migrate to python3

This commit is contained in:
Lars Kruse 2020-10-05 01:04:06 +02:00
parent 73817ba85c
commit 118040e32a

View file

@ -1,4 +1,4 @@
#! /usr/local/bin/python
#!/usr/bin/env python3
# Overview
# --------
@ -35,7 +35,10 @@
# (C) Copyleft 2007, The Anarcat <anarcat@koumbit.org>
# Licensed under the GPLv2 or any later version
import sys, operator, os
import operator
import os
from re import sub
import sys
os.chdir('/export/wiki/config')
sys.path.insert(0, '/export/wiki/config')
@ -43,33 +46,34 @@ sys.path.insert(0, '/export/wiki/config')
from MoinMoin import wikiutil
from MoinMoin.Page import Page
from farmconfig import wikis
from re import sub
import farmconfig
from MoinMoin.request import RequestCLI
def _formatInReadableUnits(size):
size = float(size)
unit = u' Byte'
if size > 9999:
unit = u' KiB'
size /= 1024
if size > 9999:
unit = u' MiB'
size /= 1024
if size > 9999:
unit = u' GiB'
size /= 1024
return u"%.1f %s" % (size, unit)
size = float(size)
unit = u' Byte'
if size > 9999:
unit = u' KiB'
size /= 1024
if size > 9999:
unit = u' MiB'
size /= 1024
if size > 9999:
unit = u' GiB'
size /= 1024
return u"%.1f %s" % (size, unit)
def _getDirectorySize(path):
try:
dirsize = 0
for root, dirs, files in os.walk(path):
dirsize += sum([os.path.getsize(os.path.join(root, name)) for name in files])
except EnvironmentError, e:
dirsize = -1
return dirsize
try:
dirsize = 0
for root, dirs, files in os.walk(path):
dirsize += sum([os.path.getsize(os.path.join(root, name)) for name in files])
except EnvironmentError:
dirsize = -1
return dirsize
def main():
for wiki in wikis:
@ -78,9 +82,9 @@ def main():
# XXX, hack: transform the regexp into a canonical url
# we need canonical urls in the config for this to be clean
# look for (foo|bar) and replace with foo
url = sub('\(([^\|]*)(\|[^\)]*\))+', '\\1', url)
url = sub(r'\(([^\|]*)(\|[^\)]*\))+', r'\1', url)
# remove common regexp patterns and slap a protocol to make this a real url
url = sub('[\^\$]|(\.\*)', '', url)
url = sub(r'[\^\$]|(\.\*)', '', url)
mod = getattr(__import__(name), 'Config')
#print "Upgradeing wiki %s (%s)" % (getattr(mod, 'sitename'), url)
@ -88,12 +92,12 @@ def main():
request = RequestCLI(url)
pagelist = request.rootpage.getPageList(user='')
systemPages = [page for page in pagelist
if wikiutil.isSystemPage(request, page)]
print(name + '.value ' + str(len(pagelist)-len(systemPages)))
systemPages = [page for page in pagelist if wikiutil.isSystemPage(request, page)]
print(name + '.value ' + str(len(pagelist) - len(systemPages)))
#totalsize = reduce(operator.add, [Page(request, name).size() for name in pagelist])
#print('Accumulated page sizes' + _formatInReadableUnits(totalsize))
def config():
print("""graph_title Wiki size
graph_vlabel Number of pages
@ -104,7 +108,8 @@ graph_info The number of pages excludes system pages but includes ACL-protected
for wiki in wikis:
name = wiki[0]
mod = getattr(__import__(name), 'Config')
print(name + '.label ' + getattr(mod, 'sitename'))
print(name + '.label ' + getattr(mod, 'sitename'))
if __name__ == "__main__":
if len(sys.argv) > 1 and sys.argv[1] == 'config':