From 673abcbfa259539d395f3f5fde67638679fd9b42 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Cacilh=CE=B1=CF=82=2C=20La=20Batalema?= Date: Thu, 11 Jul 2013 15:46:16 -0300 Subject: [PATCH] bugfix: close forgotten file descriptors --- alembic/command.py | 6 +++--- alembic/templates/multidb/env.py | 10 ++++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/alembic/command.py b/alembic/command.py index 095d041f..26fc148c 100644 --- a/alembic/command.py +++ b/alembic/command.py @@ -9,11 +9,11 @@ def list_templates(config): config.print_stdout("Available templates:\n") for tempname in os.listdir(config.get_template_directory()): - readme = os.path.join( + with open(os.path.join( config.get_template_directory(), tempname, - 'README') - synopsis = open(readme).next() + 'README')) as readme: + synopsis = readme.next() config.print_stdout("%s - %s", tempname, synopsis) config.print_stdout("\nTemplates are used via the 'init' command, e.g.:") diff --git a/alembic/templates/multidb/env.py b/alembic/templates/multidb/env.py index b5f205c3..fc2d3ba4 100644 --- a/alembic/templates/multidb/env.py +++ b/alembic/templates/multidb/env.py @@ -64,12 +64,10 @@ def run_migrations_offline(): logger.info("Migrating database %s" % name) file_ = "%s.sql" % name logger.info("Writing output to %s" % file_) - context.configure( - url=rec['url'], - output_buffer=open(file_, 'w') - ) - with context.begin_transaction(): - context.run_migrations(engine_name=name) + with open(file_, 'w') as buffer: + context.configure(url=rec['url'], output_buffer=buffer) + with context.begin_transaction(): + context.run_migrations(engine_name=name) def run_migrations_online(): """Run migrations in 'online' mode. -- 2.47.2