annotate MoinMoin/packages.py @ 3125:40c4670c3410

refactored auth package to use own logger
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Wed, 27 Feb 2008 10:05:20 +0100
parents 7dd064111811
children 8a1f1a9dd37f
rev   line source
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
2 """
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
3 MoinMoin - Package Installer
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
4
1918
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1821
diff changeset
5 @copyright: 2005 MoinMoin:AlexanderSchremmer,
1993
93877b7d87b9 fixing copyright headers:unified my name
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1920
diff changeset
6 2007 MoinMoin:ReimarBauer
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
7 @license: GNU GPL, see COPYING for details.
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
8 """
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
9
1791
6dd2e29acffe Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1729
diff changeset
10 import os, sys
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
11 import zipfile
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
12
1717
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
13 from MoinMoin import config, wikiutil, caching, user
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
14 from MoinMoin.Page import Page
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
15 from MoinMoin.PageEditor import PageEditor
1717
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
16 from MoinMoin.logfile import editlog, eventlog
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
17
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
18 MOIN_PACKAGE_FILE = 'MOIN_PACKAGE'
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
19 MAX_VERSION = 1
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
20
1717
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
21
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
22 # Exceptions
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
23 class PackageException(Exception):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
24 """ Raised if the package is broken. """
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
25 pass
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
26
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
27 class ScriptException(Exception):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
28 """ Raised when there is a problem in the script. """
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
29
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
30 def __unicode__(self):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
31 """ Return unicode error message """
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
32 if isinstance(self.args[0], str):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
33 return unicode(self.args[0], config.charset)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
34 else:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
35 return unicode(self.args[0])
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
36
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
37 class RuntimeScriptException(ScriptException):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
38 """ Raised when the script problem occurs at runtime. """
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
39
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
40 class ScriptExit(Exception):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
41 """ Raised by the script commands when the script should quit. """
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
42
1717
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
43 def event_logfile(self, pagename, pagefile):
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
44 # add event log entry
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
45 eventtype = 'SAVENEW'
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
46 mtime_usecs = wikiutil.timestamp2version(os.path.getmtime(pagefile))
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
47 elog = eventlog.EventLog(self.request)
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
48 elog.add(self.request, eventtype, {'pagename': pagename}, 1, mtime_usecs)
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
49
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
50 def edit_logfile_append(self, pagename, pagefile, rev, action, logname='edit-log', comment=u'', author=u"Scripting Subsystem"):
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
51 glog = editlog.EditLog(self.request, uid_override=author)
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
52 pagelog = Page(self.request, pagename).getPagePath(logname, use_underlay=0, isfile=1)
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
53 llog = editlog.EditLog(self.request, filename=pagelog,
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
54 uid_override=author)
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
55 mtime_usecs = wikiutil.timestamp2version(os.path.getmtime(pagefile))
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
56 host = '::1'
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
57 extra = u''
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
58 glog.add(self.request, mtime_usecs, rev, action, pagename, host, comment)
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
59 llog.add(self.request, mtime_usecs, rev, action, pagename, host, extra, comment)
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
60 event_logfile(self, pagename, pagefile)
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
61
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
62 # Parsing and (un)quoting for script files
1920
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
63 def packLine(items, separator="|"):
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
64 """ Packs a list of items into a string that is separated by `separator`. """
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
65 return '|'.join([item.replace('\\', '\\\\').replace(separator, '\\' + separator) for item in items])
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
66
293
239cd0931e6b Added missing API for PackagePages action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 262
diff changeset
67 def unpackLine(string, separator="|"):
604
c96423da9e21 Beautified parts of the packages code to satisfy pylint
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 550
diff changeset
68 """ Unpacks a string that was packed by packLine. """
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
69 result = []
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
70 token = None
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
71 escaped = False
604
c96423da9e21 Beautified parts of the packages code to satisfy pylint
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 550
diff changeset
72 for char in string:
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
73 if token is None:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
74 token = ""
604
c96423da9e21 Beautified parts of the packages code to satisfy pylint
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 550
diff changeset
75 if escaped and char in ('\\', separator):
c96423da9e21 Beautified parts of the packages code to satisfy pylint
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 550
diff changeset
76 token += char
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
77 escaped = False
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
78 continue
604
c96423da9e21 Beautified parts of the packages code to satisfy pylint
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 550
diff changeset
79 escaped = (char == '\\')
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
80 if escaped:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
81 continue
604
c96423da9e21 Beautified parts of the packages code to satisfy pylint
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 550
diff changeset
82 if char == separator:
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
83 result.append(token)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
84 token = ""
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
85 else:
604
c96423da9e21 Beautified parts of the packages code to satisfy pylint
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 550
diff changeset
86 token += char
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
87 if token is not None:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
88 result.append(token)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
89 return result
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
90
604
c96423da9e21 Beautified parts of the packages code to satisfy pylint
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 550
diff changeset
91 def str2boolean(string):
c96423da9e21 Beautified parts of the packages code to satisfy pylint
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 550
diff changeset
92 """
c96423da9e21 Beautified parts of the packages code to satisfy pylint
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 550
diff changeset
93 Converts the parameter to a boolean value by recognising different
c96423da9e21 Beautified parts of the packages code to satisfy pylint
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 550
diff changeset
94 truth literals.
c96423da9e21 Beautified parts of the packages code to satisfy pylint
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 550
diff changeset
95 """
c96423da9e21 Beautified parts of the packages code to satisfy pylint
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 550
diff changeset
96 return (string.lower() in ('yes', 'true', '1'))
c96423da9e21 Beautified parts of the packages code to satisfy pylint
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 550
diff changeset
97
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
98 class ScriptEngine:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
99 """
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
100 The script engine supplies the needed commands to execute the installation
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
101 script.
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
102 """
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
103
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
104 def _extractToFile(self, source, target):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
105 """ Extracts source and writes the contents into target. """
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
106 # TODO, add file dates
604
c96423da9e21 Beautified parts of the packages code to satisfy pylint
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 550
diff changeset
107 target_file = open(target, "wb")
c96423da9e21 Beautified parts of the packages code to satisfy pylint
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 550
diff changeset
108 target_file.write(self.extract_file(source))
c96423da9e21 Beautified parts of the packages code to satisfy pylint
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 550
diff changeset
109 target_file.close()
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
110
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
111 def __init__(self):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
112 self.themename = None
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
113 self.ignoreExceptions = False
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
114 self.goto = 0
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
115
604
c96423da9e21 Beautified parts of the packages code to satisfy pylint
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 550
diff changeset
116 #Satisfy pylint
c96423da9e21 Beautified parts of the packages code to satisfy pylint
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 550
diff changeset
117 self.msg = getattr(self, "msg", "")
c96423da9e21 Beautified parts of the packages code to satisfy pylint
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 550
diff changeset
118 self.request = getattr(self, "request", None)
1793
2a4caa295346 Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
119
1727
8907f3657f80 packages: uses now generic name for attachments as for pages n_attachment
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1717
diff changeset
120 def do_addattachment(self, zipname, filename, pagename, author=u"Scripting Subsystem", comment=u""):
1717
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
121 """
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
122 Installs an attachment
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
123
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
124 @param pagename: Page where the file is attached. Or in 2.0, the file itself.
1729
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
125 @param zipname: Filename of the attachment from the zip file
1717
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
126 @param filename: Filename of the attachment (just applicable for MoinMoin < 2.0)
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
127 """
1729
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
128 if self.request.user.may.write(pagename):
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
129 _ = self.request.getText
1717
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
130
1729
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
131 attachments = Page(self.request, pagename).getPagePath("attachments", check_create=1)
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
132 filename = wikiutil.taintfilename(filename)
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
133 zipname = wikiutil.taintfilename(zipname)
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
134 target = os.path.join(attachments, filename)
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
135 page = PageEditor(self.request, pagename, do_editor_backup=0, uid_override=author)
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
136 rev = page.current_rev()
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
137 path = page.getPagePath(check_create=0)
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
138 if not os.path.exists(target):
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
139 self._extractToFile(zipname, target)
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
140 if os.path.exists(target):
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
141 os.chmod(target, config.umask )
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
142 action = 'ATTNEW'
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
143 edit_logfile_append(self, pagename, path, rev, action, logname='edit-log',
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1993
diff changeset
144 comment=u'%(filename)s' % {"filename": filename}, author=author)
1729
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
145 self.msg += u"%(filename)s attached \n" % {"filename": filename}
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
146 else:
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1993
diff changeset
147 self.msg += u"%(filename)s not attached \n" % {"filename": filename}
1717
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
148 else:
1729
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
149 self.msg += u"action add attachment: not enough rights - nothing done \n"
1717
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
150
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
151 def do_delattachment(self, filename, pagename, author=u"Scripting Subsystem", comment=u""):
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
152 """
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
153 Removes an attachment
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
154
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
155 @param pagename: Page where the file is attached. Or in 2.0, the file itself.
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
156 @param filename: Filename of the attachment (just applicable for MoinMoin < 2.0)
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
157 """
1729
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
158 if self.request.user.may.write(pagename):
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
159 _ = self.request.getText
1717
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
160
1729
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
161 attachments = Page(self.request, pagename).getPagePath("attachments", check_create=1)
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
162 filename = wikiutil.taintfilename(filename)
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
163 target = os.path.join(attachments, filename)
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
164 page = PageEditor(self.request, pagename, do_editor_backup=0, uid_override=author)
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
165 rev = page.current_rev()
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
166 path = page.getPagePath(check_create=0)
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
167 if os.path.exists(target):
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
168 os.remove(target)
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
169 action = 'ATTDEL'
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
170 edit_logfile_append(self, pagename, path, rev, action, logname='edit-log',
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1993
diff changeset
171 comment=u'%(filename)s' % {"filename": filename}, author=author)
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1993
diff changeset
172 self.msg += u"%(filename)s removed \n" % {"filename": filename}
1729
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
173 else:
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1993
diff changeset
174 self.msg += u"%(filename)s not exists \n" % {"filename": filename}
1717
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
175 else:
1729
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
176 self.msg += u"action delete attachment: not enough rights - nothing done \n"
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
177
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
178 def do_print(self, *param):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
179 """ Prints the parameters into output of the script. """
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
180 self.msg += '; '.join(param) + "\n"
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
181
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
182 def do_exit(self):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
183 """ Exits the script. """
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
184 raise ScriptExit
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
185
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
186 def do_ignoreexceptions(self, boolean):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
187 """ Sets the ignore exceptions setting. If exceptions are ignored, the
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
188 script does not stop if one is encountered. """
604
c96423da9e21 Beautified parts of the packages code to satisfy pylint
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 550
diff changeset
189 self.ignoreExceptions = str2boolean(boolean)
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
190
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
191 def do_ensureversion(self, version, lines=0):
490
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 377
diff changeset
192 """
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 377
diff changeset
193 Ensures that the version of MoinMoin is greater or equal than
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 377
diff changeset
194 version. If lines is unspecified, the script aborts. Otherwise,
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 377
diff changeset
195 the next lines (amount specified by lines) are not executed.
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
196
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
197 @param version: required version of MoinMoin (e.g. "1.3.4")
490
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 377
diff changeset
198 @param lines: lines to ignore
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
199 """
604
c96423da9e21 Beautified parts of the packages code to satisfy pylint
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 550
diff changeset
200 _ = self.request.getText
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
201
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
202 from MoinMoin.version import release
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
203 version_int = [int(x) for x in version.split(".")]
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
204 release = [int(x) for x in release.split(".")]
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
205 if version_int > release:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
206 if lines > 0:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
207 self.goto = lines
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
208 else:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
209 raise RuntimeScriptException(_("The package needs a newer version"
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
210 " of MoinMoin (at least %s).") %
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
211 version)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
212
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
213 def do_setthemename(self, themename):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
214 """ Sets the name of the theme which will be altered next. """
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
215 self.themename = wikiutil.taintfilename(str(themename))
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
216
604
c96423da9e21 Beautified parts of the packages code to satisfy pylint
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 550
diff changeset
217 def do_copythemefile(self, filename, ftype, target):
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
218 """ Copies a theme-related file (CSS, PNG, etc.) into a directory of the
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
219 current theme.
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
220
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
221 @param filename: name of the file in this package
604
c96423da9e21 Beautified parts of the packages code to satisfy pylint
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 550
diff changeset
222 @param ftype: the subdirectory of the theme directory, e.g. "css"
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
223 @param target: filename, e.g. "screen.css"
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
224 """
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
225 _ = self.request.getText
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
226 if self.themename is None:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
227 raise RuntimeScriptException(_("The theme name is not set."))
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
228 sa = getattr(self.request, "sareq", None)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
229 if sa is None:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
230 raise RuntimeScriptException(_("Installing theme files is only supported "
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
231 "for standalone type servers."))
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
232 htdocs_dir = sa.server.htdocs
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
233 theme_file = os.path.join(htdocs_dir, self.themename,
604
c96423da9e21 Beautified parts of the packages code to satisfy pylint
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 550
diff changeset
234 wikiutil.taintfilename(ftype),
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
235 wikiutil.taintfilename(target))
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
236 theme_dir = os.path.dirname(theme_file)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
237 if not os.path.exists(theme_dir):
1427
5e4d0d49dd60 don't use mask, as we have os.umask() now
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1317
diff changeset
238 os.makedirs(theme_dir)
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
239 self._extractToFile(filename, theme_file)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
240
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
241 def do_installplugin(self, filename, visibility, ptype, target):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
242 """
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
243 Installs a python code file into the appropriate directory.
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
244
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
245 @param filename: name of the file in this package
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
246 @param visibility: 'local' will copy it into the plugin folder of the
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
247 current wiki. 'global' will use the folder of the MoinMoin python
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
248 package.
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
249 @param ptype: the type of the plugin, e.g. "parser"
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
250 @param target: the filename of the plugin, e.g. wiki.py
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
251 """
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
252 visibility = visibility.lower()
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
253 ptype = wikiutil.taintfilename(ptype.lower())
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
254
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
255 if visibility == 'global':
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
256 basedir = os.path.dirname(__import__("MoinMoin").__file__)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
257 elif visibility == 'local':
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
258 basedir = self.request.cfg.plugin_dir
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
259
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
260 target = os.path.join(basedir, ptype, wikiutil.taintfilename(target))
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
261
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
262 self._extractToFile(filename, target)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
263 wikiutil._wiki_plugins = {}
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
264
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
265 def do_installpackage(self, pagename, filename):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
266 """
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
267 Installs a package.
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
268
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
269 @param pagename: Page where the file is attached. Or in 2.0, the file itself.
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
270 @param filename: Filename of the attachment (just applicable for MoinMoin < 2.0)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
271 """
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
272 _ = self.request.getText
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
273
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
274 attachments = Page(self.request, pagename).getPagePath("attachments", check_create=0)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
275 package = ZipPackage(self.request, os.path.join(attachments, wikiutil.taintfilename(filename)))
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
276
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
277 if package.isPackage():
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
278 if not package.installPackage():
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
279 raise RuntimeScriptException(_("Installation of '%(filename)s' failed.") % {
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
280 'filename': filename} + "\n" + package.msg)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
281 else:
2293
bb76818db210 i18n fixes, mostly _('aa'%xx) -> _('aa')%xx
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
282 raise RuntimeScriptException(_('The file %s is not a MoinMoin package file.') % filename)
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
283
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
284 self.msg += package.msg
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
285
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
286 def do_addrevision(self, filename, pagename, author=u"Scripting Subsystem", comment=u"", trivial=u"No"):
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
287 """ Adds a revision to a page.
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
288
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
289 @param filename: name of the file in this package
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
290 @param pagename: name of the target page
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
291 @param author: user name of the editor (optional)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
292 @param comment: comment related to this revision (optional)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
293 @param trivial: boolean, if it is a trivial edit
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
294 """
1729
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
295 if self.request.user.may.write(pagename):
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
296 _ = self.request.getText
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
297 trivial = str2boolean(trivial)
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
298 uid = user.getUserId(self.request, author)
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
299 theuser = user.User(self.request, uid)
1821
b88810a5c7b5 packages:cycles user in do_addrevision
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1793
diff changeset
300 save_user = self.request.user
1729
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
301 self.request.user = theuser
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
302 page = PageEditor(self.request, pagename, do_editor_backup=0, uid_override=author)
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
303 try:
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
304 page.saveText(self.extract_file(filename).decode("utf-8"), 0, trivial=trivial, comment=comment)
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
305 self.msg += u"%(pagename)s added \n" % {"pagename": pagename}
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
306 except PageEditor.Unchanged:
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
307 pass
1821
b88810a5c7b5 packages:cycles user in do_addrevision
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1793
diff changeset
308 self.request.user = save_user
1729
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
309 page.clean_acl_cache()
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
310 else:
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
311 self.msg += u"action add revision: not enough rights - nothing done \n"
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
312
1717
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
313 def do_renamepage(self, pagename, newpagename, author=u"Scripting Subsystem", comment=u"Renamed by the scripting subsystem."):
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
314 """ Renames a page.
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
315
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
316 @param pagename: name of the target page
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
317 @param newpagename: name of the new page
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
318 @param author: user name of the editor (optional)
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
319 @param comment: comment related to this revision (optional)
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
320 """
1729
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
321 if self.request.user.may.write(pagename):
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
322 _ = self.request.getText
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
323 page = PageEditor(self.request, pagename, do_editor_backup=0, uid_override=author)
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
324 if not page.exists():
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
325 raise RuntimeScriptException(_("The page %s does not exist.") % pagename)
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
326 newpage = PageEditor(self.request, newpagename)
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
327 page.renamePage(newpage.page_name, comment=u"Renamed from '%s'" % (pagename))
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
328 self.msg += u'%(pagename)s renamed to %(newpagename)s\n' % {
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
329 "pagename": pagename,
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
330 "newpagename": newpagename}
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
331 else:
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
332 self.msg += u"action rename page: not enough rights - nothing done \n"
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
333
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
334 def do_deletepage(self, pagename, comment="Deleted by the scripting subsystem."):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
335 """ Marks a page as deleted (like the DeletePage action).
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
336
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
337 @param pagename: page to delete
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
338 @param comment: the related comment (optional)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
339 """
1729
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
340 if self.request.user.may.write(pagename):
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
341 _ = self.request.getText
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
342 page = PageEditor(self.request, pagename, do_editor_backup=0)
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
343 if not page.exists():
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
344 raise RuntimeScriptException(_("The page %s does not exist.") % pagename)
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
345 page.deletePage(comment)
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
346 else:
fe83672bd165 packages: for page stuff relevant acl checks added (superuser must not have default or before acl rights)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1727
diff changeset
347 self.msg += u"action delete page: not enough rights - nothing done \n"
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
348
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
349 def do_replaceunderlay(self, filename, pagename):
490
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 377
diff changeset
350 """
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 377
diff changeset
351 Overwrites underlay pages. Implementational detail: This needs to be
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 377
diff changeset
352 kept in sync with the page class.
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
353
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
354 @param filename: name of the file in the package
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
355 @param pagename: page to be overwritten
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
356 """
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
357 page = Page(self.request, pagename)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
358
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
359 pagedir = page.getPagePath(use_underlay=1, check_create=1)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
360
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
361 revdir = os.path.join(pagedir, 'revisions')
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
362 cfn = os.path.join(pagedir, 'current')
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
363
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
364 revstr = '%08d' % 1
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
365 if not os.path.exists(revdir):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
366 os.mkdir(revdir)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
367
604
c96423da9e21 Beautified parts of the packages code to satisfy pylint
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 550
diff changeset
368 currentf = open(cfn, 'w')
c96423da9e21 Beautified parts of the packages code to satisfy pylint
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 550
diff changeset
369 currentf.write(revstr + "\n")
c96423da9e21 Beautified parts of the packages code to satisfy pylint
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 550
diff changeset
370 currentf.close()
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
371
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
372 pagefile = os.path.join(revdir, revstr)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
373 self._extractToFile(filename, pagefile)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
374
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
375 # Clear caches
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
376 try:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
377 del self.request.cfg.DICTS_DATA
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
378 except AttributeError:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
379 pass
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
380 self.request.pages = {}
682
1314fdb74689 refactor CacheEntry usage to use scope param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 640
diff changeset
381 caching.CacheEntry(self.request, 'wikidicts', 'dicts_groups', scope='wiki').remove()
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
382 page.clean_acl_cache()
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
383
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
384 def runScript(self, commands):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
385 """ Runs the commands.
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
386
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
387 @param commands: list of strings which contain a command each
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
388 @return True on success
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
389 """
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
390 _ = self.request.getText
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
391
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
392 headerline = unpackLine(commands[0])
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
393
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
394 if headerline[0].lower() != "MoinMoinPackage".lower():
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
395 raise PackageException(_("Invalid package file header."))
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
396
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
397 self.revision = int(headerline[1])
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
398 if self.revision > MAX_VERSION:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
399 raise PackageException(_("Package file format unsupported."))
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
400
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
401 lineno = 1
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
402 success = True
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
403
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
404 for line in commands[1:]:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
405 lineno += 1
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
406 if self.goto > 0:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
407 self.goto -= 1
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
408 continue
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
409
1717
10c60d1131dd packages:AddAttachment, DelAttachment, RenamePage added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1427
diff changeset
410 if line.startswith("#") or len(line) == 0:
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
411 continue
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
412 elements = unpackLine(line)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
413 fnname = elements[0].strip().lower()
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
414 if fnname == '':
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
415 continue
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
416 try:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
417 fn = getattr(self, "do_" + fnname)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
418 except AttributeError:
550
24c87a2cd368 Changed i18ned string to have named arguments.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 490
diff changeset
419 self.msg += u"Exception RuntimeScriptException: %s\n" % (
24c87a2cd368 Changed i18ned string to have named arguments.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 490
diff changeset
420 _("Unknown function %(func)s in line %(lineno)i.") %
24c87a2cd368 Changed i18ned string to have named arguments.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 490
diff changeset
421 {'func': elements[0], 'lineno': lineno}, )
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
422 success = False
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
423 break
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
424
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
425 try:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
426 fn(*elements[1:])
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
427 except ScriptExit:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
428 break
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
429 except TypeError, e:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
430 self.msg += u"Exception %s (line %i): %s\n" % (e.__class__.__name__, lineno, unicode(e))
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
431 success = False
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
432 break
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
433 except RuntimeScriptException, e:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
434 if not self.ignoreExceptions:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
435 self.msg += u"Exception %s (line %i): %s\n" % (e.__class__.__name__, lineno, unicode(e))
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
436 success = False
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
437 break
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
438
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
439 return success
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
440
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
441 class Package:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
442 """ A package consists of a bunch of files which can be installed. """
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
443 def __init__(self, request):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
444 self.request = request
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
445 self.msg = ""
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
446
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
447 def installPackage(self):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
448 """ Opens the package and executes the script. """
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
449
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
450 _ = self.request.getText
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
451
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
452 if not self.isPackage():
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
453 raise PackageException(_("The file %s was not found in the package.") % MOIN_PACKAGE_FILE)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
454
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
455 commands = self.getScript().splitlines()
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
456
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
457 return self.runScript(commands)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
458
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
459 def getScript(self):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
460 """ Returns the script. """
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
461 return self.extract_file(MOIN_PACKAGE_FILE).decode("utf-8").replace(u"\ufeff", "")
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
462
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
463 def extract_file(self, filename):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
464 """ Returns the contents of a file in the package. """
604
c96423da9e21 Beautified parts of the packages code to satisfy pylint
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 550
diff changeset
465 raise NotImplementedError
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
466
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
467 def filelist(self):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
468 """ Returns a list of all files. """
604
c96423da9e21 Beautified parts of the packages code to satisfy pylint
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 550
diff changeset
469 raise NotImplementedError
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
470
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
471 def isPackage(self):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
472 """ Returns true if this package is recognised. """
1791
6dd2e29acffe Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1729
diff changeset
473 raise NotImplementedError
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
474
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
475 class ZipPackage(Package, ScriptEngine):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
476 """ A package that reads its files from a .zip file. """
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
477 def __init__(self, request, filename):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
478 """ Initialise the package.
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
479
490
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 377
diff changeset
480 @param request: RequestBase instance
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 377
diff changeset
481 @param filename: filename of the .zip file
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
482 """
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
483
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
484 Package.__init__(self, request)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
485 ScriptEngine.__init__(self)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
486 self.filename = filename
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
487
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
488 self._isZipfile = zipfile.is_zipfile(filename)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
489 if self._isZipfile:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
490 self.zipfile = zipfile.ZipFile(filename)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
491 # self.zipfile.getinfo(name)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
492
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
493 def extract_file(self, filename):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
494 """ Returns the contents of a file in the package. """
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
495 _ = self.request.getText
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
496 try:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
497 return self.zipfile.read(filename.encode("cp437"))
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
498 except KeyError:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
499 raise RuntimeScriptException(_(
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
500 "The file %s was not found in the package.") % filename)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
501
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
502 def filelist(self):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
503 """ Returns a list of all files. """
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
504 return self.zipfile.namelist()
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
505
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
506 def isPackage(self):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
507 """ Returns true if this package is recognised. """
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
508 return self._isZipfile and MOIN_PACKAGE_FILE in self.zipfile.namelist()
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
509
604
c96423da9e21 Beautified parts of the packages code to satisfy pylint
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 550
diff changeset
510 def main():
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
511 args = sys.argv
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
512 if len(args)-1 not in (2, 3) or args[1] not in ('l', 'i'):
604
c96423da9e21 Beautified parts of the packages code to satisfy pylint
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 550
diff changeset
513 print >> sys.stderr, """MoinMoin Package Installer v%(version)i
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
514
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
515 %(myname)s action packagefile [request URL]
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
516
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
517 action - Either "l" for listing the script or "i" for installing.
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
518 packagefile - The path to the file containing the MoinMoin installer package
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
519 request URL - Just needed if you are running a wiki farm, used to differentiate
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
520 the correct wiki.
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
521
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
522 Example:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
523
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
524 %(myname)s i ../package.zip
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
525
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
526 """ % {"version": MAX_VERSION, "myname": os.path.basename(args[0])}
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
527 raise SystemExit
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
528
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
529 packagefile = args[2]
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
530 if len(args) > 3:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
531 request_url = args[3]
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
532 else:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
533 request_url = "localhost/"
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
534
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
535 # Setup MoinMoin environment
2338
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2286
diff changeset
536 from MoinMoin.request import request_cli
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2286
diff changeset
537 request = request_cli.Request(url='localhost/')
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
538 request.form = request.args = request.setup_args()
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
539
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
540 package = ZipPackage(request, packagefile)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
541 if not package.isPackage():
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
542 print "The specified file %s is not a package." % packagefile
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
543 raise SystemExit
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
544
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
545 if args[1] == 'l':
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
546 print package.getScript()
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
547 elif args[1] == 'i':
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
548 if package.installPackage():
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
549 print "Installation was successful!"
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
550 else:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
551 print "Installation failed."
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
552 if package.msg:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
553 print package.msg
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
554
604
c96423da9e21 Beautified parts of the packages code to satisfy pylint
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 550
diff changeset
555 if __name__ == '__main__':
c96423da9e21 Beautified parts of the packages code to satisfy pylint
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 550
diff changeset
556 main()