Commits

Thomas Waldmann committed 75de15d

add --file param to moin load/save script command

  • Participants
  • Parent commits 04cdc38
  • Branches storage-ng

Comments (0)

Files changed (1)

File MoinMoin/script/maint/serialization.py

 MoinMoin - backend serialization / deserialization
 """
 
+import sys
 
 from flask import current_app as app
 from flask import g as flaskg
     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)