diff --git a/docs/changelog.rst b/docs/changelog.rst index ef77ef1..35b4e66 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -1,6 +1,8 @@ Changelog ========= +* :feature:`-` implement new tasks create_file_website_hierarchy and + delete_file_website_hierarchy * :support:`-` remove unneeded Django dependencies * :release:`0.3.0 <2015-01-19>` diff --git a/docs/code.rst b/docs/code.rst index 87a7455..5e632c2 100644 --- a/docs/code.rst +++ b/docs/code.rst @@ -33,8 +33,8 @@ The project module :py:mod:`gvafile` :members: -:py:mod:`filservertasks` app -============================ +:py:mod:`fileservertasks` app +============================= .. automodule:: fileservertasks diff --git a/gvafile/fileservertasks/tasks.py b/gvafile/fileservertasks/tasks.py index 6761dae..05123e2 100644 --- a/gvafile/fileservertasks/tasks.py +++ b/gvafile/fileservertasks/tasks.py @@ -197,3 +197,74 @@ def delete_file_mailbox(username, mailboxname): raise GVAFileException( "could not remove mailbox %s of user %s" % (mailboxname, username)) return mailbox_directory + + +@shared_task +def create_file_website_hierarchy(username, sitename): + """ + This task creates the directory hierarchy for a website. + + :param str username: the user name + :param str sitename: name of the website + :return: the directory name + :rtype: str + + """ + website_directory = os.path.join( + _build_sftp_directory_name(username), sitename) + try: + subprocess.check_output([ + SUDO_CMD, INSTALL_CMD, '-o', 'root', '-g', username, + '-m', '0750', '-d', website_directory], stderr=subprocess.STDOUT) + subprocess.check_output([ + SUDO_CMD, SETFACL_CMD, '-m', 'www-data:--x', + website_directory], stderr=subprocess.STDOUT) + htmldir = os.path.join(website_directory, 'html') + subprocess.check_output([ + SUDO_CMD, INSTALL_CMD, '-o', username, '-g', username, + '-m', '0750', '-d', htmldir], stderr=subprocess.STDOUT) + subprocess.check_output([ + SUDO_CMD, SETFACL_CMD, '-m', 'www-data:r-x', + htmldir], stderr=subprocess.STDOUT) + subprocess.check_output([ + SUDO_CMD, SETFACL_CMD, '-d', '-m', 'www-data:r-X', + htmldir], stderr=subprocess.STDOUT) + tmpdir = os.path.join(website_directory, 'tmp') + subprocess.check_output([ + SUDO_CMD, INSTALL_CMD, '-o', username, '-g', username, + '-m', '0750', '-d', tmpdir], stderr=subprocess.STDOUT) + except subprocess.CalledProcessError: + _logger.exception( + ("could not setup website file hierarchy for user %s's " + "website %s"), username, sitename) + raise GVAFileException( + ("could not setup website file hierarchy for user %s's " + "website %s") % (username, sitename)) + return website_directory + + +@shared_task +def delete_file_website_hierarchy(username, sitename): + """ + This task deletes the website hierarchy recursively. + + :param str username: the user name + :param str sitename: name of the website + :return: the directory name + :rtype: str + + """ + website_directory = os.path.join( + _build_sftp_directory_name(username), sitename) + try: + subprocess.check_output([ + SUDO_CMD, RM_CMD, '-r', '-f', website_directory], + stderr=subprocess.STDOUT) + except subprocess.CalledProcessError: + _logger.exception( + ("could not delete the website file hierarchy of user %s's " + "website %s"), username, sitename) + raise GVAFileException( + ("could not delete the website file hierarchy of user %s's " + "website %s") % (username, sitename)) + return website_directory