Skip to content
Browse files

Add -o/--output option to yamltodb.

  • Loading branch information...
1 parent 7077633 commit 1552198585b8c1e8ab39c2fc20611c31ae53cb4e @jmafc jmafc committed
Showing with 12 additions and 0 deletions.
  1. +5 −0 docs/yamltodb.rst
  2. +7 −0 pyrseas/yamltodb.py
View
5 docs/yamltodb.rst
@@ -56,6 +56,11 @@ yamlspec
Specifies the host name of the machine on which the PostgreSQL
server is running. The default host name is 'localhost'.
+-o `file`, --output= `file`
+
+ Send SQL statements to the specified file. If this is omitted, the
+ standard output is used.
+
-p `port`, --port= `port`
Specifies the TCP port on which the PostgreSQL server is listening
View
7 pyrseas/yamltodb.py
@@ -31,6 +31,8 @@ def main(host='localhost', port=5432):
help="apply changes to database (implies -1)")
parser.add_option('-n', '--schema', dest='schlist', action='append',
help="only for named schemas (default all)")
+ parser.add_option('-o', '--output', dest='filename',
+ help="output file name (default stdout)")
parser.set_defaults(host=host, port=port, username=os.getenv("USER"))
(options, args) = parser.parse_args()
@@ -50,6 +52,9 @@ def main(host='localhost', port=5432):
if sch not in kschlist:
del inmap[sch]
stmts = db.diff_map(inmap, options.schlist)
+ if options.filename:
+ fd = open(options.filename, 'w')
+ sys.stdout = fd
if stmts:
if options.onetrans or options.update:
print("BEGIN;")
@@ -67,6 +72,8 @@ def main(host='localhost', port=5432):
else:
dbconn.conn.commit()
print("Changes applied", file=sys.stderr)
+ if options.filename:
+ fd.close()
if __name__ == '__main__':
main()

0 comments on commit 1552198

Please sign in to comment.
Something went wrong with that request. Please try again.