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."""
"""
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.
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
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:
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