Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Private Attributes
MoinMoin.packages.ZipPackage Class Reference
Inheritance diagram for MoinMoin.packages.ZipPackage:
Inheritance graph
[legend]
Collaboration diagram for MoinMoin.packages.ZipPackage:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def extract_file
def filelist
def isPackage
def installPackage
def getScript
def do_addattachment
def do_delattachment
def do_print
def do_exit
def do_ignoreexceptions
def do_ensureversion
def do_setthemename
def do_copythemefile
def do_installplugin
def do_installpackage
def do_addrevision
def do_renamepage
def do_deletepage
def do_replaceunderlayattachment
def do_replaceunderlay
def runScript

Public Attributes

 filename
 zipfile
 request
 msg
 themename
 ignoreExceptions
 goto
 msg
 request
 revision

Private Attributes

 _isZipfile

Detailed Description

A package that reads its files from a .zip file. 

Definition at line 489 of file packages.py.


Constructor & Destructor Documentation

def MoinMoin.packages.ZipPackage.__init__ (   self,
  request,
  filename 
)
Initialise the package.

@param request: RequestBase instance
@param filename: filename of the .zip file

Definition at line 491 of file packages.py.

00491 
00492     def __init__(self, request, filename):
00493         """ Initialise the package.
00494 
00495         @param request: RequestBase instance
00496         @param filename: filename of the .zip file
00497         """
00498 
00499         Package.__init__(self, request)
00500         ScriptEngine.__init__(self)
00501         self.filename = filename
00502 
00503         self._isZipfile = zipfile.is_zipfile(filename)
00504         if self._isZipfile:
00505             self.zipfile = zipfile.ZipFile(filename)
00506         # self.zipfile.getinfo(name)


Member Function Documentation

def MoinMoin.packages.ScriptEngine.do_addattachment (   self,
  zipname,
  filename,
  pagename,
  author = u"Scripting Subsystem",
  comment = u"" 
) [inherited]
Installs an attachment

@param pagename: Page where the file is attached. Or in 2.0, the file itself.
@param zipname: Filename of the attachment from the zip file
@param filename: Filename of the attachment (just applicable for MoinMoin < 2.0)

Definition at line 120 of file packages.py.

00120 
00121     def do_addattachment(self, zipname, filename, pagename, author=u"Scripting Subsystem", comment=u""):
00122         """
00123         Installs an attachment
00124 
00125         @param pagename: Page where the file is attached. Or in 2.0, the file itself.
00126         @param zipname: Filename of the attachment from the zip file
00127         @param filename: Filename of the attachment (just applicable for MoinMoin < 2.0)
00128         """
00129         if self.request.user.may.write(pagename):
00130             _ = self.request.getText
00131 
00132             attachments = Page(self.request, pagename).getPagePath("attachments", check_create=1)
00133             filename = wikiutil.taintfilename(filename)
00134             zipname = wikiutil.taintfilename(zipname)
00135             target = os.path.join(attachments, filename)
00136             page = PageEditor(self.request, pagename, do_editor_backup=0, uid_override=author)
00137             rev = page.current_rev()
00138             path = page.getPagePath(check_create=0)
00139             if not os.path.exists(target):
00140                 self._extractToFile(zipname, target)
00141                 if os.path.exists(target):
00142                     os.chmod(target, config.umask )
00143                     action = 'ATTNEW'
00144                     edit_logfile_append(self, pagename, path, rev, action, logname='edit-log',
00145                                        comment=u'%(filename)s' % {"filename": filename}, author=author)
00146                 self.msg += u"%(filename)s attached \n" % {"filename": filename}
00147             else:
00148                 self.msg += u"%(filename)s not attached \n" % {"filename": filename}
00149         else:
00150             self.msg += u"action add attachment: not enough rights - nothing done \n"

Here is the call graph for this function:

def MoinMoin.packages.ScriptEngine.do_addrevision (   self,
  filename,
  pagename,
  author = u"Scripting Subsystem",
  comment = u"",
  trivial = u"No" 
) [inherited]
Adds a revision to a page.

