diff options
-rw-r--r-- | fietsboek/updater/__init__.py | 6 | ||||
-rw-r--r-- | fietsboek/updater/script.py | 32 |
2 files changed, 36 insertions, 2 deletions
diff --git a/fietsboek/updater/__init__.py b/fietsboek/updater/__init__.py index 1c26715..e81a515 100644 --- a/fietsboek/updater/__init__.py +++ b/fietsboek/updater/__init__.py @@ -23,6 +23,8 @@ TEMPLATE = """\ Date created: {{ date }} \"\"\" +from fietsboek.updater.script import UpdateScript + update_id = {{ "{!r}".format(update_id) }} previous = [ {%- for prev in previous %} @@ -32,7 +34,7 @@ previous = [ alembic_revision = {{ "{!r}".format(alembic_revision) }} -class Up: +class Up(UpdateScript): def pre_alembic(self, config): pass @@ -40,7 +42,7 @@ class Up: pass -class Down: +class Down(UpdateScript): def pre_alembic(self, config): pass diff --git a/fietsboek/updater/script.py b/fietsboek/updater/script.py new file mode 100644 index 0000000..15e1d59 --- /dev/null +++ b/fietsboek/updater/script.py @@ -0,0 +1,32 @@ +# Placed in a separate file to avoid cyclic dependencies +class UpdateScript: + def tell(self, text): + """Output a message to the user. + + This function should be used in update scripts instead of :func:`print` + to ensure the right stream is selected. + + :param text: The text to show to the user. + :type text: str + """ + print(text) + + def pre_alembic(self, config): + """Script that is run before the alembic migration is run. + + This method is to be overridden by subclasses. + + :param config: The app configuration. + :type config: dict + """ + pass + + def post_alembic(self, config): + """Script that is run after the alembic migrations have been run. + + This method is to be overridden by subclasses. + + :param config: The app configuration. + :type config: dict + """ + pass |