[Moin-devel] PATCH - underlaid directory for system pages

Fujio Nobori toh at fuji-climb.org
Fri Feb 20 03:32:04 EST 2004


Hello,

Thank you for providing this great software.  I really love
it.

I know developers are busy for the coming next release, so
this may not be the appropriate time for it, but here's a
small patch I wrote, against the cvs version of today
(release 1.2 revision 1.182).

This patch lets you use a immutable directory for pages,
such as system pages, which can be shared by different
instances of MoinMoin on a server.

When you use this feature, you put the system pages into one
directory, such as /var/htdocs/common, while the data/text
directory for instances can be completely empty.  If you go
to a FrontPage of an instance and there is no FrontPage in
the data/text directory in that instance, FrontPage in the
shared directory, /var/htdocs/common, is shown, as if it
were in the data/text directory of that instance.  It seems
like there is a shared directory laid under the directory of
an instance.

You can modify FrontPage, of cource,  and modified page is
saved in the data/text directory in that instance.  You can
add, modify, delete, or rename the files of the instance.

This way, all files in data/text directory are needed by
that specific instance.  Other files, such as system pages,
are in another directory, shared by other instances.

To use this feature,

 1. Put all the files in moin/share/moin/data/text into
 /var/htdocs/common directory.
 {{{
 cp /some_where_you_installed/moin/share/moin/data/text/* \
     /var/htdocs/common
 }}}

 1. Create an instance (/var/htdocs/MyMoin) in an usual way,
 but leave /var/htdocs/MyMoin/data/text empty.

 1. Set 'underlay_dir' in moin_config.py.
 {{{
 underlay_dir = '/var/htdocs/common'
 }}}

 1. Now go to your MyMoin site with your favorite browser!


I will appreciate any comment.

Thank you very muche for reading my terrrible Englissssssh.

Regards,

-- 
Fujio Nobori                                     il|li
    email: toh at fuji-climb.org                   q|@.@|p
                                              m. ( o ) .m
                                             ~~~~~~~~~~~~~
PGP-Key
    http://pgp.nic.ad.jp:11371/pks/lookup?op=get&search=0xC1BDBC10
    C3DA 7318 32F4 49F6 9D23  C686 3B83 231F C1BD BC10
-------------- next part --------------
diff -r -c MoinMoin/Page.py MoinMoin.toh/Page.py
*** MoinMoin/Page.py	Wed Feb 18 11:13:31 2004
--- MoinMoin.toh/Page.py	Fri Feb 20 19:04:37 2004
***************
*** 76,81 ****
--- 76,94 ----
  #            if os.path.getmtime(os.path.join(config.text_dir, wikiutil.quoteFilename(self.page_name))) != self.prev_date:
  #                os.errno = 2
  #                raise OSError
+         if config.underlay_dir:
+             quoted_name = wikiutil.quoteFilename(self.page_name)
+             filename_over  = os.path.join(config.text_dir, quoted_name)
+             if os.path.exists(filename_over):
+                 return filename_over
+ 
+             # check if the page exists in the underlay directory
+             filename_under = os.path.join(config.underlay_dir, quoted_name)
+             if os.path.exists(filename_under):
+                 return filename_under
+ 
+             # this must be the new page. return the normal file name
+ 
          return os.path.join(config.text_dir, wikiutil.quoteFilename(self.page_name))
  
  
***************
*** 170,175 ****
--- 183,206 ----
          return os.access(self._text_filename(), os.W_OK) or not self.exists()
  
  
+     def isUnderlayFile(self):
+         """
+         Is this page from underlay directory?
+         
+         @rtype: bool
+         @return: true, if page is from underlay directory
+         """
+         if not config.underlay_dir:
+             return 0
+ 
+         underlay_filename = os.path.join(config.underlay_dir,
+                                          wikiutil.quoteFilename(self.page_name))
+         if underlay_filename == self._text_filename():
+             return 1
+         else:
+             return 0
+ 
+         
      def exists(self):
          """
          Does this page exist?
diff -r -c MoinMoin/PageEditor.py MoinMoin.toh/PageEditor.py
*** MoinMoin/PageEditor.py	Wed Feb 18 11:13:31 2004
--- MoinMoin.toh/PageEditor.py	Fri Feb 20 16:36:06 2004
***************
*** 115,120 ****
--- 115,138 ----
          self.lock = PageLock(page_name, request)
  
  
+     def _text_filename_to_save(self):
+         """
+         The name of the page file to save, possibly of an older page.
+         
+         @rtype: string
+         @return: complete filename (including path) to save this page
+         """
+         # do i have to care about an older page???
+         if self.prev_date:
+             old_file = os.path.join(config.backup_dir, wikiutil.quoteFilename(self.page_name) + "." + self.prev_date)
+             if os.path.exists(old_file):
+                 return old_file
+ #            if os.path.getmtime(os.path.join(config.text_dir, wikiutil.quoteFilename(self.page_name))) != self.prev_date:
+ #                os.errno = 2
+ #                raise OSError
+         return os.path.join(config.text_dir, wikiutil.quoteFilename(self.page_name))
+ 
+ 
      def sendEditor(self, **kw):
          """
          Send the editor form page.
***************
*** 671,678 ****
              os.chmod(config.backup_dir, 0777 & config.umask)
  
          if os.path.isfile(page_filename) and not is_deprecated and self.do_revision_backup:
!             os.rename(page_filename, os.path.join(config.backup_dir,
!                 wikiutil.quoteFilename(self.page_name) + '.' + str(os.path.getmtime(page_filename))))
          else:
              if os.name == 'nt':
                  # Bad Bill!  POSIX rename ought to replace. :-(
--- 689,703 ----
              os.chmod(config.backup_dir, 0777 & config.umask)
  
          if os.path.isfile(page_filename) and not is_deprecated and self.do_revision_backup:
!             if config.underlay_dir:
!                 from distutils.file_util import copy_file
!                 copy_file(page_filename, os.path.join(config.backup_dir,
!                           wikiutil.quoteFilename
!                             (self.page_name) + '.'
!                             + str(os.path.getmtime(page_filename))))
!             else:
!                 os.rename(page_filename, os.path.join(config.backup_dir,
!                     wikiutil.quoteFilename(self.page_name) + '.' + str(os.path.getmtime(page_filename))))
          else:
              if os.name == 'nt':
                  # Bad Bill!  POSIX rename ought to replace. :-(
***************
*** 687,692 ****
--- 712,718 ----
  
          # replace old page by tmpfile
          os.chmod(tmp_filename, 0666 & config.umask)
+         page_filename = self._text_filename_to_save()
          os.rename(tmp_filename, page_filename)
          return os.path.getmtime(page_filename)
  
diff -r -c MoinMoin/action/DeletePage.py MoinMoin.toh/action/DeletePage.py
*** MoinMoin/action/DeletePage.py	Wed Feb 18 11:13:32 2004
--- MoinMoin.toh/action/DeletePage.py	Fri Feb 20 18:12:33 2004
***************
*** 26,31 ****
--- 26,35 ----
          return page.send_page(request,
              msg = _('You are not allowed to delete this page.'))
  
+     # check whether page is from underlay_dir
+     if page.isUnderlayFile():
+         return page.send_page(request,
+             msg = _('You can not delete this page because it is treated as a base.'))
  
      # check whether page exists at all
      if not page.exists():
diff -r -c MoinMoin/action/RenamePage.py MoinMoin.toh/action/RenamePage.py
*** MoinMoin/action/RenamePage.py	Wed Feb 18 11:13:32 2004
--- MoinMoin.toh/action/RenamePage.py	Fri Feb 20 18:15:18 2004
***************
*** 24,29 ****
--- 24,33 ----
          not request.user.may.edit(pagename) or not request.user.may.delete(pagename):
              msg = _('You are not allowed to rename pages in this wiki!')
  
+     # check whether page is from underlay_dir
+     elif page.isUnderlayFile():
+         msg = _('You can not rename this page because it is treated as a base.')
+ 
      # check whether page exists at all
      elif not page.exists():
          msg = _('This page is already deleted or was never created!')
diff -r -c MoinMoin/config.py MoinMoin.toh/config.py
*** MoinMoin/config.py	Thu Feb 19 19:37:49 2004
--- MoinMoin.toh/config.py	Fri Feb 20 12:24:37 2004
***************
*** 163,168 ****
--- 163,169 ----
      'url_mappings': {},
      'LogStore': 'text:editlog',
      'SecurityPolicy': None,
+     'underlay_dir': None,
  }
  
  smiley_defaults = {
diff -r -c MoinMoin/wikiutil.py MoinMoin.toh/wikiutil.py
*** MoinMoin/wikiutil.py	Wed Feb 18 11:13:31 2004
--- MoinMoin.toh/wikiutil.py	Fri Feb 20 17:18:01 2004
***************
*** 271,276 ****
--- 271,283 ----
      @return: all (unquoted) wiki page names
      """
      pages = os.listdir(text_dir)
+     if config.underlay_dir:
+         # add files only in underlay_dir
+         underlay_pages = os.listdir(config.underlay_dir)
+         for file in underlay_pages:
+             if not (file in pages):
+                 pages.append(file)
+ 
      result = []
      for file in pages:
          if file[0] in ['.', '#'] or file in ['CVS']: continue


More information about the Moin-devel mailing list