@param filename: name of the file in this package
@param pagename: name of the target page
@param author:   user name of the editor (optional)
@param comment:  comment related to this revision (optional)
@param trivial:  boolean, if it is a trivial edit

Definition at line 288 of file packages.py.

00288 
00289     def do_addrevision(self, filename, pagename, author=u"Scripting Subsystem", comment=u"", trivial=u"No"):
00290         """ Adds a revision to a page.
00291 
00292         @param filename: name of the file in this package
00293         @param pagename: name of the target page
00294         @param author:   user name of the editor (optional)
00295         @param comment:  comment related to this revision (optional)
00296         @param trivial:  boolean, if it is a trivial edit
00297         """
00298         _ = self.request.getText
00299         trivial = str2boolean(trivial)
00300         if self.request.user.may.write(pagename):
00301             page = PageEditor(self.request, pagename, do_editor_backup=0)
00302             try:
00303                 page.saveText(self.extract_file(filename).decode("utf-8"), 0, trivial=trivial, comment=comment)
00304             except PageEditor.Unchanged:
00305                 pass
00306             else:
00307                 self.msg += u"%(pagename)s added \n" % {"pagename": pagename}
00308         else:
00309             self.msg += u"action add revision: not enough rights - nothing done \n"

Here is the call graph for this function:

def MoinMoin.packages.ScriptEngine.do_copythemefile (   self,
  filename,
  ftype,
  target 
) [inherited]
Copies a theme-related file (CSS, PNG, etc.) into a directory of the
current theme.

@param filename: name of the file in this package
@param ftype:   the subdirectory of the theme directory, e.g. "css"
@param target: filename, e.g. "screen.css"

Definition at line 219 of file packages.py.

00219 
00220     def do_copythemefile(self, filename, ftype, target):
00221         """ Copies a theme-related file (CSS, PNG, etc.) into a directory of the
00222         current theme.
00223 
00224         @param filename: name of the file in this package
00225         @param ftype:   the subdirectory of the theme directory, e.g. "css"
00226         @param target: filename, e.g. "screen.css"
00227         """
00228         _ = self.request.getText
00229         if self.themename is None:
00230             raise RuntimeScriptException(_("The theme name is not set."))
00231 
00232         from MoinMoin.web.static import STATIC_FILES_PATH as htdocs_dir
00233         if not os.access(htdocs_dir, os.W_OK):
00234             raise RuntimeScriptException(_("Theme files not installed! Write rights missing for %s.") % htdocs_dir)
00235 
00236         theme_file = os.path.join(htdocs_dir, self.themename,
00237                                   wikiutil.taintfilename(ftype),
00238                                   wikiutil.taintfilename(target))
00239         theme_dir = os.path.dirname(theme_file)
00240         if not os.path.exists(theme_dir):
00241             os.makedirs(theme_dir)
00242         self._extractToFile(filename, theme_file)

Here is the call graph for this function:

def MoinMoin.packages.ScriptEngine.do_delattachment (   self,
  filename,
  pagename,
  author = u"Scripting Subsystem",
  comment = u"" 
) [inherited]
Removes an attachment

@param pagename: Page where the file is attached. Or in 2.0, the file itself.
@param filename: Filename of the attachment (just applicable for MoinMoin < 2.0)

Definition at line 151 of file packages.py.

00151 
00152     def do_delattachment(self, filename, pagename, author=u"Scripting Subsystem", comment=u""):
00153         """
00154         Removes an attachment
00155 
00156         @param pagename: Page where the file is attached. Or in 2.0, the file itself.
00157         @param filename: Filename of the attachment (just applicable for MoinMoin < 2.0)
00158         """
00159         if self.request.user.may.write(pagename):
00160             _ = self.request.getText
00161 
00162             attachments = Page(self.request, pagename).getPagePath("attachments", check_create=1)
00163             filename = wikiutil.taintfilename(filename)
00164             target = os.path.join(attachments, filename)
00165             page = PageEditor(self.request, pagename, do_editor_backup=0, uid_override=author)
00166             rev = page.current_rev()
00167             path = page.getPagePath(check_create=0)
00168             if os.path.exists(target):
00169                 os.remove(target)
00170                 action = 'ATTDEL'
00171                 edit_logfile_append(self, pagename, path, rev, action, logname='edit-log',
00172                                     comment=u'%(filename)s' % {"filename": filename}, author=author)
00173                 self.msg += u"%(filename)s removed \n" % {"filename": filename}
00174             else:
00175                 self.msg += u"%(filename)s does not exist \n" % {"filename": filename}
00176         else:
00177             self.msg += u"action delete attachment: not enough rights - nothing done \n"

