From: Mike Bayer Date: Tue, 15 Nov 2011 20:02:12 +0000 (-0500) Subject: - add set_main_option to config X-Git-Tag: rel_0_1_0~51 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=da8e3db9ec3ab96a1a90937a794122ea6c455548;p=thirdparty%2Fsqlalchemy%2Falembic.git - add set_main_option to config - add output_buffer option to config for programmatic output --- diff --git a/alembic/config.py b/alembic/config.py index 5409b836..8957ac0b 100644 --- a/alembic/config.py +++ b/alembic/config.py @@ -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. diff --git a/alembic/context.py b/alembic/context.py index cf19344a..4bc6b032 100644 --- a/alembic/context.py +++ b/alembic/context.py @@ -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: diff --git a/tests/__init__.py b/tests/__init__.py index 462e3d54..b2ecb944 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -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