From 68f0834954b75661e9978c06502e5495cb28f98e Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Wed, 4 Mar 2020 18:14:08 +0100 Subject: [PATCH] Refactor module structure Move pgsqltasks to top level to keep the task names when using Python 3 --- docs/changelog.rst | 2 ++ docs/code.rst | 32 ++++++++----------- docs/conf.py | 21 ++++++------ gvapgsql/gvacommon/.gitignore | 3 -- gvapgsql/gvacommon/celeryrouters.py | 9 ++---- gvapgsql/gvapgsql/__init__.py | 0 gvapgsql/gvapgsql/celery.py | 15 --------- gvapgsql/pgsqltasks/__init__.py | 6 ++++ gvapgsql/pgsqltasks/celery.py | 13 ++++++++ gvapgsql/pgsqltasks/models.py | 4 --- gvapgsql/{gvapgsql => pgsqltasks}/settings.py | 28 ++++++++-------- gvapgsql/pgsqltasks/tasks.py | 18 ++++------- 12 files changed, 67 insertions(+), 84 deletions(-) delete mode 100644 gvapgsql/gvacommon/.gitignore delete mode 100644 gvapgsql/gvapgsql/__init__.py delete mode 100644 gvapgsql/gvapgsql/celery.py create mode 100644 gvapgsql/pgsqltasks/celery.py delete mode 100644 gvapgsql/pgsqltasks/models.py rename gvapgsql/{gvapgsql => pgsqltasks}/settings.py (57%) diff --git a/docs/changelog.rst b/docs/changelog.rst index 0f36aa8..045cba4 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -1,6 +1,8 @@ Changelog ========= +* :support:`-` move pgsqltasks to top level to keep the task names when + using Python 3 * :support:`-` use Pipenv for dependency management * :release:`0.2.0 <2018-11-21>` diff --git a/docs/code.rst b/docs/code.rst index 0aac8f9..3ef1a9f 100644 --- a/docs/code.rst +++ b/docs/code.rst @@ -7,30 +7,24 @@ gvapgsql is implemented as `Celery`_ app. .. _Celery: http://www.celeryproject.org/ -The project module :py:mod:`gvapgsql` -===================================== - -.. automodule:: gvapgsql - - -:py:mod:`gvapgsql.celery` -------------------------- - -.. automodule:: gvapgsql.celery - :members: - - -:py:mod:`gvapgsql.settings` ---------------------------- - -.. automodule:: gvapgsql.settings - - :py:mod:`pgsqltasks` app ======================== +:py:mod:`pgsqltasks.celery` +--------------------------- + .. automodule:: pgsqltasks +.. automodule:: pgsqltasks.celery + :members: + + +:py:mod:`pgsqltasks.settings` +----------------------------- + +.. automodule:: pgsqltasks.settings + + :py:mod:`pgsqltasks.tasks` -------------------------- diff --git a/docs/conf.py b/docs/conf.py index 2b24949..4b0766f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # pymode:lint_ignore=E501 # -# gvamysql documentation build configuration file, created by +# gvapgsql documentation build configuration file, created by # sphinx-quickstart on Sun Feb 17 11:46:20 2013. # # This file is execfile()d with the current directory set to its containing dir. @@ -35,13 +35,13 @@ os.environ['GVAPGSQL_DBADMIN_PASSWORD'] = 'gvapgsql' # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = ['releases', 'sphinx.ext.autodoc', 'celery.contrib.sphinx'] +# configuration for releases extension +releases_issue_uri = 'https://git.dittberner.info/gnuviech/gvapgsql/issues/%s' +releases_release_uri = 'https://git.dittberner.info/gnuviech/gvapgsql/stc/tag/%s' + # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] -releases_issue_uri = 'https://dev.gnuviech-server.de/gvapgsql/ticket/%s' - -releases_release_uri = 'https://dev.gnuviech-server.de/gvapgsql/milestone/%s' - # The suffix of source filenames. source_suffix = '.rst' @@ -53,16 +53,17 @@ master_doc = 'index' # General information about the project. project = u'gvapgsql' -copyright = u'2015-2018 Jan Dittberner' +copyright = u'2015-2020 Jan Dittberner' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # -# The short X.Y version. -version = '0.2' # The full version, including alpha/beta/rc tags. -release = '0.2.0' +from pgsqltasks import __version__ as release + +# The short X.Y version. +version = ".".join(release.split('.')[:2]) # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -103,7 +104,7 @@ pygments_style = 'sphinx' # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. -html_theme = 'default' +html_theme = 'alabaster' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the diff --git a/gvapgsql/gvacommon/.gitignore b/gvapgsql/gvacommon/.gitignore deleted file mode 100644 index 5f1ace6..0000000 --- a/gvapgsql/gvacommon/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -.*.swp -*.pyc -.ropeproject/ diff --git a/gvapgsql/gvacommon/celeryrouters.py b/gvapgsql/gvacommon/celeryrouters.py index ec7b122..24ec8e5 100644 --- a/gvapgsql/gvacommon/celeryrouters.py +++ b/gvapgsql/gvacommon/celeryrouters.py @@ -3,13 +3,8 @@ from __future__ import unicode_literals class GvaRouter(object): - def route_for_task(self, task, args=None, kwargs=None): - for route in ['ldap', 'file', 'mysql', 'pgsql']: + for route in ["ldap", "file", "mysql", "pgsql"]: if route in task: - return { - 'exchange': route, - 'exchange_type': 'direct', - 'queue': route, - } + return {"exchange": route, "exchange_type": "direct", "queue": route} return None diff --git a/gvapgsql/gvapgsql/__init__.py b/gvapgsql/gvapgsql/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/gvapgsql/gvapgsql/celery.py b/gvapgsql/gvapgsql/celery.py deleted file mode 100644 index a99dd76..0000000 --- a/gvapgsql/gvapgsql/celery.py +++ /dev/null @@ -1,15 +0,0 @@ -""" -This module defines the Celery_ app for gvapgsql. - -.. _Celery: http://www.celeryproject.org/ - -""" -from __future__ import absolute_import - -from celery import Celery - -#: The Celery application -app = Celery('gvapgsql') - -app.config_from_object('gvapgsql.settings') -app.autodiscover_tasks(['pgsqltasks'], force=True) diff --git a/gvapgsql/pgsqltasks/__init__.py b/gvapgsql/pgsqltasks/__init__.py index c49a650..699edd7 100644 --- a/gvapgsql/pgsqltasks/__init__.py +++ b/gvapgsql/pgsqltasks/__init__.py @@ -2,3 +2,9 @@ This module contains :py:mod:`pgsqltasks.tasks`. """ + +__version__ = "0.3.0" + +from pgsqltasks.celery import app as celery_app + +__all__ = ("celery_app",) diff --git a/gvapgsql/pgsqltasks/celery.py b/gvapgsql/pgsqltasks/celery.py new file mode 100644 index 0000000..5873c89 --- /dev/null +++ b/gvapgsql/pgsqltasks/celery.py @@ -0,0 +1,13 @@ +""" +This module defines the Celery_ app for gvapgsql. + +.. _Celery: http://www.celeryproject.org/ + +""" +from celery import Celery + +#: The Celery application +app = Celery("pgsqltasks") + +app.config_from_object("pgsqltasks.settings") +app.autodiscover_tasks(["pgsqltasks.tasks"], force=True) diff --git a/gvapgsql/pgsqltasks/models.py b/gvapgsql/pgsqltasks/models.py deleted file mode 100644 index 3a43087..0000000 --- a/gvapgsql/pgsqltasks/models.py +++ /dev/null @@ -1,4 +0,0 @@ -""" -Empty models to make Django accept pgsqltasks as an app. - -""" diff --git a/gvapgsql/gvapgsql/settings.py b/gvapgsql/pgsqltasks/settings.py similarity index 57% rename from gvapgsql/gvapgsql/settings.py rename to gvapgsql/pgsqltasks/settings.py index 5de01b4..1bafb26 100644 --- a/gvapgsql/gvapgsql/settings.py +++ b/gvapgsql/pgsqltasks/settings.py @@ -25,23 +25,21 @@ def get_env_setting(setting): ########## CELERY CONFIGURATION -CELERY_TIMEZONE = 'Europe/Berlin' -CELERY_ENABLE_UTC = True -CELERY_RESULT_BACKEND = 'amqp' -CELERY_RESULT_PERSISTENT = True +CELERY_BROKER_URL = get_env_setting("GVAPGSQL_BROKER_URL") +CELERY_RESULT_BACKEND = get_env_setting("GVAPGSQL_RESULTS_REDIS_URL") CELERY_TASK_RESULT_EXPIRES = None -CELERY_ROUTES = ( - 'gvacommon.celeryrouters.GvaRouter', -) -CELERY_ACCEPT_CONTENT = ['json'] -CELERY_TASK_SERIALIZER = 'json' -CELERY_RESULT_SERIALIZER = 'json' -BROKER_URL = get_env_setting('GVAPGSQL_BROKER_URL') +CELERY_ROUTES = ("gvacommon.celeryrouters.GvaRouter",) +CELERY_TIMEZONE = "Europe/Berlin" +CELERY_ENABLE_UTC = True +CELERY_RESULT_PERSISTENT = True +CELERY_ACCEPT_CONTENT = ["json"] +CELERY_TASK_SERIALIZER = "json" +CELERY_RESULT_SERIALIZER = "json" ########## END CELERY CONFIGURATION ########## GVAPGSQL CONFIGURATION -GVAPGSQL_DBADMIN_HOST = get_env_setting('GVAPGSQL_DBADMIN_HOST') -GVAPGSQL_DBADMIN_PORT = int(get_env_setting('GVAPGSQL_DBADMIN_PORT')) -GVAPGSQL_DBADMIN_USER = get_env_setting('GVAPGSQL_DBADMIN_USER') -GVAPGSQL_DBADMIN_PASSWORD = get_env_setting('GVAPGSQL_DBADMIN_PASSWORD') +GVAPGSQL_DBADMIN_HOST = get_env_setting("GVAPGSQL_DBADMIN_HOST") +GVAPGSQL_DBADMIN_PORT = int(get_env_setting("GVAPGSQL_DBADMIN_PORT")) +GVAPGSQL_DBADMIN_USER = get_env_setting("GVAPGSQL_DBADMIN_USER") +GVAPGSQL_DBADMIN_PASSWORD = get_env_setting("GVAPGSQL_DBADMIN_PASSWORD") ########## END GVAPGSQL CONFIGURATION diff --git a/gvapgsql/pgsqltasks/tasks.py b/gvapgsql/pgsqltasks/tasks.py index 5fcf861..03ebca2 100644 --- a/gvapgsql/pgsqltasks/tasks.py +++ b/gvapgsql/pgsqltasks/tasks.py @@ -2,15 +2,12 @@ This module defines Celery_ tasks to manage PostgreSQL users and databases. """ -from __future__ import absolute_import - from celery import shared_task from celery.utils.log import get_task_logger - -from gvapgsql import settings from psycopg2 import connect from psycopg2.extensions import ISQLQuote +from pgsqltasks import settings _LOGGER = get_task_logger(__name__) @@ -56,7 +53,7 @@ def _get_connection(): port=settings.GVAPGSQL_DBADMIN_PORT, user=settings.GVAPGSQL_DBADMIN_USER, password=settings.GVAPGSQL_DBADMIN_PASSWORD, - database='postgres', + database="postgres", ) @@ -77,11 +74,10 @@ def create_pgsql_user(username, password): """ CREATE USER %(username)s WITH PASSWORD %(password)s """, - {'username': Ident(username), 'password': password} + {"username": Ident(username), "password": password}, ) - @shared_task def set_pgsql_userpassword(username, password): """ @@ -99,7 +95,7 @@ def set_pgsql_userpassword(username, password): """ ALTER ROLE %(username)s WITH PASSWORD %(password)s """, - {'username': Ident(username), 'password': password} + {"username": Ident(username), "password": password}, ) @@ -119,7 +115,7 @@ def delete_pgsql_user(username): """ DROP ROLE %(username)s """, - {'username': Ident(username)} + {"username": Ident(username)}, ) @@ -142,7 +138,7 @@ def create_pgsql_database(dbname, username): CREATE DATABASE %(dbname)s OWNER %(username)s TEMPLATE template0 ENCODING 'UTF8' """, - {'dbname': Ident(dbname), 'username': Ident(username)} + {"dbname": Ident(dbname), "username": Ident(username)}, ) @@ -163,5 +159,5 @@ def delete_pgsql_database(dbname): """ DROP DATABASE %(dbname)s """, - {'dbname': Ident(dbname)} + {"dbname": Ident(dbname)}, )