Here is the call graph for this function:

def MoinMoin.packages.ScriptEngine.do_deletepage (   self,
  pagename,
  comment = "Deleted by the scripting subsystem." 
) [inherited]
Marks a page as deleted (like the DeletePage action).

@param pagename: page to delete
@param comment:  the related comment (optional)

Definition at line 331 of file packages.py.

00331 
00332     def do_deletepage(self, pagename, comment="Deleted by the scripting subsystem."):
00333         """ Marks a page as deleted (like the DeletePage action).
00334 
00335         @param pagename: page to delete
00336         @param comment:  the related comment (optional)
00337         """
00338         if self.request.user.may.write(pagename):
00339             _ = self.request.getText
00340             page = PageEditor(self.request, pagename, do_editor_backup=0)
00341             if not page.exists():
00342                 raise RuntimeScriptException(_("The page %s does not exist.") % pagename)
00343             page.deletePage(comment)
00344         else:
00345             self.msg += u"action delete page: not enough rights - nothing done \n"

def MoinMoin.packages.ScriptEngine.do_ensureversion (   self,
  version,
  lines = 0 
) [inherited]
Ensures that the version of MoinMoin is greater or equal than
version. If lines is unspecified, the script aborts. Otherwise,
the next lines (amount specified by lines) are not executed.

@param version: required version of MoinMoin (e.g. "1.3.4")
@param lines: lines to ignore

Definition at line 191 of file packages.py.

00191 
00192     def do_ensureversion(self, version, lines=0):
00193         """
00194         Ensures that the version of MoinMoin is greater or equal than
00195         version. If lines is unspecified, the script aborts. Otherwise,
00196         the next lines (amount specified by lines) are not executed.
00197 
00198         @param version: required version of MoinMoin (e.g. "1.3.4")
00199         @param lines: lines to ignore
00200         """
00201         _ = self.request.getText
00202 
00203         from MoinMoin.version import release
00204         version_int = [int(x) for x in version.split(".")]
00205         # use a regex here to get only the numbers of the release string (e.g. ignore betaX)
00206         release = re.compile('\d+').findall(release)[0:3]
00207         release = [int(x) for x in release]
00208         if version_int > release:
00209             if lines > 0:
00210                 self.goto = lines
00211             else:
00212                 raise RuntimeScriptException(_("The package needs a newer version"
00213                                                " of MoinMoin (at least %s).") %
00214                                              version)

def MoinMoin.packages.ScriptEngine.do_exit (   self) [inherited]
Exits the script. 

Definition at line 182 of file packages.py.

00182 
00183     def do_exit(self):
00184         """ Exits the script. """
00185         raise ScriptExit

def MoinMoin.packages.ScriptEngine.do_ignoreexceptions (   self,
  boolean 
) [inherited]
Sets the ignore exceptions setting. If exceptions are ignored, the
script does not stop if one is encountered. 

Definition at line 186 of file packages.py.

00186 
00187     def do_ignoreexceptions(self, boolean):
00188         """ Sets the ignore exceptions setting. If exceptions are ignored, the
00189         script does not stop if one is encountered. """
00190         self.ignoreExceptions = str2boolean(boolean)

Here is the call graph for this function:

def MoinMoin.packages.ScriptEngine.do_installpackage (   self,
  pagename,
  filename 
) [inherited]
Installs a package.

@param pagename: Page where the file is attached. Or in 2.0, the file itself.
@param filename: Filename of the attachment (just applicable for MoinMoin < 2.0)

Definition at line 267 of file packages.py.

