+# -*- coding: utf-8 -*-
+#
+# This file is part of MIL/PEER, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+#
from __future__ import with_statement
-import shutil
import os
import sys
import logging
+from string import Template
logging.basicConfig(stream=sys.stderr, format="%(levelname)s:: %(message)s", level=logging.INFO)
-from string import Template
class DeploySite(object):
self.env['PYTHON_BIN'] = os.path.join(
self.env['PYTHON_BASE'], 'bin', 'python') + self.env['PYTHON_VERSION']
+ if 'PIP_BIN' not in self.env:
+ self.env['PIP_BIN'] = os.path.join(self.env['PYTHON_BASE'], 'bin', 'pip')
+
if 'PYTHON_SITE' not in self.env:
self.env['PYTHON_SITE'] = os.path.join(
self.env['PYTHON_BASE'], 'lib',
def update_app(self):
pass
+ def update_config(self):
+ pass
+
def install_dependencies(self):
pass
self.restart_app()
def find_resource(self, path):
- full_path = os.path.join(self.env['APP_DIR'], path)
- if os.path.isfile(full_path):
- return full_path
+ for dir in (self.env['CONFIG_DIR'], self.env['APP_DIR']):
+ full_path = os.path.join(dir, path)
+ if os.path.isfile(full_path):
+ return full_path
+
raise ValueError("Resource '%s' not found" % path)
@classmethod
site = cls(*args, **kwargs)
return site.deploy()
+
class WSGISite(DeploySite):
def __init__(self, **env):
if 'WSGI_FILE' not in self.env:
self.env['WSGI_FILE'] = os.path.join(self.env['ROOT'], 'www',
- 'wsgi', self.env['PROJECT_NAME']) + '.wsgi'
+ 'wsgi', self.env['PROJECT_NAME']) + '.wsgi'
+
+ self.env['WSGI_DIR'] = os.path.dirname(self.env['WSGI_FILE'])
if 'WSGI_SOURCE_FILE' not in self.env:
self.env['WSGI_SOURCE_FILE'] = 'wsgi_app.template'
os.system("touch %s" % self.env['WSGI_FILE'])
def update_config(self):
+ super(WSGISite, self).update_config()
+
source = self.find_resource(self.env['WSGI_SOURCE_FILE'])
self.render_template(source, self.env['WSGI_FILE'])
+
class PIPSite(DeploySite):
def install_dependencies(self):
self.info("Installing requirements")
- os.system("pip install -r %s" % self.find_resource('requirements.txt'))
+ os.system("%s install -r %s" % (self.env['PIP_BIN'], self.find_resource('requirements.txt')))
try:
self.info("Installing local requirements")
- os.system("pip install -r %s" % self.find_resource('requirements_local.txt'))
+ os.system("%s install -r %s" % (self.env['PIP_BIN'], self.find_resource('requirements_local.txt')))
except ValueError:
pass
+
class GitSite(DeploySite):
def update_app(self):
self.info("Updating repository.")
os.system("cd %s; git pull" % self.env['APP_DIR'])
+
class ApacheSite(DeploySite):
def __init__(self, **env):
self.env['VHOST_FILE'] = os.path.join(self.env['CONFIG_DIR'], self.env['PROJECT_NAME'] + '.vhost')
def update_config(self):
+ super(ApacheSite, self).update_config()
+
source = self.find_resource(self.env['VHOST_SOURCE_FILE'])
- self.render_template(source, self.env['VHOST_CONFIG_FILE'])
+ self.render_template(source, self.env['VHOST_FILE'])