]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
- add set_main_option to config
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 15 Nov 2011 20:02:12 +0000 (15:02 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 15 Nov 2011 20:02:12 +0000 (15:02 -0500)
- add output_buffer option to config for programmatic output

alembic/config.py
alembic/context.py
tests/__init__.py

index 5409b8364afca1257c77222757a06885646fc1d1..8957ac0b61cb6a0ad66b4984c1d765e4868dac09 100644 (file)
@@ -26,9 +26,20 @@ class Config(object):
     in :mod:`alembic.command`.
 
     """
-    def __init__(self, file_, ini_section='alembic'):
+    def __init__(self, file_, ini_section='alembic', output_buffer=None):
+        """Construct a new :class:`.Config`
+        
+        :param file_: name of the .ini file to open.
+        :param ini_section: name of the main Alembic section within the 
+         .ini file
+        :param output_buffer: optional file-like input buffer which
+         will be passed to the :class:`.Context` - used to redirect
+         access when using Alembic programmatically.
+
+        """
         self.config_file_name = file_
         self.config_ini_section = ini_section
+        self.output_buffer = output_buffer
 
     config_file_name = None
     """Filesystem path to the .ini file in use."""
@@ -73,6 +84,14 @@ class Config(object):
         """
         return dict(self.file_config.items(name))
 
+    def set_main_option(self, name, value):
+        """Set an option programmatically within the 'main' section.
+        
+        This overrides whatever was in the .ini file.
+        
+        """
+        self.file_config.set(self.config_ini_section, name, value)
+
     def get_section_option(self, section, name, default=None):
         """Return an option from the given section of the .ini file.
 
index cf19344a354cf79212b8bae15bdea93a310a17a6..4bc6b03225b14e4079aa573165edc1d95c8a38c2 100644 (file)
@@ -280,7 +280,8 @@ def configure(
      this otherwise defaults to whether or not the dialect in use supports it.
     :param output_buffer: a file-like object that will be used for textual output
      when the ``--sql`` option is used to generate SQL scripts.  Defaults to
-     ``sys.stdout`` if not passed here.
+     ``sys.stdout`` if not passed here and also not present on the :class:`.Config`
+     object.  The value here overrides that of the :class:`.Config` object.
     :param starting_rev: Override the "starting revision" argument when using
      ``--sql`` mode.
     :param tag: a string tag for usage by custom ``env.py`` scripts.  Set via
@@ -305,6 +306,8 @@ def configure(
         opts["transactional_ddl"] =  transactional_ddl
     if output_buffer is not None:
         opts["output_buffer"] = output_buffer
+    elif config.output_buffer is not None:
+        opts["output_buffer"] = config.output_buffer
     if starting_rev:
         opts['starting_rev'] = starting_rev
     if tag:
index 462e3d54efe8b82341e2516fadf40c3589be3009..b2ecb944a2e85ea7a018c74345a1d1822287ee9b 100644 (file)
@@ -92,14 +92,6 @@ def _op_fixture(dialect='default', as_sql=False):
         def __init__(self, dialect='default', as_sql=False):
             self.dialect = _get_dialect(dialect)
             self.impl = Impl(self.dialect, as_sql)
-#            super(ctx, self).__init__(_get_dialect(dialect), None, None, None, as_sql=as_sql)
-
-#    def __init__(self, dialect, script, connection, fn, 
-#                        as_sql=False, 
-#                       output_buffer=None,
-#                        transactional_ddl=None,
-#                        starting_rev=None):
-
 
             context._context = self
             self.as_sql = as_sql