00267 
00268     def do_installpackage(self, pagename, filename):
00269         """
00270         Installs a package.
00271 
00272         @param pagename: Page where the file is attached. Or in 2.0, the file itself.
00273         @param filename: Filename of the attachment (just applicable for MoinMoin < 2.0)
00274         """
00275         _ = self.request.getText
00276 
00277         attachments = Page(self.request, pagename).getPagePath("attachments", check_create=0)
00278         package = ZipPackage(self.request, os.path.join(attachments, wikiutil.taintfilename(filename)))
00279 
00280         if package.isPackage():
00281             if not package.installPackage():
00282                 raise RuntimeScriptException(_("Installation of '%(filename)s' failed.") % {
00283                     'filename': filename} + "\n" + package.msg)
00284         else:
00285             raise RuntimeScriptException(_('The file %s is not a MoinMoin package file.') % filename)
00286 
00287         self.msg += package.msg

def MoinMoin.packages.ScriptEngine.do_installplugin (   self,
  filename,
  visibility,
  ptype,
  target 
) [inherited]
Installs a python code file into the appropriate directory.

@param filename: name of the file in this package
@param visibility: 'local' will copy it into the plugin folder of the
    current wiki. 'global' will use the folder of the MoinMoin python
    package.
@param ptype: the type of the plugin, e.g. "parser"
@param target: the filename of the plugin, e.g. wiki.py

Definition at line 243 of file packages.py.

00243 
00244     def do_installplugin(self, filename, visibility, ptype, target):
00245         """
00246         Installs a python code file into the appropriate directory.
00247 
00248         @param filename: name of the file in this package
00249         @param visibility: 'local' will copy it into the plugin folder of the
00250             current wiki. 'global' will use the folder of the MoinMoin python
00251             package.
00252         @param ptype: the type of the plugin, e.g. "parser"
00253         @param target: the filename of the plugin, e.g. wiki.py
00254         """
00255         visibility = visibility.lower()
00256         ptype = wikiutil.taintfilename(ptype.lower())
00257 
00258         if visibility == 'global':
00259             basedir = os.path.dirname(__import__("MoinMoin").__file__)
00260         elif visibility == 'local':
00261             basedir = self.request.cfg.plugin_dir
00262 
00263         target = os.path.join(basedir, ptype, wikiutil.taintfilename(target))
00264 
00265         self._extractToFile(filename, target)
00266         wikiutil._wiki_plugins = {}

Here is the call graph for this function:

def MoinMoin.packages.ScriptEngine.do_print (   self,
  param 
) [inherited]
Prints the parameters into output of the script. 

Definition at line 178 of file packages.py.

00178 
00179     def do_print(self, *param):
00180         """ Prints the parameters into output of the script. """
00181         self.msg += '; '.join(param) + "\n"

def MoinMoin.packages.ScriptEngine.do_renamepage (   self,
  pagename,
  newpagename,
  author = u"Scripting Subsystem",
  comment = u"Renamed by the scripting subsystem." 
) [inherited]
Renames a page.

@param pagename: name of the target page
@param newpagename: name of the new page
@param author:   user name of the editor (optional)
@param comment:  comment related to this revision (optional)

Definition at line 310 of file packages.py.

00310 
00311     def do_renamepage(self, pagename, newpagename, author=u"Scripting Subsystem", comment=u"Renamed by the scripting subsystem."):
00312         """ Renames a page.
00313 
00314         @param pagename: name of the target page
00315         @param newpagename: name of the new page
00316         @param author:   user name of the editor (optional)
00317         @param comment:  comment related to this revision (optional)
00318         """
00319         if self.request.user.may.write(pagename):
00320             _ = self.request.getText
00321             page = PageEditor(self.request, pagename, do_editor_backup=0, uid_override=author)
00322             if not page.exists():
00323                 raise RuntimeScriptException(_("The page %s does not exist.") % pagename)
00324             newpage = PageEditor(self.request, newpagename)
00325             page.renamePage(newpage.page_name, comment=u"Renamed from '%s'" % (pagename))
00326             self.msg += u'%(pagename)s renamed to %(newpagename)s\n' % {
00327                             "pagename": pagename,
00328                             "newpagename": newpagename}
00329         else:
00330             self.msg += u"action rename page: not enough rights - nothing done \n"

