implement new tasks for website hierarchy

- implement tasks fileservertasks.tasks.create_file_website_hierarchy and
  fileservertasks.tasks.delete_file_website_hierarchy
This commit is contained in:
Jan Dittberner 2015-01-26 17:32:24 +01:00
parent ea3164b762
commit 5955f3c38c
3 changed files with 75 additions and 2 deletions

View file

@ -1,6 +1,8 @@
Changelog Changelog
========= =========
* :feature:`-` implement new tasks create_file_website_hierarchy and
delete_file_website_hierarchy
* :support:`-` remove unneeded Django dependencies * :support:`-` remove unneeded Django dependencies
* :release:`0.3.0 <2015-01-19>` * :release:`0.3.0 <2015-01-19>`

View file

@ -33,8 +33,8 @@ The project module :py:mod:`gvafile`
:members: :members:
:py:mod:`filservertasks` app :py:mod:`fileservertasks` app
============================ =============================
.. automodule:: fileservertasks .. automodule:: fileservertasks

View file

@ -197,3 +197,74 @@ def delete_file_mailbox(username, mailboxname):
raise GVAFileException( raise GVAFileException(
"could not remove mailbox %s of user %s" % (mailboxname, username)) "could not remove mailbox %s of user %s" % (mailboxname, username))
return mailbox_directory 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