summaryrefslogtreecommitdiff
path: root/alembic/script
diff options
context:
space:
mode:
authorCaselIT <cfederico87@gmail.com>2023-04-02 12:21:00 +0200
committerFederico Caselli <cfederico87@gmail.com>2023-04-28 21:00:04 +0000
commite460d6756b86260460986eea292d30225e20d137 (patch)
tree7bc55b06b86f5b70200a0abaf5f235c90571250d /alembic/script
parentabd175bf86b1091fe444b91c4f98dc9ea97ff723 (diff)
downloadalembic-e460d6756b86260460986eea292d30225e20d137.tar.gz
Added quiet option to command line
Added quiet option to the command line, using the ``-q/--quiet`` option. This flag will prevent alembic from logging anything to stdout. Fixes: #1109 Change-Id: I7d9fac05d93e07efaefd87a582a7e785891798ef
Diffstat (limited to 'alembic/script')
-rw-r--r--alembic/script/base.py34
-rw-r--r--alembic/script/write_hooks.py15
2 files changed, 25 insertions, 24 deletions
diff --git a/alembic/script/base.py b/alembic/script/base.py
index b6858b5..2440865 100644
--- a/alembic/script/base.py
+++ b/alembic/script/base.py
@@ -9,9 +9,9 @@ import sys
from types import ModuleType
from typing import Any
from typing import cast
-from typing import Dict
from typing import Iterator
from typing import List
+from typing import Mapping
from typing import Optional
from typing import Sequence
from typing import Set
@@ -27,6 +27,7 @@ from ..util import not_none
if TYPE_CHECKING:
from ..config import Config
+ from ..config import MessagingOptions
from ..runtime.migration import RevisionStep
from ..runtime.migration import StampStep
from ..script.revision import Revision
@@ -79,8 +80,11 @@ class ScriptDirectory:
sourceless: bool = False,
output_encoding: str = "utf-8",
timezone: Optional[str] = None,
- hook_config: Optional[Dict[str, str]] = None,
+ hook_config: Optional[Mapping[str, str]] = None,
recursive_version_locations: bool = False,
+ messaging_opts: MessagingOptions = cast(
+ "MessagingOptions", util.EMPTY_DICT
+ ),
) -> None:
self.dir = dir
self.file_template = file_template
@@ -92,6 +96,7 @@ class ScriptDirectory:
self.timezone = timezone
self.hook_config = hook_config
self.recursive_version_locations = recursive_version_locations
+ self.messaging_opts = messaging_opts
if not os.access(dir, os.F_OK):
raise util.CommandError(
@@ -225,6 +230,7 @@ class ScriptDirectory:
timezone=config.get_main_option("timezone"),
hook_config=config.get_section("post_write_hooks", {}),
recursive_version_locations=rvl,
+ messaging_opts=config.messaging_opts,
)
@contextmanager
@@ -580,24 +586,24 @@ class ScriptDirectory:
return os.path.abspath(os.path.join(self.dir, "env.py"))
def _generate_template(self, src: str, dest: str, **kw: Any) -> None:
- util.status(
- "Generating %s" % os.path.abspath(dest),
- util.template_to_file,
- src,
- dest,
- self.output_encoding,
- **kw,
- )
+ with util.status(
+ f"Generating {os.path.abspath(dest)}", **self.messaging_opts
+ ):
+ util.template_to_file(src, dest, self.output_encoding, **kw)
def _copy_file(self, src: str, dest: str) -> None:
- util.status(
- "Generating %s" % os.path.abspath(dest), shutil.copy, src, dest
- )
+ with util.status(
+ f"Generating {os.path.abspath(dest)}", **self.messaging_opts
+ ):
+ shutil.copy(src, dest)
def _ensure_directory(self, path: str) -> None:
path = os.path.abspath(path)
if not os.path.exists(path):
- util.status("Creating directory %s" % path, os.makedirs, path)
+ with util.status(
+ f"Creating directory {path}", **self.messaging_opts
+ ):
+ os.makedirs(path)
def _generate_create_date(self) -> datetime.datetime:
if self.timezone is not None:
diff --git a/alembic/script/write_hooks.py b/alembic/script/write_hooks.py
index 8bc7ac1..d37555d 100644
--- a/alembic/script/write_hooks.py
+++ b/alembic/script/write_hooks.py
@@ -7,6 +7,7 @@ from typing import Any
from typing import Callable
from typing import Dict
from typing import List
+from typing import Mapping
from typing import Optional
from typing import Union
@@ -41,7 +42,7 @@ def register(name: str) -> Callable:
def _invoke(
- name: str, revision: str, options: Dict[str, Union[str, int]]
+ name: str, revision: str, options: Mapping[str, Union[str, int]]
) -> Any:
"""Invokes the formatter registered for the given name.
@@ -61,7 +62,7 @@ def _invoke(
return hook(revision, options)
-def _run_hooks(path: str, hook_config: Dict[str, str]) -> None:
+def _run_hooks(path: str, hook_config: Mapping[str, str]) -> None:
"""Invoke hooks for a generated revision."""
from .base import _split_on_space_comma
@@ -84,14 +85,8 @@ def _run_hooks(path: str, hook_config: Dict[str, str]) -> None:
"Key %s.type is required for post write hook %r" % (name, name)
) from ke
else:
- util.status(
- 'Running post write hook "%s"' % name,
- _invoke,
- type_,
- path,
- opts,
- newline=True,
- )
+ with util.status("Running post write hook {name!r}", newline=True):
+ _invoke(type_, path, opts)
def _parse_cmdline_options(cmdline_options_str: str, path: str) -> List[str]: