Attachment 'PageCompare.py'

Download

   1 """
   2     MoinMoin - Macro to compare pages, e.g. to find out, if a page with a
   3     german translation is still "in sync" with the english original page.
   4 
   5     If you generate some sort of "derived work" of a page, go to page info
   6     of the original page and copy & paste the PageCompare macro shown there
   7     to your derived page.
   8     
   9     Usage:
  10         [[PageCompare(masterpagename,masterdate,mastersha)]]
  11 
  12         masterpagename	name of the master (original) page
  13 	masterdate	original date of master page (only for information)
  14 	mastersha	original SHA digest of master page
  15 
  16     Examples:
  17 	[[PageCompare(HelpIndex,2002-02-02 13:45:00,5AE4EF821719D7AD65E3D258178E851CA9B39320)]]
  18         This will compare the given mastersha with the current sha of the
  19 	masterpage. If they are the same, everything is still in sync and you
  20 	get an appropriate message. If not, you will be informed, that the
  21 	masterpage has changed and therefore the current page is not in sync any
  22 	more (e.g. because it was a translation of the older masterpage).
  23 	
  24     Copyright (c) 2002 by Thomas Waldmann <tw@waldmann-edv.de>
  25     All rights reserved, see COPYING for details.
  26 
  27 """
  28 
  29 import string, re
  30 # import sys, cStringIO
  31 # from MoinMoin import user
  32 from MoinMoin.Page import Page
  33 from MoinMoin.i18n import _
  34 
  35 _args_re_pattern = r'(?P<masterpage>[^,]*),(?P<masterdate>[^,]*),(?P<mastersha>.*)'
  36 
  37 def execute(macro, text, args_re=re.compile(_args_re_pattern)):
  38 
  39     # parse and check arguments
  40     args = args_re.match(text)
  41     if not args:
  42         return ('<p><strong class="error">%s</strong></p>' % _('Invalid MasterPage arguments "%s"!')) % (text,)
  43 
  44     masterpagename = args.group('masterpage')
  45     origmasterdate = args.group('masterdate')
  46     origmasterdigest = args.group('mastersha')
  47 
  48 #    this_page = macro.formatter.page
  49 
  50     masterpage = Page(masterpagename)
  51     import sha
  52     masterdigest=string.upper(sha.new(masterpage.get_raw_body()).hexdigest())
  53     if masterdigest != origmasterdigest:
  54         ret = '<p><b>This page is not in sync with %s, last update was at %s.</b></p>' \
  55 	      % (macro.formatter.pagelink(masterpagename),origmasterdate)
  56     else:
  57         ret = '<p>This page is in sync with its original at %s.</p>' % macro.formatter.pagelink(masterpagename)
  58     return ret
  59     

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2003-12-07 18:15:53, 2.2 KB) [[attachment:PageCompare.py]]
  • [get | view] (2008-05-05 11:26:10, 175.4 KB) [[attachment:UserHomePagesFailure.jpg]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.