def create_wsgi_handler(self): wsgi_template = cuisine.text_strip_margin( """ |import os |import sys |import site | |# prevent errors with 'print' commands |sys.stdout = sys.stderr | |# adopted from http://code.google.com/p/modwsgi/wiki/VirtualEnvironments |def add_to_path(dirs): | # Remember original sys.path. | prev_sys_path = list(sys.path) | | # Add each new site-packages directory. | for directory in dirs: | site.addsitedir(directory) | | # Reorder sys.path so new directories at the front. | new_sys_path = [] | for item in list(sys.path): | if item not in prev_sys_path: | new_sys_path.append(item) | sys.path.remove(item) | sys.path[:0] = new_sys_path | |add_to_path([ | $virtualenv_path | | '$src_root', |]) | |os.environ['DJANGO_SETTINGS_MODULE'] = '$settings_module' | |import django.core.handlers.wsgi |application = django.core.handlers.wsgi.WSGIHandler() """) if self.use_virtualenv: virtualenv_template = cuisine.text_strip_margin(""" | os.path.normpath('$site_root/$virtualenv_name/lib/python$python_version/site-packages'), """) context = { 'site_root': self.remote_site_path, 'python_version': self.python.get_short_version(), 'virtualenv_name': self.virtualenv_name } virtualenv_path = cuisine.text_template(virtualenv_template, context) else: virtualenv_path = '' if self.env_path: context = self.__dict__.copy() context['virtualenv_path'] = virtualenv_path return cuisine.text_template(wsgi_template, context) else: raise RuntimeError("Properties env_path and $project_local_path should be set to configure web server")
def create_wsgi_handler(self): if self.use_virtualenv: virtualenv_template = cuisine.text_strip_margin( """ | os.path.normpath('$site_root/$virtualenv_name/lib/python$python_version/site-packages'), """ ) context = { "site_root": self.remote_site_path, "project_root": self.remote_project_path, "python_version": self.python.get_short_version(), "virtualenv_name": self.virtualenv_name, } virtualenv_path = cuisine.text_template(virtualenv_template, context) else: virtualenv_path = "" if self.env_path: context = self.settings.__dict__ context.update(self.__dict__.copy()) context["virtualenv_path"] = virtualenv_path return cuisine.text_template(self.wsgi_template, context) else: raise RuntimeError("Properties env_path and $project_local_path should be set to configure web server")
def create_apache_config(self): apache_template = cuisine.text_strip_margin( """ |<VirtualHost *:80> | ServerAdmin $server_admin | | DocumentRoot $static_root | | Alias $media_url $media_root/ | <Directory $media_root> | Order deny,allow | Allow from all | </Directory> | | Alias $static_url $static_root/ | <Directory $static_root> | Order deny,allow | Allow from all | </Directory> | | WSGIScriptAlias / $wsgi_handler_path | | WSGIDaemonProcess $project_name | WSGIProcessGroup %{GLOBAL} | |</VirtualHost> """) return cuisine.text_template(apache_template, self.__dict__)
def create_backup_script(self, folder=None, project_name=None): folder = folder or "/tmp" project_name = project_name or self.database_name tmpl = cuisine.text_strip_margin( """ |echo *:*:${database_name}:${user}:${password} > ~/.pgpass |chmod 0600 ~/.pgpass |file_full_path="${folder}/${project_name}_db_`date +%s`.sql.gz" |pg_dump -O -x ${database_name} | gzip > $file_full_path |echo $file_full_path | env python /usr/local/bin/s3.py |rm ~/.pgpass |rm $file_full_path """ ) context = { "database_name": self.database_name, "user": self.user, "password": self.password, "folder": folder, "project_name": project_name, } return cuisine.text_template(tmpl, context)
def create_backup_script(self, folder=None): folder = folder or "/tmp" tmpl = cuisine.text_strip_margin( """ |media_full_path="${folder}/${project_name}_media_`date +%s`.tar.gz" |tar -cvzf $media_full_path ${media_root} |echo $media_full_path | env python /usr/local/bin/s3.py |rm $media_full_path """ ) context = {"project_name": self.project_name, "media_root": self.media_root, "folder": folder} return cuisine.text_template(tmpl, context)
def create_apache_config(self): return cuisine.text_template(self.apache_template, self.__dict__)