changeset 56:a8d244c73d48

merged main
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Wed, 02 Mar 2011 00:19:51 +0100
parents 32b88d45d63c (current diff) 0814fedc9020 (diff)
children cb538b13b626
files
diffstat 2 files changed, 48 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/script/maint/create_item.py	Wed Mar 02 00:19:51 2011 +0100
@@ -0,0 +1,46 @@
+# Copyright: 2011 MoinMoin:ReimarBauer
+# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
+
+"""
+    MoinMoin - creates an item 
+
+    This script creates a new revision of an item
+"""
+
+
+from flask import flaskg
+from flask import current_app as app
+from flaskext.script import Command, Option
+from MoinMoin.storage.error import ItemAlreadyExistsError, NoSuchItemError
+
+
+class Create_Item(Command):
+    description = 'This command can be used to create an item'
+    option_list = (
+        Option('--name', '-n', dest='name', type=unicode, required=True,
+            help='Name of the item to create'),
+        Option('--file', '-f', dest='data_file', type=unicode, required=True,
+            help='Filename of file to read in and store as item.'),
+        Option('--mimetype', '-m', dest='mimetype', type=unicode, required=True,
+            help='mimetype of item'),
+        Option('--comment', '-c', dest='comment', type=unicode,
+            help='comment for item')
+    )
+
+    def run(self, name, data_file, mimetype, comment):
+        storage = app.unprotected_storage
+        rev_no = -1
+        try:
+            item = storage.create_item(name)
+        except ItemAlreadyExistsError:
+            item = storage.get_item(name)
+            currentrev = item.get_revision(-1)
+            rev_no = currentrev.revno
+        rev = item.create_revision(rev_no + 1)
+        rev['action'] = u'SAVE'
+        rev['name'] = name
+        rev['mimetype'] = mimetype
+        data = open(data_file, 'rb')
+        rev.write(data.read())
+        item.commit()
+        data.close()
--- a/moin	Wed Mar 02 00:19:10 2011 +0100
+++ b/moin	Wed Mar 02 00:19:51 2011 +0100
@@ -74,6 +74,8 @@
 manager.add_command("maint_reduce_revisions", Reduce_Revisions())
 from MoinMoin.script.maint.set_meta import Set_Meta
 manager.add_command("maint_set_meta", Set_Meta())
+from MoinMoin.script.maint.create_item import Create_Item
+manager.add_command("maint_create_item", Create_Item())
 from MoinMoin.script.maint.xml import XML
 manager.add_command("maint_xml", XML())