def MoinMoin.packages.ScriptEngine.do_replaceunderlay (   self,
  filename,
  pagename 
) [inherited]
Overwrites underlay pages. Implementational detail: This needs to be
kept in sync with the page class.

@param filename: name of the file in the package
@param pagename: page to be overwritten

Definition at line 370 of file packages.py.

00370 
00371     def do_replaceunderlay(self, filename, pagename):
00372         """
00373         Overwrites underlay pages. Implementational detail: This needs to be
00374         kept in sync with the page class.
00375 
00376         @param filename: name of the file in the package
00377         @param pagename: page to be overwritten
00378         """
00379         page = Page(self.request, pagename)
00380 
00381         pagedir = page.getPagePath(use_underlay=1, check_create=1)
00382 
00383         revdir = os.path.join(pagedir, 'revisions')
00384         cfn = os.path.join(pagedir, 'current')
00385 
00386         revstr = '%08d' % 1
00387         if not os.path.exists(revdir):
00388             os.mkdir(revdir)
00389 
00390         currentf = open(cfn, 'w')
00391         currentf.write(revstr + "\n")
00392         currentf.close()
00393 
00394         pagefile = os.path.join(revdir, revstr)
00395         self._extractToFile(filename, pagefile)
00396         # Clear caches
00397         # TODO Code from MoinMoin/script/maint/cleancache.py may be used

Here is the call graph for this function:

def MoinMoin.packages.ScriptEngine.do_replaceunderlayattachment (   self,
  zipname,
  filename,
  pagename,
  author = u"Scripting Subsystem",
  comment = u"" 
) [inherited]
overwrite underlay attachments

@param pagename: Page where the file is attached. Or in 2.0, the file itself.
@param zipname: Filename of the attachment from the zip file
@param filename: Filename of the attachment (just applicable for MoinMoin < 2.0)

Definition at line 346 of file packages.py.

00346 
00347     def do_replaceunderlayattachment(self, zipname, filename, pagename, author=u"Scripting Subsystem", comment=u""):
00348         """
00349         overwrite underlay attachments
00350 
00351         @param pagename: Page where the file is attached. Or in 2.0, the file itself.
00352         @param zipname: Filename of the attachment from the zip file
00353         @param filename: Filename of the attachment (just applicable for MoinMoin < 2.0)
00354         """
00355         if self.request.user.may.write(pagename):
00356             _ = self.request.getText
00357             filename = wikiutil.taintfilename(filename)
00358             zipname = wikiutil.taintfilename(zipname)
00359             page = PageEditor(self.request, pagename, do_editor_backup=0, uid_override=author)
00360             pagedir = page.getPagePath(use_underlay=1, check_create=1)
00361             attachments = os.path.join(pagedir, 'attachments')
00362             if not os.path.exists(attachments):
00363                 os.mkdir(attachments)
00364             target = os.path.join(attachments, filename)
00365             self._extractToFile(zipname, target)
00366             if os.path.exists(target):
00367                 os.chmod(target, config.umask )
00368         else:
00369             self.msg += u"action replace underlay attachment: not enough rights - nothing done \n"

Here is the call graph for this function:

def MoinMoin.packages.ScriptEngine.do_setthemename (   self,
  themename 
) [inherited]
Sets the name of the theme which will be altered next. 

Definition at line 215 of file packages.py.

00215 
00216     def do_setthemename(self, themename):
00217         """ Sets the name of the theme which will be altered next. """
00218         self.themename = wikiutil.taintfilename(str(themename))

def MoinMoin.packages.ZipPackage.extract_file (   self,
  filename 
)
Returns the contents of a file in the package. 

Reimplemented from MoinMoin.packages.Package.

Definition at line 507 of file packages.py.

00507 
00508     def extract_file(self, filename):
00509         """ Returns the contents of a file in the package. """
00510         _ = self.request.getText
00511         try:
00512             return self.zipfile.read(filename.encode("cp437"))
00513         except KeyError:
00514             raise RuntimeScriptException(_(
00515                 "The file %s was not found in the package.") % filename)

