• R/O
  • SSH

execsql: Commit

Default repository for execsql.py


Commit MetaInfo

Revisionfeb27e06a7799cc56a83be77dca8bd02063cc202 (tree)
Time2020-06-01 09:10:41
AuthorDreas Nielsen <dreas.nielsen@gmai...>
CommiterDreas Nielsen

Log Message

Modified to close additional output files after writing.

Change Summary

Incremental Difference

diff -r 54ba035c947d -r feb27e06a779 execsql/execsql.py
--- a/execsql/execsql.py Sun May 31 14:52:54 2020 -0700
+++ b/execsql/execsql.py Sun May 31 17:10:41 2020 -0700
@@ -27,12 +27,12 @@
2727 #
2828 # ===============================================================================
2929
30-__version__ = "1.73.4"
30+__version__ = "1.73.5"
3131 __vdate = "2020-05-31"
3232
3333 primary_vno = 1
3434 secondary_vno = 73
35-tertiary_vno = 4
35+tertiary_vno = 5
3636
3737 import os
3838 import os.path
@@ -5071,6 +5071,8 @@
50715071 ofile = EncodedFile(output_dest, conf.output_encoding).open("w")
50725072 for dd in data_dict_rows:
50735073 ofile.write(self.template.safe_substitute(dd))
5074+ if output_dest != 'stdout':
5075+ ofile.close()
50745076
50755077 class JinjaTemplateReport(object):
50765078 # Exporting/reporting using the Jinja2 templating library.
@@ -5101,6 +5103,8 @@
51015103 raise ErrInfo("error", other_msg="Jinja2 template error (%s)" % e.message)
51025104 except:
51035105 raise
5106+ if output_dest != 'stdout':
5107+ ofile.close()
51045108
51055109 class AirspeedTemplateReport(object):
51065110 # Exporting/reporting using the Airspeed templating library.
@@ -5133,6 +5137,8 @@
51335137 raise ErrInfo("error", other_msg=e.msg)
51345138 except:
51355139 raise
5140+ if output_dest != 'stdout':
5141+ ofile.close()
51365142
51375143
51385144 # End of template-based exports.
@@ -9511,7 +9517,9 @@
95119517 global conf
95129518 if outf:
95139519 check_dir(outf)
9514- EncodedFile(outf, conf.output_encoding).open('a').write(msg)
9520+ of = EncodedFile(outf, conf.output_encoding).open('a')
9521+ of.write(msg)
9522+ of.close()
95159523 if (not outf) or tee:
95169524 try:
95179525 output.write(msg)
@@ -10351,6 +10359,8 @@
1035110359 if comment:
1035210360 o.write(u"-- %s\n" % comment)
1035310361 o.write(u"%s\n" % sql)
10362+ if outfile:
10363+ o.close()
1035410364
1035510365 metacommands.append(MetaCommand(
1035610366 ins_table_rxs(r'^\s*WRITE\s+CREATE_TABLE\s+',
@@ -10386,6 +10396,8 @@
1038610396 if comment:
1038710397 o.write(u"-- %s\n" % comment)
1038810398 o.write(u"%s\n" % sql)
10399+ if outfile:
10400+ o.close()
1038910401
1039010402 metacommands.append(MetaCommand(
1039110403 ins_table_rxs(r'^\s*WRITE\s+CREATE_TABLE\s+',
@@ -10428,6 +10440,8 @@
1042810440 if comment:
1042910441 o.write(u"-- %s\n" % comment)
1043010442 o.write(u"%s\n" % sql)
10443+ if outfile:
10444+ o.close()
1043110445
1043210446 metacommands.append(MetaCommand(
1043310447 ins_table_rxs(r'^\s*WRITE\s+CREATE_TABLE\s+',
@@ -10478,6 +10492,8 @@
1047810492 if comment:
1047910493 o.write(u"-- %s\n" % comment)
1048010494 o.write(u"%s\n" % sql)
10495+ if outfile:
10496+ o.close()
1048110497
1048210498 metacommands.append(MetaCommand(
1048310499 ins_table_rxs(r'^\s*WRITE\s+CREATE_TABLE\s+',
@@ -10768,7 +10784,7 @@
1076810784 if output_dest is None or output_dest == 'stdout':
1076910785 ofile = output
1077010786 else:
10771- check_dir(outfile)
10787+ check_dir(output_dest)
1077210788 if append:
1077310789 ofile = EncodedFile(output_dest, conf.output_encoding).open("a")
1077410790 else:
@@ -10782,6 +10798,8 @@
1078210798 for line in lines:
1078310799 ofile.write(u"%s\n" % line)
1078410800 ofile.write(u"END SCRIPT %s\n" % script_id)
10801+ if output_dest is not None and output_dest != 'stdout':
10802+ ofile.close()
1078510803
1078610804 metacommands.append(MetaCommand(ins_fn_rxs(r'^\s*(?:DEBUG\s+)?WRITE\s+SCRIPT\s+(?P<script_id>\w+)(?:\s+(?P<append>APPEND\s+)?TO\s+', r')?\s*$'), x_writescript))
1078710805
@@ -10920,6 +10938,8 @@
1092010938 for s in subvars.substitutions:
1092110939 if user is None or s[0][0].isalnum() or s[0][0] == '_':
1092210940 ofile.write(u"Substitution [%s] = [%s]\n" % s)
10941+ if output_dest is not None and output_dest != 'stdout':
10942+ ofile.close()
1092310943
1092410944 metacommands.append(MetaCommand(ins_fn_rxs(r'^\s*DEBUG\s+WRITE(?:\s+(?P<local>LOCAL))?(?:\s+(?P<user>USER))?\s+SUBVARS(?:\s+(?P<append>APPEND\s+)?TO\s+', r')?\s*$'), x_debug_write_subvars))
1092510945
@@ -10969,6 +10989,8 @@
1096910989 ofile.write(u"Config; Email CSS = %s\n" % conf.email_css)
1097010990 ofile.write(u"Config; DAO flush delay (seconds) = %s\n" % conf.dao_flush_delay_secs)
1097110991 ofile.write(u"Config; Configuration files read = %s\n" % ", ".join(conf.files_read))
10992+ if output_dest is not None and output_dest != 'stdout':
10993+ ofile.close()
1097210994
1097310995 metacommands.append(MetaCommand(ins_fn_rxs(r'^\s*DEBUG\s+WRITE\s+CONFIG(?:\s+(?P<append>APPEND\s+)?TO\s+', r')?\s*$'), x_debug_write_config))
1097410996
@@ -10990,6 +11012,8 @@
1099011012 ofile = EncodedFile(output_dest, conf.output_encoding).open("w")
1099111013 for d in pyodbc.drivers():
1099211014 ofile.write(u"%s\n" % d)
11015+ if output_dest is not None and output_dest != 'stdout':
11016+ ofile.close()
1099311017
1099411018 metacommands.append(MetaCommand(ins_fn_rxs(r'^\s*DEBUG\s+WRITE\s+ODBC_DRIVERS(?:\s+(?P<append>APPEND\s+)?TO\s+', r')?\s*$'), x_debug_write_odbc_drivers))
1099511019
@@ -11968,6 +11992,8 @@
1196811992 for row in rows:
1196911993 ln = u"%s%s\n" % (margin, row)
1197011994 ofile.write(ln)
11995+ if output_dest != 'stdout':
11996+ ofile.close()
1197111997 return None
1197211998
1197311999 def prettyprint_query(select_stmt, db, outfile, append=False, nd_val=u'', desc=None):
@@ -12166,6 +12192,8 @@
1216612192 quoted_row = ["'%s'" % v.replace("'", "''") if isinstance(v, stringtypes) else type(u"")(v) if v is not None else u"NULL" for v in r]
1216712193 f.write(u" (%s)" % u", ".join(quoted_row))
1216812194 f.write(u"\n ;\n")
12195+ if outfile.lower() != 'stdout':
12196+ f.close()
1216912197
1217012198 def write_query_to_values(select_stmt, db, outfile, append=False, desc=None):
1217112199 try:
@@ -12231,11 +12259,13 @@
1223112259 f.write(u'\n</head>\n<body>\n')
1223212260 write_table(f)
1223312261 f.write(u'</body>\n</html>\n')
12262+ f.close()
1223412263 else:
1223512264 if not os.path.isfile(outfile):
1223612265 ef = EncodedFile(outfile, conf.output_encoding)
1223712266 f = ef.open("wt")
1223812267 write_table(f)
12268+ f.close()
1223912269 else:
1224012270 ef = EncodedFile(outfile, conf.output_encoding)
1224112271 f = ef.open("rt")
@@ -12304,6 +12334,8 @@
1230412334 f.write(u'\\begin{document}\n')
1230512335 write_table(f)
1230612336 f.write(u'\\end{document}\n')
12337+ if outfile.lower() != 'stdout':
12338+ f.close()
1230712339 else:
1230812340 if outfile.lower() == 'stdout' or not os.path.isfile(outfile):
1230912341 if outfile.lower() == 'stdout':
@@ -12312,6 +12344,8 @@
1231212344 ef = EncodedFile(outfile, conf.output_encoding)
1231312345 f = ef.open("wt")
1231412346 write_table(f)
12347+ if outfile.lower() != 'stdout':
12348+ f.close()
1231512349 else:
1231612350 ef = EncodedFile(outfile, conf.output_encoding)
1231712351 f = ef.open("rt")
diff -r 54ba035c947d -r feb27e06a779 setup.py
--- a/setup.py Sun May 31 14:52:54 2020 -0700
+++ b/setup.py Sun May 31 17:10:41 2020 -0700
@@ -4,7 +4,7 @@
44 long_description = f.read()
55
66 setuptools.setup(name='execsql',
7- version='1.73.4',
7+ version='1.73.5',
88 description="Runs a SQL script against a PostgreSQL, MS-Access, SQLite, MS-SQL-Server, MySQL, MariaDB, Firebird, or Oracle database, or an ODBC DSN. Provides metacommands to import and export data, copy data between databases, conditionally execute SQL and metacommands, and dynamically alter SQL and metacommands with substitution variables. Data can be exported in 18 different formats, including CSV, TSV, ODS, HTML, JSON, LaTeX, and Markdown tables, and using custom templates.",
99 author='Dreas Nielsen',
1010 author_email='dreas.nielsen@gmail.com',
Show on old repository browser