def __init__(self, environ, start_response):
		self.environ = environ
		self.start_response = start_response
		from submin.models import storage
		self.storage = storage
		self.storage.open()

		# importing options is only possbile after storage.open()
		from submin.models import options

		submin_www_dir = options.static_path('www')
		os.chdir(submin_www_dir) # same behaviour as CGI script

		from submin.bootstrap import SubminInstallationCheck
		submin_dir = options.lib_path()
		check = SubminInstallationCheck(submin_dir, environ)
		if not check.ok:
			self.start_response("500 Not Ok", [])
			return check.error_page().encode("utf-8")

		os.environ['SUBMIN_ENV'] = environ['SUBMIN_ENV']

		from submin.dispatch.wsgirequest import WSGIRequest
		from submin.dispatch.dispatcher import dispatcher
		self.WSGIRequest = WSGIRequest
		self.dispatcher = dispatcher
Example #2
0
def setCommitEmailHook(reponame, enable):
    prepare(reponame)

    reposdir = repository.directory('git', reponame)
    hook_dir = reposdir + 'hooks' + 'post-receive.d'
    mkdirs(hook_dir)
    hook_dest = hook_dir + '001-commit-email.hook'

    if enable:
        variables = {
            'submin_lib_dir': options.lib_path(),
            'base_url': options.url_path('base_url_submin'),
            'http_vhost': options.http_vhost(),
            'hook_version': HOOK_VERSIONS['commit-email'],
        }
        hook = evaluate('plugins/vcs/git/post-receive', variables)
        try:
            os.unlink(hook_dest)
        except OSError as e:
            if e.errno != errno.ENOENT:
                raise

        try:
            with file(hook_dest, 'w') as f:
                f.write(hook)

            os.chmod(hook_dest, 0o755)
        except OSError as e:
            raise repository.PermissionError("Enabling hook failed: %s" %
                                             (str(e), ))
        try:
            cfg = repository.directory('git', reponame) + 'config'
            email = options.value(
                'commit_email_from',
                'Please configure commit_email_from <*****@*****.**>')

            set_git_config(cfg, 'multimailhook.emailmaxlines', '2000')
            prefix = '[%s]' % reponame
            set_git_config(cfg, 'multimailhook.emailprefix', prefix)
            set_git_config(cfg, 'multimailhook.envelopesender', email)
        except SetGitConfigError as e:
            raise repository.PermissionError(
                "Enabling hook succeeded, but configuring it failed: %s" %
                (str(e)))
    else:
        try:
            os.unlink(hook_dest)
        except OSError as e:
            if e.errno != errno.ENOENT:
                raise repository.PermissionError("Removing hook failed: %s" %
                                                 (str(e), ))
Example #3
0
def setCommitEmailHook(reponame, enable):
	prepare(reponame)

	reposdir = repository.directory('git', reponame)
	hook_dir = reposdir + 'hooks' + 'post-receive.d'
	mkdirs(hook_dir)
	hook_dest = hook_dir + '001-commit-email.hook'

	if enable:
		variables = {
			'submin_lib_dir': options.lib_path(),
			'base_url': options.url_path('base_url_submin'),
			'http_vhost': options.http_vhost(),
			'hook_version': HOOK_VERSIONS['commit-email'],
		}
		hook = evaluate('plugins/vcs/git/post-receive', variables)
		try:
			os.unlink(hook_dest)
		except OSError as e:
			if e.errno != errno.ENOENT:
				raise

		try:
			with file(hook_dest, 'w') as f:
				f.write(hook)

			os.chmod(hook_dest, 0o755)
		except OSError as e:
			raise repository.PermissionError(
				"Enabling hook failed: %s" % (str(e),))
		try:
			cfg = repository.directory('git', reponame) + 'config'
			email = options.value('commit_email_from',
				'Please configure commit_email_from <*****@*****.**>')

			set_git_config(cfg, 'multimailhook.emailmaxlines', '2000')
			prefix = '[%s]' % reponame
			set_git_config(cfg, 'multimailhook.emailprefix', prefix)
			set_git_config(cfg, 'multimailhook.envelopesender', email)
		except SetGitConfigError as e:
			raise repository.PermissionError(
				"Enabling hook succeeded, but configuring it failed: %s" %
				(str(e)))
	else:
		try:
			os.unlink(hook_dest)
		except OSError as e:
			if e.errno != errno.ENOENT:
				raise repository.PermissionError(
					"Removing hook failed: %s" % (str(e),))
Example #4
0
import os
import sys
import re

from submin.models import storage
from submin.models.user import User
from submin.models import options

# add to python_path so we can import git_multimail
LIBDIR = os.path.join(options.lib_path(), 'static/hooks/git')
sys.path.append(LIBDIR)

import git_multimail

FOOTER_TEMPLATE = """

--
This message was sent by Submin through git_multimail.
To unsubscribe from this commit list, please login to {http_vhost}{base_url} and change your preferences.
"""

class Config(git_multimail.Config):
	"""Allow overrides without having to write them everytime to git config"""
	overrides = {}

	def set_override(self, var, val):
		self.overrides[var] = val

	def get(self, var, *args, **kwargs):
		if var in self.overrides:
			return self.overrides[var]