Thomas Waldmann avatar Thomas Waldmann committed 75de15d

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

Comments (0)

Files changed (1)

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)
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.