]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
bugfix: close forgotten file descriptors
authorCacilhας, La Batalema <batalema@cacilhas.info>
Thu, 11 Jul 2013 18:46:16 +0000 (15:46 -0300)
committerCacilhας, La Batalema <batalema@cacilhas.info>
Thu, 11 Jul 2013 18:46:16 +0000 (15:46 -0300)
alembic/command.py
alembic/templates/multidb/env.py

index 095d041f5b219fd99e08da9d742ccfc862471734..26fc148ca38519d5e9f3ed93427bed633644c0d5 100644 (file)
@@ -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.:")
index b5f205c3de8f99f34bf69413f6373cdd1bf646c1..fc2d3ba41ae34f4dbbb0be714c6047ec9a5db36e 100644 (file)
@@ -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.