Back to index

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

List of all members.

Public Member Functions

def __init__
def buildPageSets
def packagePages
def removePages
def mainloop
def init_request
def run
def logRuntime

Public Attributes

 request
 argv
 def_values
 parser
 args

Detailed Description

\
Purpose:
========
This tool generates a set of packages from all the pages in a wiki.

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

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

[mkpagepacks-options] see below:
0. THIS SCRIPT SHOULD NEVER BE RUN ON ANYTHING OTHER THAN A TEST WIKI!

1. This script takes no command line arguments.

Definition at line 28 of file mkpagepacks.py.


Constructor & Destructor Documentation

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

Reimplemented from MoinMoin.script.MoinScript.

Definition at line 47 of file mkpagepacks.py.

00047 
00048     def __init__(self, argv, def_values):
00049         MoinScript.__init__(self, argv, def_values)


Member Function Documentation

Calculates which pages should go into which package. 

Definition at line 50 of file mkpagepacks.py.

00050 
00051     def buildPageSets(self):
00052         """ Calculates which pages should go into which package. """
00053         request = self.request
00054 
00055         all_pages = set(request.rootpage.getPageList())
00056         packaged_pages = set()
00057 
00058         languages = i18n.wikiLanguages()
00059         pageset_names = i18n.strings.pagesets
00060         pageSets = {}
00061         for lang in languages:
00062             def trans(text, request=request, lang=lang, **kw):
00063                 return i18n.getText(text, request, lang, **kw)
00064 
00065             try:
00066                 lang_long = languages[lang]['x-language-in-english']
00067                 lang_long = lang_long.replace('/', '_').replace(' ', '_')
00068             except KeyError:
00069                 lang_long = lang
00070 
00071             for pageset_name in pageset_names:
00072                 pageset_orig = set(getattr(i18n.strings, pageset_name))
00073                 pageset_trans = set([trans(pn) for pn in pageset_orig])
00074                 key = u"%s_%s" % (lang_long, pageset_name)
00075                 pageset = pageset_trans
00076                 if lang != 'en':
00077                     pageset -= pageset_orig
00078                 if pageset:
00079                     print key, len(pageset)
00080                     pageSets[key] = pageset
00081                     packaged_pages |= pageset
00082 
00083         not_packaged_pages = all_pages - packaged_pages
00084         pageSets['00_needs_fixing'] = not_packaged_pages
00085         return pageSets

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 140 of file mkpagepacks.py.

00140 
00141     def mainloop(self):
00142         # self.options.wiki_url = 'localhost/'
00143         if self.options.wiki_url and '.' in self.options.wiki_url:
00144             print "NEVER EVER RUN THIS ON A REAL WIKI!!! This must be run on a local testwiki."
00145             return
00146 
00147         self.init_request() # this request will work on a test wiki in tests/wiki/ directory
00148                             # we assume that there are current moinmaster pages there
00149         request = self.request
00150 
00151         if not ('tests/wiki' in request.cfg.data_dir.replace("\\", "/") and 'tests/wiki' in request.cfg.data_underlay_dir.replace("\\", "/")):
00152             import sys
00153             print sys.path
00154             print "NEVER EVER RUN THIS ON A REAL WIKI!!! This must be run on a local testwiki."
00155             return
00156 
00157         print "Building page sets ..."
00158         pageSets = self.buildPageSets()
00159 
00160         print "Creating packages ..."
00161         package_path = os.path.join('tests', 'wiki', 'underlay', 'pages', 'LanguageSetup', 'attachments')
00162         try:
00163             # create attachment dir in case it is not there:
00164             os.mkdir(package_path)
00165         except OSError:
00166             pass
00167         generate_filename = lambda name: os.path.join(package_path, '%s.zip' % name)
00168         [self.packagePages(list(pages), generate_filename(name), "ReplaceUnderlay") for name, pages in pageSets.items()]
00169 
00170         print "Removing pagedirs of packaged pages ..."
00171         dontkill = set(['LanguageSetup'])
00172         [self.removePages(list(pages - dontkill)) for name, pages in pageSets.items()]
00173 
00174         print "Finished."
00175 

Here is the call graph for this function:

def MoinMoin.script.maint.mkpagepacks.PluginScript.packagePages (   self,
  pagelist,
  filename,
  function 
)
Puts pages from pagelist into filename and calls function on them on installation. 

Definition at line 86 of file mkpagepacks.py.

00086 
00087     def packagePages(self, pagelist, filename, function):
00088         """ Puts pages from pagelist into filename and calls function on them on installation. """
00089         request = self.request
00090         try:
00091             os.remove(filename)
00092         except OSError:
00093             pass
00094         # page LanguageSetup needs no packing!
00095         existing_pages = [pagename for pagename in pagelist if Page(request, pagename).exists() and pagename != 'LanguageSetup']
00096         if not existing_pages:
00097             return
00098 
00099         zf = zipfile.ZipFile(filename, "w", COMPRESSION_LEVEL)
00100 
00101         script = [packLine(['MoinMoinPackage', '1']), ]
00102 
00103         cnt = 0
00104         for pagename in existing_pages:
00105             pagename = pagename.strip()
00106             page = Page(request, pagename)
00107             files = _get_files(request, pagename)
00108             for attname in files:
00109                 cnt += 1
00110                 zipname = "%d" % cnt
00111                 script.append(packLine(["ReplaceUnderlayAttachment", zipname, attname, pagename]))
00112                 attpath = AttachFile.getFilename(request, pagename, attname)
00113                 zf.write(attpath, zipname)
00114 
00115             cnt += 1
00116             zipname = "%d" % cnt
00117             script.append(packLine([function, zipname, pagename]))
00118             timestamp = wikiutil.version2timestamp(page.mtime_usecs())
00119             zi = zipfile.ZipInfo(filename=zipname, date_time=datetime.fromtimestamp(timestamp).timetuple()[:6])
00120             zi.compress_type = COMPRESSION_LEVEL
00121             zf.writestr(zi, page.get_raw_body().encode("utf-8"))
00122 
00123         script += [packLine(['Print', 'Installed MoinMaster page bundle %s.' % os.path.basename(filename)])]
00124 
00125         zf.writestr(MOIN_PACKAGE_FILE, u"\n".join(script).encode("utf-8"))
00126         zf.close()

Here is the call graph for this function:

Here is the caller graph for this function:

Pages from pagelist get removed from the underlay directory. 

Definition at line 127 of file mkpagepacks.py.

00127 
00128     def removePages(self, pagelist):
00129         """ Pages from pagelist get removed from the underlay directory. """
00130         request = self.request
00131         import shutil
00132         for pagename in pagelist:
00133             pagename = pagename.strip()
00134             page = Page(request, pagename)
00135             try:
00136                 underlay, path = page.getPageBasePath(-1)
00137                 shutil.rmtree(path)
00138             except:
00139                 pass

Here is the caller 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: