Back to index

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

List of all members.

Public Member Functions

def __init__
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 dump MoinMoin wiki pages to static HTML files.

Detailed Instructions:
======================
General syntax: moin [options] export dump [dump-options]

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

[dump-options] see below:
0. You must run this script as owner of the wiki files, usually this is the
   web server user.

1. To dump all the pages on the wiki to the directory '/mywiki'
   moin ... export dump --target-dir=/mywiki

2. To dump all the pages readable by 'JohnSmith' on the wiki to the directory
   '/mywiki'
   moin ... export dump --target-dir=/mywiki --username JohnSmith

Definition at line 93 of file dump.py.


Constructor & Destructor Documentation

def MoinMoin.script.export.dump.PluginScript.__init__ (   self,
  argv = None,
  def_values = None 
)

Reimplemented from MoinMoin.script.MoinScript.

Definition at line 118 of file dump.py.

00118 
00119     def __init__(self, argv=None, def_values=None):
00120         script.MoinScript.__init__(self, argv, def_values)
00121         self.parser.add_option(
00122             "-t", "--target-dir", dest = "target_dir",
00123             help = "Write html dump to DIRECTORY"
00124         )
00125         self.parser.add_option(
00126             "-u", "--username", dest = "dump_user",
00127             help = "User the dump will be performed as (for ACL checks, etc)"
00128         )


Member Function Documentation

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:

moin-dump's main code. 

Reimplemented from MoinMoin.script.MoinScript.

Definition at line 129 of file dump.py.

00129 
00130     def mainloop(self):
00131         """ moin-dump's main code. """
00132 
00133         # Prepare output directory
00134         if not self.options.target_dir:
00135             script.fatal("you must use --target-dir=/your/output/path to specify the directory we write the html files to")
00136         outputdir = os.path.abspath(self.options.target_dir)
00137         try:
00138             os.mkdir(outputdir)
00139             script.log("Created output directory '%s'!" % outputdir)
00140         except OSError, err:
00141             if err.errno != errno.EEXIST:
00142                 script.fatal("Cannot create output directory '%s'!" % outputdir)
00143 
00144         # Insert config dir or the current directory to the start of the path.
00145         config_dir = self.options.config_dir
00146         if config_dir and os.path.isfile(config_dir):
00147             config_dir = os.path.dirname(config_dir)
00148         if config_dir and not os.path.isdir(config_dir):
00149             script.fatal("bad path given to --config-dir option")
00150         sys.path.insert(0, os.path.abspath(config_dir or os.curdir))
00151 
00152         self.init_request()
00153         request = self.request
00154 
00155         # fix url_prefix_static so we get relative paths in output html
00156         request.cfg.url_prefix_static = url_prefix_static
00157 
00158         # use this user for permissions checks
00159         request.user = user.User(request, name=self.options.dump_user)
00160 
00161         pages = request.rootpage.getPageList(user='') # get list of all pages in wiki
00162         pages.sort()
00163         if self.options.page: # did user request a particular page or group of pages?
00164             try:
00165                 namematch = re.compile(self.options.page)
00166                 pages = [page for page in pages if namematch.match(page)]
00167                 if not pages:
00168                     pages = [self.options.page]
00169             except:
00170                 pages = [self.options.page]
00171 
00172         wikiutil.quoteWikinameURL = lambda pagename, qfn=wikiutil.quoteWikinameFS: (qfn(pagename) + HTML_SUFFIX)
00173 
00174         AttachFile.getAttachUrl = lambda pagename, filename, request, **kw: _attachment(request, pagename, filename, outputdir, **kw)
00175 
00176         errfile = os.path.join(outputdir, 'error.log')
00177         errlog = open(errfile, 'w')
00178         errcnt = 0
00179 
00180         page_front_page = wikiutil.getLocalizedPage(request, request.cfg.page_front_page).page_name
00181         page_title_index = wikiutil.getLocalizedPage(request, 'TitleIndex').page_name
00182         page_word_index = wikiutil.getLocalizedPage(request, 'WordIndex').page_name
00183 
00184         navibar_html = ''
00185         for p in [page_front_page, page_title_index, page_word_index]:
00186             navibar_html += '[<a href="%s">%s</a>]&nbsp;' % (wikiutil.quoteWikinameURL(p), wikiutil.escape(p))
00187 
00188         urlbase = request.url # save wiki base url
00189         for pagename in pages:
00190             # we have the same name in URL and FS
00191             file = wikiutil.quoteWikinameURL(pagename)
00192             script.log('Writing "%s"...' % file)
00193             try:
00194                 pagehtml = ''
00195                 request.url = urlbase + pagename # add current pagename to url base
00196                 page = Page.Page(request, pagename)
00197                 request.page = page
00198                 try:
00199                     request.reset()
00200                     pagehtml = request.redirectedOutput(page.send_page, count_hit=0, content_only=1)
00201                 except:
00202                     errcnt = errcnt + 1
00203                     print >> sys.stderr, "*** Caught exception while writing page!"
00204                     print >> errlog, "~" * 78
00205                     print >> errlog, file # page filename
00206                     import traceback
00207                     traceback.print_exc(None, errlog)
00208             finally:
00209                 timestamp = time.strftime("%Y-%m-%d %H:%M")
00210                 filepath = os.path.join(outputdir, file)
00211                 fileout = codecs.open(filepath, 'w', config.charset)
00212                 fileout.write(page_template % {
00213                     'charset': config.charset,
00214                     'pagename': pagename,
00215                     'pagehtml': pagehtml,
00216                     'logo_html': logo_html,
00217                     'navibar_html': navibar_html,
00218                     'timestamp': timestamp,
00219                     'theme': request.cfg.theme_default,
00220                 })
00221                 fileout.close()
00222 
00223         # copy FrontPage to "index.html"
00224         indexpage = page_front_page
00225         if self.options.page:
00226             indexpage = pages[0] # index page has limited use when dumping specific pages, but create one anyway
00227         shutil.copyfile(
00228             os.path.join(outputdir, wikiutil.quoteWikinameFS(indexpage) + HTML_SUFFIX),
00229             os.path.join(outputdir, 'index' + HTML_SUFFIX)
00230         )
00231 
00232         errlog.close()
00233         if errcnt:
00234             print >> sys.stderr, "*** %d error(s) occurred, see '%s'!" % (errcnt, errfile)
00235 

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: