root / plugins / moinmoin / moinmoin_pages @ 26e497fc
Historique | Voir | Annoter | Télécharger (3,39 ko)
| 1 | 118040e3 | Lars Kruse | #!/usr/bin/env python3 |
|---|---|---|---|
| 2 | 39d48eb0 | Antoine Beaupr? | |
| 3 | d369b316 | Lars Kruse | """ |
| 4 | |||
| 5 | =head1 NAME |
||
| 6 | |||
| 7 | 26e497fc | Lars Kruse | moinmoin_pages - lists the number of pages in all wikis of a MoinMoin wikifarm |
| 8 | |||
| 9 | |||
| 10 | ACL-protected pages are included. |
||
| 11 | d369b316 | Lars Kruse | |
| 12 | |||
| 13 | =head1 CONFIGURATION |
||
| 14 | |||
| 15 | [moinmoin_*] |
||
| 16 | user www |
||
| 17 | |||
| 18 | |||
| 19 | =head1 IMPLEMENTATION NOTES |
||
| 20 | |||
| 21 | The plugin is quite koumbit-specific: |
||
| 22 | |||
| 23 | =over 4 |
||
| 24 | |||
| 25 | =item 1. the wikifarm config is hardcoded |
||
| 26 | |||
| 27 | =item 2. "wikilist.py" is assumed to contain the list of wiki -> url patterns |
||
| 28 | |||
| 29 | =item 3. url patterns are assumed to be simple enough, that they are decodable into an url |
||
| 30 | |||
| 31 | =back |
||
| 32 | |||
| 33 | Also note that this plugin reuses code from MoinMoin/wikimacro.py's SystemInfo macro. |
||
| 34 | |||
| 35 | Finally, i tried using XMLRPC instead of native functions to fetch the data, but it ended up being |
||
| 36 | slower. For the record, here is what the getPageList() call would have looked like: |
||
| 37 | |||
| 38 | xmlrpclib.ServerProxy("http://wiki.koumbit.net/?action=xmlrpc2").getAllPages()
|
||
| 39 | |||
| 40 | The quick benchmark I did yielded those results for the getAllPages() vs getPageList() calls: |
||
| 41 | |||
| 42 | xmlrpc: 2.35 real 0.12 user 0.04 sys |
||
| 43 | native: 1.44 real 1.07 user 0.35 sys |
||
| 44 | |||
| 45 | So the plugin is spending more time in the CPU (all time, actually), but it's doing in faster. |
||
| 46 | It is highly possible that the CPU time spared in XMLRPC is in fact used by the server. |
||
| 47 | |||
| 48 | |||
| 49 | =head1 AUTHORS |
||
| 50 | |||
| 51 | Copyleft 2007, The Anarcat <anarcat@koumbit.org> |
||
| 52 | |||
| 53 | |||
| 54 | =head1 LICENSE |
||
| 55 | |||
| 56 | Licensed under the GPLv2 or any later version. |
||
| 57 | |||
| 58 | SPDX-License-Identifier: GPL-2.0-or-later |
||
| 59 | |||
| 60 | =cut |
||
| 61 | """ |
||
| 62 | 39d48eb0 | Antoine Beaupr? | |
| 63 | 118040e3 | Lars Kruse | import os |
| 64 | from re import sub |
||
| 65 | import sys |
||
| 66 | 39d48eb0 | Antoine Beaupr? | |
| 67 | 26e497fc | Lars Kruse | from MoinMoin import wikiutil |
| 68 | from MoinMoin.request import RequestCLI |
||
| 69 | |||
| 70 | 39d48eb0 | Antoine Beaupr? | os.chdir('/export/wiki/config')
|
| 71 | sys.path.insert(0, '/export/wiki/config') |
||
| 72 | |||
| 73 | 26e497fc | Lars Kruse | from farmconfig import wikis # noqa: E402 |
| 74 | 39d48eb0 | Antoine Beaupr? | |
| 75 | 118040e3 | Lars Kruse | |
| 76 | 39d48eb0 | Antoine Beaupr? | def _formatInReadableUnits(size): |
| 77 | 118040e3 | Lars Kruse | size = float(size) |
| 78 | unit = u' Byte' |
||
| 79 | if size > 9999: |
||
| 80 | unit = u' KiB' |
||
| 81 | size /= 1024 |
||
| 82 | if size > 9999: |
||
| 83 | unit = u' MiB' |
||
| 84 | size /= 1024 |
||
| 85 | if size > 9999: |
||
| 86 | unit = u' GiB' |
||
| 87 | size /= 1024 |
||
| 88 | return u"%.1f %s" % (size, unit) |
||
| 89 | |||
| 90 | 39d48eb0 | Antoine Beaupr? | |
| 91 | def _getDirectorySize(path): |
||
| 92 | 118040e3 | Lars Kruse | try: |
| 93 | dirsize = 0 |
||
| 94 | for root, dirs, files in os.walk(path): |
||
| 95 | dirsize += sum([os.path.getsize(os.path.join(root, name)) for name in files]) |
||
| 96 | except EnvironmentError: |
||
| 97 | dirsize = -1 |
||
| 98 | return dirsize |
||
| 99 | |||
| 100 | 39d48eb0 | Antoine Beaupr? | |
| 101 | def main(): |
||
| 102 | for wiki in wikis: |
||
| 103 | name = wiki[0] |
||
| 104 | url = wiki[1] |
||
| 105 | # XXX, hack: transform the regexp into a canonical url |
||
| 106 | # we need canonical urls in the config for this to be clean |
||
| 107 | # look for (foo|bar) and replace with foo |
||
| 108 | 118040e3 | Lars Kruse | url = sub(r'\(([^\|]*)(\|[^\)]*\))+', r'\1', url) |
| 109 | 39d48eb0 | Antoine Beaupr? | # remove common regexp patterns and slap a protocol to make this a real url |
| 110 | 118040e3 | Lars Kruse | url = sub(r'[\^\$]|(\.\*)', '', url) |
| 111 | 17f78427 | Lars Kruse | |
| 112 | 39d48eb0 | Antoine Beaupr? | request = RequestCLI(url) |
| 113 | pagelist = request.rootpage.getPageList(user='') |
||
| 114 | 17f78427 | Lars Kruse | |
| 115 | 118040e3 | Lars Kruse | systemPages = [page for page in pagelist if wikiutil.isSystemPage(request, page)] |
| 116 | print(name + '.value ' + str(len(pagelist) - len(systemPages))) |
||
| 117 | 39d48eb0 | Antoine Beaupr? | |
| 118 | 118040e3 | Lars Kruse | |
| 119 | 39d48eb0 | Antoine Beaupr? | def config(): |
| 120 | print("""graph_title Wiki size
|
||
| 121 | graph_vlabel Number of pages |
||
| 122 | graph_args --base 1000 -l 0 |
||
| 123 | graph_scale no |
||
| 124 | 33e95e6f | Lars Kruse | graph_category wiki |
| 125 | 39d48eb0 | Antoine Beaupr? | graph_info The number of pages excludes system pages but includes ACL-protected pages.""") |
| 126 | for wiki in wikis: |
||
| 127 | name = wiki[0] |
||
| 128 | mod = getattr(__import__(name), 'Config') |
||
| 129 | 118040e3 | Lars Kruse | print(name + '.label ' + getattr(mod, 'sitename')) |
| 130 | |||
| 131 | 39d48eb0 | Antoine Beaupr? | |
| 132 | if __name__ == "__main__": |
||
| 133 | if len(sys.argv) > 1 and sys.argv[1] == 'config': |
||
| 134 | config() |
||
| 135 | else: |
||
| 136 | main() |
