Attachment 'MoonEdit.py'

Download

   1 from MoinMoin.PageEditor import PageEditor
   2 from MoinMoin import config
   3 import shutil, os, codecs
   4 
   5 moon_dir = "/home/festifn/moonedit/test"
   6 moon_pw = ""
   7 
   8 
   9 # check the os.chmod() lines!!!!
  10 
  11 def execute(page_name, request):
  12     #moon_dir = request.cfg.moon_dir
  13     #moon_pw = request.cfg.moon_pw
  14 
  15     _ = request.getText
  16     p = PageEditor(request, page_name)
  17     msg = ""
  18 
  19     if not moon_dir:
  20         msg = _("MoonEdit not configured")
  21 
  22     # Locking doesn't work with 1.3 locking code!
  23     #else:
  24     #    # try to acquire edit lock
  25     #    p.lock.locktype = "lock"
  26     #    p.lock.timeout = 3600 # one hour
  27     #    
  28     #    ok, edit_lock_message = p.lock.aquire()
  29     #    if not ok:
  30     #        # failed to get the lock
  31     #        if preview is not None:
  32     #            edit_lock_message = _('The lock you held timed out, be prepared for editing conflicts!'
  33     #                                 ) + "<br>" + edit_lock_message
  34     #       else:
  35     #           msg = edit_lock_message
  36 
  37     # Did one of the prechecks fail?
  38     if msg:
  39         p.send_page(request, msg=msg)
  40         return
  41 
  42 
  43     moon_file = os.path.join(moon_dir, p.page_name_fs)
  44 
  45     # check if already in MoonEdit
  46     if os.path.exists(moon_file + ".me"):
  47         if os.path.exists(moon_file):
  48             content = codecs.open(moon_file, 'rb', config.charset).read()
  49             
  50             try:
  51                 # make page file writable again
  52                 # XXXX EVIL!!!!
  53                 os.chmod(p._text_filename(), 0660)
  54                 
  55                 savemsg = p.saveText(content, 0)
  56                 os.remove(moon_file)
  57                 os.remove(moon_file + ".me")
  58                 os.remove(moon_file + ".pw")
  59             except p.SaveError, msg:
  60                 # msg contain a unicode string
  61                 savemsg = unicode(msg)
  62 
  63         else:
  64             savemsg = _("Already in MoonEdit but not yet saved")
  65 
  66         # Send page
  67         request.reset()
  68         p.send_page(request, msg=savemsg)
  69 
  70     else: # put page into MoonEdit
  71         
  72         #check edit permissions
  73         msg = ""
  74         if not request.user.may.write(page_name):
  75             msg = _('You are not allowed to edit this page.')
  76         elif not p.isWritable():
  77             msg = _('Page is immutable!')
  78         if msg:
  79             p.send_page(request, msg=msg)
  80             return
  81 
  82         # copy content
  83         shutil.copyfile(p._text_filename(), moon_file + ".me")
  84         # write protect the page file
  85         # XXXX EVIL!!!!
  86         os.chmod(p._text_filename(), 0440)
  87     
  88         # make pw file
  89         pw = open(moon_file + ".pw", "w")
  90         pw.write(moon_pw + "\n")
  91         pw.close()
  92         msg = _("Page made available in MoonEdit and locked for normal editing")
  93         p.send_page(request, msg=msg)
  94 
  95     
  96     

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] (2005-03-06 20:41:32, 2.7 KB) [[attachment:MoonEdit.py]]
 All files | Selected Files: delete move to page copy to page

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