Here is the caller graph for this function:

Returns a list of all files. 

Reimplemented from MoinMoin.packages.Package.

Definition at line 516 of file packages.py.

00516 
00517     def filelist(self):
00518         """ Returns a list of all files. """
00519         return self.zipfile.namelist()

def MoinMoin.packages.Package.getScript (   self) [inherited]
Returns the script. 

Definition at line 473 of file packages.py.

00473 
00474     def getScript(self):
00475         """ Returns the script. """
00476         return self.extract_file(MOIN_PACKAGE_FILE).decode("utf-8").replace(u"\ufeff", "")

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.packages.Package.installPackage (   self) [inherited]
Opens the package and executes the script. 

Definition at line 461 of file packages.py.

00461 
00462     def installPackage(self):
00463         """ Opens the package and executes the script. """
00464 
00465         _ = self.request.getText
00466 
00467         if not self.isPackage():
00468             raise PackageException(_("The file %s was not found in the package.") % MOIN_PACKAGE_FILE)
00469 
00470         commands = self.getScript().splitlines()
00471 
00472         return self.runScript(commands)

Here is the call graph for this function:

Returns true if this package is recognised. 

Reimplemented from MoinMoin.packages.Package.

Definition at line 520 of file packages.py.

00520 
00521     def isPackage(self):
00522         """ Returns true if this package is recognised. """
00523         return self._isZipfile and MOIN_PACKAGE_FILE in self.zipfile.namelist()

def MoinMoin.packages.ScriptEngine.runScript (   self,
  commands 
) [inherited]
Runs the commands.

@param commands: list of strings which contain a command each
@return True on success

Definition at line 398 of file packages.py.

00398 
00399     def runScript(self, commands):
00400         """ Runs the commands.
00401 
00402         @param commands: list of strings which contain a command each
00403         @return True on success
00404         """
00405         _ = self.request.getText
00406 
00407         headerline = unpackLine(commands[0])
00408 
00409         if headerline[0].lower() != "MoinMoinPackage".lower():
00410             raise PackageException(_("Invalid package file header."))
00411 
00412         self.revision = int(headerline[1])
00413         if self.revision > MAX_VERSION:
00414             raise PackageException(_("Package file format unsupported."))
00415 
00416         lineno = 1
00417         success = True
00418 
00419         for line in commands[1:]:
00420             lineno += 1
00421             if self.goto > 0:
00422                 self.goto -= 1
00423                 continue
00424 
00425             if line.startswith("#") or len(line) == 0:
00426                 continue
00427             elements = unpackLine(line)
00428             fnname = elements[0].strip().lower()
00429             if fnname == '':
00430                 continue
00431             try:
00432                 fn = getattr(self, "do_" + fnname)
00433             except AttributeError:
00434                 self.msg += u"Exception RuntimeScriptException: %s\n" % (
00435                         _("Unknown function %(func)s in line %(lineno)i.") %
00436                         {'func': elements[0], 'lineno': lineno}, )
00437                 success = False
00438                 break
00439 
00440             try:
00441                 fn(*elements[1:])
00442             except ScriptExit:
00443                 break
00444             except TypeError, e:
00445                 self.msg += u"Exception %s (line %i): %s\n" % (e.__class__.__name__, lineno, unicode(e))
00446                 success = False
00447                 break
00448             except RuntimeScriptException, e:
00449                 if not self.ignoreExceptions:
00450                     self.msg += u"Exception %s (line %i): %s\n" % (e.__class__.__name__, lineno, unicode(e))
00451                     success = False
00452                     break
00453 
00454         return success

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 502 of file packages.py.

Definition at line 500 of file packages.py.

Definition at line 114 of file packages.py.

Definition at line 113 of file packages.py.

Definition at line 117 of file packages.py.

Definition at line 459 of file packages.py.

Definition at line 118 of file packages.py.

Definition at line 458 of file packages.py.

Definition at line 411 of file packages.py.

Definition at line 112 of file packages.py.

Definition at line 504 of file packages.py.


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