changeset 871:75de15de041b storage-ng

add --file param to moin load/save script command
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 25 Sep 2011 17:36:31 +0200
parents 04cdc3823cac
children 135198715129 6362eb610f9f
files MoinMoin/script/maint/serialization.py
diffstat 1 files changed, 19 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/script/maint/serialization.py	Sun Sep 25 17:22:15 2011 +0200
+++ b/MoinMoin/script/maint/serialization.py	Sun Sep 25 17:36:31 2011 +0200
@@ -5,6 +5,7 @@
 MoinMoin - backend serialization / deserialization
 """
 
+import sys
 
 from flask import current_app as app
 from flask import g as flaskg
@@ -20,18 +21,32 @@
     description = 'Serialize the backend into a file.'
 
     option_list = [
+        Option('--file', '-f', dest='filename', type=unicode, required=False,
+               help='Filename of the output file.'),
     ]
 
-    def run(self, filename="dump"):
-        serialize(app.storage.backend, open(filename, "wb"))
+    def run(self, filename=None):
+        if filename is None:
+            f = sys.stdout
+        else:
+            f = open(filename, "wb")
+        with f as f:
+            serialize(app.storage.backend, f)
 
 
 class Deserialize(Command):
     description = 'Deserialize a file into the backend.'
 
     option_list = [
+        Option('--file', '-f', dest='filename', type=unicode, required=False,
+               help='Filename of the input file.'),
     ]
 
-    def run(self, filename="dump"):
-        deserialize(open(filename, "rb"), app.storage.backend)
+    def run(self, filename=None):
+        if filename is None:
+            f = sys.stdin
+        else:
+            f = open(filename, "rb")
+        with f as f:
+            deserialize(f, app.storage.backend)