aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2022-10-10 20:53:04 +0200
committerDaniel Schadt <kingdread@gmx.de>2022-10-10 20:53:04 +0200
commite1361e556840a1a710385cd1a09bfa1a9f91742a (patch)
treee8cf3723fbea964cac964707a2140598f11d8f04
parent3402387360a5712c96d60c0ee67c03b268e4c55d (diff)
downloadfietsboek-e1361e556840a1a710385cd1a09bfa1a9f91742a.tar.gz
fietsboek-e1361e556840a1a710385cd1a09bfa1a9f91742a.tar.bz2
fietsboek-e1361e556840a1a710385cd1a09bfa1a9f91742a.zip
add a common base class to update scripts
This makes it easier to add some useful hooks, such as "self.tell" to output information about the update to the user, and it ensures the pre_alembic/post_alembic methods exist.
-rw-r--r--fietsboek/updater/__init__.py6
-rw-r--r--fietsboek/updater/script.py32
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