summaryrefslogtreecommitdiff
path: root/alembic/config.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2011-11-14 23:34:17 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2011-11-14 23:34:17 -0500
commitdfba9c719f2328e8e0cd6277c362c4d780e14ef3 (patch)
tree310faa3b5d967a2286247cc3c92c7e9846d81024 /alembic/config.py
parent1ceac5c457a6d6599e7c0ced35e998903fd362ab (diff)
downloadalembic-dfba9c719f2328e8e0cd6277c362c4d780e14ef3.tar.gz
- add argparse to install requires
- more docs - get env.py to work in --sql mode even without the DBAPI installed, using just the URL - add get_section_option()
Diffstat (limited to 'alembic/config.py')
-rw-r--r--alembic/config.py44
1 files changed, 25 insertions, 19 deletions
diff --git a/alembic/config.py b/alembic/config.py
index 26750a9..c5389f8 100644
--- a/alembic/config.py
+++ b/alembic/config.py
@@ -6,17 +6,17 @@ import os
class Config(object):
"""Represent an Alembic configuration.
-
+
You can get at one of these by specifying the name of
an .ini file::
-
+
from alembic.config import Config
alembic_cfg = Config("/path/to/yourapp/alembic.ini")
-
+
With a :class:`.Config` object, you can then
run Alembic commands programmatically using the directives
in :mod:`alembic.command`.
-
+
"""
def __init__(self, file_, ini_section='alembic'):
self.config_file_name = file_
@@ -30,13 +30,13 @@ class Config(object):
from. Defaults to ``alembic``, that is the ``[alembic]`` section
of the .ini file. This value is modified using the ``-n/--name``
option to the Alembic runnier.
-
+
"""
@util.memoized_property
def file_config(self):
"""Return the underlying :class:`ConfigParser` object.
-
+
Direct access to the .ini file is available here,
though the :meth:`.Config.get_section` and
:meth:`.Config.get_main_option`
@@ -51,36 +51,42 @@ class Config(object):
def get_template_directory(self):
"""Return the directory where Alembic setup templates are found.
-
+
This method is used by the alembic ``init`` and ``list_templates``
commands.
-
+
"""
return os.path.join(package_dir, 'templates')
def get_section(self, name):
"""Return all the configuration options from a given .ini file section
as a dictionary.
-
+
"""
return dict(self.file_config.items(name))
+ def get_section_option(self, section, name, default=None):
+ """Return an option from the given section of the .ini file.
+
+ """
+ if not self.file_config.has_section(section):
+ util.err("No config file %r found, or file has no "
+ "'[%s]' section" %
+ (self.config_file_name, section))
+ if self.file_config.has_option(section, name):
+ return self.file_config.get(section, name)
+ else:
+ return default
+
def get_main_option(self, name, default=None):
"""Return an option from the 'main' section of the .ini file.
-
+
This defaults to being a key from the ``[alembic]``
section, unless the ``-n/--name`` flag were used to
indicate a different section.
-
+
"""
- if not self.file_config.has_section(self.config_ini_section):
- util.err("No config file %r found, or file has no "
- "'[%s]' section" %
- (self.config_file_name, self.config_ini_section))
- if self.file_config.has_option(self.config_ini_section, name):
- return self.file_config.get(self.config_ini_section, name)
- else:
- return default
+ return self.get_section_option(self.config_ini_section, name, default)
def main(argv):
"""The console runner function for Alembic."""