Commit 621c98ad authored by Kipp Cannon's avatar Kipp Cannon

dbtables: implement working copy mechanism as context manager

- removes the need to install a hook into the NamedTemporaryFile instance to delete the corresponding -journal file in the event of program termination.  clean-up is the responsibility of the context manager.
- backwards compatibility wrappers are provided
- a small change in calling code is, however, required:  in all calling codes, much change connect(tmpname) to connect(str(tmpname)).  this can be done in advance of the python-ligo-lw release.
- fixes issue #!14
parent e11928f7
......@@ -133,7 +133,7 @@ if will_read_from_file and not will_write_to_file and not os.path.exists(options
print("'%s': no such file" % options.database, file=sys.stderr)
target = dbtables.get_connection_filename(options.database, tmp_path = options.tmp_space if will_use_tmp_space else None, replace_file = will_replace_file, verbose = options.verbose)
ContentHandler.connection = sqlite3.connect(target)
ContentHandler.connection = sqlite3.connect(str(target))
......@@ -149,7 +149,7 @@ if will_write_to_file:
source_filename = dbtables.get_connection_filename(local_path_from_url(url), tmp_path = options.tmp_space, verbose = options.verbose)
if options.verbose:
print("reading '%s' ..." % source_filename, file=sys.stderr)
xmldoc = dbtables.get_xml(sqlite3.connect(source_filename))
xmldoc = dbtables.get_xml(sqlite3.connect(str(source_filename)))
ligolw_sqlite.insert_from_xmldoc(ContentHandler.connection, xmldoc, preserve_ids = options.preserve_ids, verbose = options.verbose)
dbtables.discard_connection_filename(local_path_from_url(url), source_filename, verbose = options.verbose)
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment