Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes
MoinMoin.script.maint.globaledit.PluginScript Class Reference
Inheritance diagram for MoinMoin.script.maint.globaledit.PluginScript:
Inheritance graph
[legend]
Collaboration diagram for MoinMoin.script.maint.globaledit.PluginScript:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def do_edit
def mainloop
def init_request
def run
def logRuntime

Public Attributes

 request
 argv
 def_values
 parser
 args

Detailed Description

\
Purpose:
========
This tool allows you to edit all the pages in a wiki.

Detailed Instructions:
======================
General syntax: moin [options] maint globaledit [globaledit-options]

[options] usually should be:
--config-dir=/path/to/my/cfg/ --wiki-url=wiki.example.org/

[globaledit-options] see below:
0. The changes that will be performed are hardcoded in the function
   do_edit.

1. This script takes no command line arguments.

Definition at line 14 of file globaledit.py.


Constructor & Destructor Documentation

def MoinMoin.script.maint.globaledit.PluginScript.__init__ (   self,
  argv,
  def_values 
)

Reimplemented from MoinMoin.script.MoinScript.

Definition at line 34 of file globaledit.py.

00034 
00035     def __init__(self, argv, def_values):
00036         MoinScript.__init__(self, argv, def_values)


Member Function Documentation

def MoinMoin.script.maint.globaledit.PluginScript.do_edit (   self,
  pagename,
  origtext 
)

Definition at line 37 of file globaledit.py.

00037 
00038     def do_edit(self, pagename, origtext):
00039         if pagename in ['LocalSpellingWords', 'LocalBadContent', ]:
00040             return origtext
00041         language_line = format_line = masterpage = None
00042         acl_lines = []
00043         master_lines = []
00044         pragma_lines = []
00045         comment_lines = []
00046         content_lines = []
00047         lines = origtext.splitlines()
00048         header = True
00049         for l in lines:
00050             if not l.startswith('#'):
00051                 header = False
00052             if header:
00053                 if l.startswith('#acl '):
00054                     acl_lines.append(l)
00055                 elif l.startswith('#language '):
00056                     language_line = l
00057                 elif l.startswith('#format '):
00058                     format_line = l
00059                 elif l.startswith('##master-page:'):
00060                     masterpage = l.split(':', 1)[1].strip()
00061                     master_lines.append(l)
00062                 elif l.startswith('##master-date:'):
00063                     master_lines.append(l)
00064                 elif l.startswith('##'):
00065                     comment_lines.append(l)
00066                 elif l.startswith('#'):
00067                     pragma_lines.append(l)
00068             else:
00069                 content_lines.append(l)
00070 
00071         if not language_line:
00072             language_line = '#language en'
00073         if not format_line:
00074             format_line = '#format wiki'
00075         aclold = '#acl MoinPagesEditorGroup:read,write,delete,revert All:read'
00076         if aclold in acl_lines:
00077             acl_lines.remove(aclold)
00078         if not acl_lines and (
00079             masterpage is None and not pagename.endswith('Template') or
00080             masterpage not in ['FrontPage', 'WikiSandBox', ] and not (pagename.endswith('Template') or masterpage.endswith('Template'))):
00081             acl_lines = ['#acl -All:write Default']
00082         if not master_lines:
00083             master_lines = ['##master-page:Unknown-Page', '##master-date:Unknown-Date', ]
00084 
00085         cold = [u"## Please edit system and help pages ONLY in the moinmaster wiki! For more",
00086                 u"## information, please see MoinMaster:MoinPagesEditorGroup.",
00087         ]
00088         cnew = [u"## Please edit system and help pages ONLY in the master wiki!",
00089                 u"## For more information, please see MoinMoin:MoinDev/Translation.",
00090         ]
00091         for c in cold + cnew:
00092             if c in comment_lines:
00093                 comment_lines.remove(c)
00094 
00095         comment_lines = cnew + comment_lines
00096 
00097         if content_lines and content_lines[-1].strip(): # not an empty line at EOF
00098             content_lines.append('')
00099 
00100         if masterpage and masterpage.endswith('Template'):
00101             changedtext = master_lines + [format_line, language_line, ] + pragma_lines + content_lines
00102         else:
00103             changedtext = comment_lines + master_lines + acl_lines + [format_line, language_line, ] + pragma_lines + content_lines
00104         changedtext = '\n'.join(changedtext)
00105         return changedtext

Here is the caller graph for this function:

def MoinMoin.script.MoinScript.init_request (   self) [inherited]
create request 

Definition at line 174 of file __init__.py.

00174 
00175     def init_request(self):
00176         """ create request """
00177         from MoinMoin.web.contexts import ScriptContext
00178         url = self.options.wiki_url or None
00179         self.request = ScriptContext(url, self.options.page)

Here is the caller graph for this function:

def MoinMoin.script.Script.logRuntime (   self) [inherited]
Print the total command run time. 

Definition at line 148 of file __init__.py.

00148 
00149     def logRuntime(self):
00150         """ Print the total command run time. """
00151         if self.options.show_timing:
00152             log("Needed %.3f secs." % (time.clock() - _start_time, ))
00153 

Here is the call graph for this function:

Reimplemented from MoinMoin.script.MoinScript.

Definition at line 106 of file globaledit.py.

00106 
00107     def mainloop(self):
00108         if debug:
00109             import codecs
00110             origtext = codecs.open('origtext', 'r', 'utf-8').read()
00111             origtext = origtext.replace('\r\n', '\n')
00112             changedtext = self.do_edit("", origtext)
00113             changedtext = changedtext.replace('\n', '\r\n')
00114             f = codecs.open('changedtext', 'w', 'utf-8')
00115             f.write(changedtext)
00116             f.close()
00117         else:
00118             self.init_request()
00119             request = self.request
00120 
00121             # Get all existing pages in the wiki
00122             pagelist = request.rootpage.getPageList(user='')
00123 
00124             for pagename in pagelist:
00125                 #request = CLI.Request(url=url, pagename=pagename.encode('utf-8'))
00126                 p = PageEditor.PageEditor(request, pagename, do_editor_backup=0)
00127                 origtext = p.get_raw_body()
00128                 changedtext = self.do_edit(pagename, origtext)
00129                 if changedtext and changedtext != origtext:
00130                     print "Writing %s ..." % repr(pagename)
00131                     p._write_file(changedtext)
00132 

Here is the call graph for this function:

def MoinMoin.script.Script.run (   self,
  showtime = 1 
) [inherited]
Run the main function of a command. 

Definition at line 130 of file __init__.py.

00130 
00131     def run(self, showtime=1):
00132         """ Run the main function of a command. """
00133         global flag_quiet
00134         try:
00135             try:
00136                 self.options, self.args = self.parser.parse_args(self.argv)
00137                 flag_quiet = self.options.quiet
00138                 # ToDo check if we need to initialize request (self.init_request())
00139                 self.mainloop()
00140             except KeyboardInterrupt:
00141                 log("*** Interrupted by user!")
00142             except SystemExit:
00143                 showtime = 0
00144                 raise
00145         finally:
00146             if showtime:
00147                 self.logRuntime()

Here is the caller graph for this function:


Member Data Documentation

Definition at line 135 of file __init__.py.

Definition at line 102 of file __init__.py.

Definition at line 113 of file __init__.py.

Definition at line 178 of file __init__.py.


The documentation for this class was generated from the following file: