summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2013-07-18 09:58:03 -0700
committermike bayer <mike_mp@zzzcomputing.com>2013-07-18 09:58:03 -0700
commit0857f04f80cb243e7818a9b09d4c7db2402f662e (patch)
treeca30eee1a16844b7e8ecfc291b600d3be358149e
parentd66202762de0e78b73037cdc111eae99cfaa0452 (diff)
parent673abcbfa259539d395f3f5fde67638679fd9b42 (diff)
downloadalembic-0857f04f80cb243e7818a9b09d4c7db2402f662e.tar.gz
Merge pull request #1 from cacilhas/master
bugfix: close forgotten file descriptors
-rw-r--r--alembic/command.py6
-rw-r--r--alembic/templates/multidb/env.py10
2 files changed, 7 insertions, 9 deletions
diff --git a/alembic/command.py b/alembic/command.py
index 095d041..26fc148 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 1b86896..a9cd393 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.