From 5b41d938984b79334860a37c03c8c23298454942 Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Mon, 19 Jan 2015 21:44:57 +0100 Subject: [PATCH] refactor osusers.tasks into fileservertasks and ldaptasks --- gnuviechadmin/fileservertasks/__init__.py | 4 + gnuviechadmin/fileservertasks/tasks.py | 94 +++++++++++++++++++ gnuviechadmin/ldaptasks/__init__.py | 4 + gnuviechadmin/{osusers => ldaptasks}/tasks.py | 90 +----------------- gnuviechadmin/managemails/models.py | 15 ++- gnuviechadmin/osusers/models.py | 9 +- 6 files changed, 124 insertions(+), 92 deletions(-) create mode 100644 gnuviechadmin/fileservertasks/__init__.py create mode 100644 gnuviechadmin/fileservertasks/tasks.py create mode 100644 gnuviechadmin/ldaptasks/__init__.py rename gnuviechadmin/{osusers => ldaptasks}/tasks.py (57%) diff --git a/gnuviechadmin/fileservertasks/__init__.py b/gnuviechadmin/fileservertasks/__init__.py new file mode 100644 index 0000000..cb2d3eb --- /dev/null +++ b/gnuviechadmin/fileservertasks/__init__.py @@ -0,0 +1,4 @@ +""" +This module contains :py:mod:`fileservertasks.tasks`. + +""" diff --git a/gnuviechadmin/fileservertasks/tasks.py b/gnuviechadmin/fileservertasks/tasks.py new file mode 100644 index 0000000..bbae738 --- /dev/null +++ b/gnuviechadmin/fileservertasks/tasks.py @@ -0,0 +1,94 @@ +""" +This module defines task stubs for the tasks implemented in the gvafile Celery +worker. + +""" +from __future__ import absolute_import + +from celery import shared_task + + +@shared_task +def setup_file_sftp_userdir(username): + """ + This task creates the home directory for an SFTP user if it does not exist + yet. + + :param str username: the user name + :raises Exception: if the SFTP directory of the user cannot be created + :return: the created directory name + :rtype: str + + """ + + +@shared_task +def delete_file_sftp_userdir(username): + """ + This task recursively deletes the home directory of an SFTP user if it + does not exist yet. + + :param str username: the user name + :raises Exception: if the SFTP directory of the user cannot be removed + :return: the removed directory name + :rtype: str + + """ + + +@shared_task +def setup_file_mail_userdir(username): + """ + This task creates the mail base directory for a user if it does not exist + yet. + + :param str username: the user name + :raises Exception: if the mail base directory for the user cannot be + created + :return: the created directory name + :rtype: str + + """ + + +@shared_task +def delete_file_mail_userdir(username): + """ + This task recursively deletes the mail base directory for a user if it + does not exist yet. + + :param str username: the user name + :raises Exception: if the mail base directory of the user cannot be removed + :return: the removed directory name + :rtype: str + + """ + + +@shared_task +def create_file_mailbox(username, mailboxname): + """ + This task creates a new mailbox directory for the given user and mailbox + name. + + :param str username: the user name + :param str mailboxname: the mailbox name + :raises GVAFileException: if the mailbox directory cannot be created + :return: the created mailbox directory name + :rtype: str + + """ + + +@shared_task +def delete_file_mailbox(username, mailboxname): + """ + This task deletes the given mailbox of the given user. + + :param str username: the user name + :param str mailboxname: the mailbox name + :raises GVAFileException: if the mailbox directory cannot be deleted + :return: the deleted mailbox directory name + :rtype: str + + """ diff --git a/gnuviechadmin/ldaptasks/__init__.py b/gnuviechadmin/ldaptasks/__init__.py new file mode 100644 index 0000000..a2fa51e --- /dev/null +++ b/gnuviechadmin/ldaptasks/__init__.py @@ -0,0 +1,4 @@ +""" +This module contains :py:mod:`ldaptasks.tasks`. + +""" diff --git a/gnuviechadmin/osusers/tasks.py b/gnuviechadmin/ldaptasks/tasks.py similarity index 57% rename from gnuviechadmin/osusers/tasks.py rename to gnuviechadmin/ldaptasks/tasks.py index 23cc612..3a2ef31 100644 --- a/gnuviechadmin/osusers/tasks.py +++ b/gnuviechadmin/ldaptasks/tasks.py @@ -1,6 +1,6 @@ """ -This module defines task stubs for the tasks implemented on the Celery -workers. +This module defines task stubs for the tasks implemented in the gvaldap Celery +worker. """ from __future__ import absolute_import @@ -115,89 +115,3 @@ def delete_ldap_group(groupname): :rtype: boolean """ - - -@shared_task -def setup_file_sftp_userdir(username): - """ - This task creates the home directory for an SFTP user if it does not exist - yet. - - :param str username: the user name - :raises Exception: if the SFTP directory of the user cannot be created - :return: the created directory name - :rtype: str - - """ - - -@shared_task -def delete_file_sftp_userdir(username): - """ - This task recursively deletes the home directory of an SFTP user if it - does not exist yet. - - :param str username: the user name - :raises Exception: if the SFTP directory of the user cannot be removed - :return: the removed directory name - :rtype: str - - """ - - -@shared_task -def setup_file_mail_userdir(username): - """ - This task creates the mail base directory for a user if it does not exist - yet. - - :param str username: the user name - :raises Exception: if the mail base directory for the user cannot be - created - :return: the created directory name - :rtype: str - - """ - - -@shared_task -def delete_file_mail_userdir(username): - """ - This task recursively deletes the mail base directory for a user if it - does not exist yet. - - :param str username: the user name - :raises Exception: if the mail base directory of the user cannot be removed - :return: the removed directory name - :rtype: str - - """ - - -@shared_task -def create_file_mailbox(username, mailboxname): - """ - This task creates a new mailbox directory for the given user and mailbox - name. - - :param str username: the user name - :param str mailboxname: the mailbox name - :raises GVAFileException: if the mailbox directory cannot be created - :return: the created mailbox directory name - :rtype: str - - """ - - -@shared_task -def delete_file_mailbox(username, mailboxname): - """ - This task deletes the given mailbox of the given user. - - :param str username: the user name - :param str mailboxname: the mailbox name - :raises GVAFileException: if the mailbox directory cannot be deleted - :return: the deleted mailbox directory name - :rtype: str - - """ diff --git a/gnuviechadmin/managemails/models.py b/gnuviechadmin/managemails/models.py index 949d260..512bea7 100644 --- a/gnuviechadmin/managemails/models.py +++ b/gnuviechadmin/managemails/models.py @@ -1,3 +1,9 @@ +""" +This module defines the database models for mail handling. + +""" +from __future__ import unicode_literals + from django.db import models from django.utils.encoding import python_2_unicode_compatible from django.utils.translation import ugettext as _ @@ -7,7 +13,11 @@ from model_utils.models import TimeStampedModel from domains.models import MailDomain from osusers.models import User as OsUser -from osusers.tasks import create_file_mailbox, delete_file_mailbox + +from fileservertasks.tasks import ( + create_file_mailbox, + delete_file_mailbox, +) class ActivateAbleMixin(models.Model): @@ -22,6 +32,9 @@ class ActivateAbleMixin(models.Model): class MailboxManager(models.Manager): + """ + This is the default manager class for :py:class:`Mailbox`. + """ def get_next_mailbox_name(self, osuser): count = 1 diff --git a/gnuviechadmin/osusers/models.py b/gnuviechadmin/osusers/models.py index 8b5edfe..c5c25a6 100644 --- a/gnuviechadmin/osusers/models.py +++ b/gnuviechadmin/osusers/models.py @@ -22,15 +22,18 @@ from passlib.utils import generate_password from taskresults.models import TaskResult -from .tasks import ( +from ldaptasks.tasks import ( add_ldap_user_to_group, create_ldap_group, create_ldap_user, - delete_file_mail_userdir, - delete_file_sftp_userdir, delete_ldap_group, delete_ldap_user, remove_ldap_user_from_group, +) + +from fileservertasks.tasks import ( + delete_file_mail_userdir, + delete_file_sftp_userdir, setup_file_mail_userdir, setup_file_sftp_userdir, )