add support for new project creation

Closes #3524
This commit is contained in:
Jérôme Schneider 2014-04-27 13:11:59 +02:00
parent 813caf14ed
commit 5c65415c46
35 changed files with 111 additions and 51 deletions

View File

@ -4,4 +4,4 @@ include mandaye/alembic.ini
recursive-include mandaye/alembic *
recursive-include mandaye/templates *.html
recursive-include skel *
recursive-include mandya/skel *

View File

@ -40,6 +40,8 @@ static_url = '/mandaye/static'
static_root = os.path.join(_PROJECT_PATH, 'mandaye/static')
# Data dir
data_dir = os.path.join(_PROJECT_PATH, 'data')
# Skel root
skel_root = os.path.join(_PROJECT_PATH, 'mandaye/skel')
# Email notification configuration
email_notification = False

3
mandaye/skel/MANIFEST.in Normal file
View File

@ -0,0 +1,3 @@
include COPYING MANIFEST.in VERSION
recursive-include {project_name}/templates *.html
recursive-include {project_name}/static *

View File

@ -0,0 +1 @@
__version__="0.1"

View File

@ -4,7 +4,7 @@ import os
_PROJECT_PATH = os.path.join(os.path.dirname(__file__), '..')
## Virtual hosts configuration
hosts = {}
hosts = {{}}
## SQL Backend config
# Database configuration
@ -16,7 +16,7 @@ db_url = 'sqlite:///' + os.path.join(_PROJECT_PATH, 'test.db')
## Log configuration
debug = False
syslog = False
log_file = os.path.join(_PROJECT_PATH, '{module_name}/{module_name}.log')
log_file = os.path.join(_PROJECT_PATH, '{project_name}/{project_name}.log')
log_level = logging.INFO
# Log rotation
# W[0-6] : weekly (0: Monday), D: day, ... (python doc)
@ -28,11 +28,11 @@ log_backup = 52
## PATH
# Template directory
template_directory = os.path.join(_PROJECT_PATH, '{module_name}/templates')
template_directory = os.path.join(_PROJECT_PATH, '{project_name}/templates')
# Static url
static_url = '/mandaye/static'
# Static folder
static_root = os.path.join(_PROJECT_PATH, '{module_name}/static')
static_root = os.path.join(_PROJECT_PATH, '{project_name}/static')
# Data dir
data_dir = os.path.join(_PROJECT_PATH, 'data')
@ -61,12 +61,12 @@ encrypt_sp_password = False
encrypt_secret = ''
# Beaker session configuration
session_opts = {
session_opts = {{
'session.type': 'file',
'session.cookie_expires': True,
'session.timeout': 3600,
'session.data_dir': '/var/tmp/beaker'
}
}}
# Choose storage
# Only mandaye.backends.sql at the moment
@ -127,8 +127,7 @@ TKX6tp6oI+7MIJE6ySZ0cBqOiydAkBePZhu57j6ToBkTa0dbHjn1WA==
# Import local config
try:
from ..{module_name}.local_config import *
except ImportError, e:
if not 'local_config' in e.args[0]:
raise ImproperlyConfigured('Error while importing "local_config.py"')
from ..{project_name}.local_config import *
except:
pass

View File

@ -1,48 +1,48 @@
from {module_name}.auth.example import MyAuthSAML
from {module_name}.filters.example import ReplayFilter
from {project_name}.auth.example import MyAuthSAML
from {project_name}.filters.example import ReplayFilter
from mandaye.configs import saml2 as saml2_config
form_values = {
form_values = {{
'login_url': '/compte/connexion',
'form_attrs': { 'id': 'new_account' },
'form_attrs': {{ 'id': 'new_account' }},
'post_fields': ['account[login]', 'account[password]'],
'username_field': 'account[login]',
'password_field': 'account[password]',
}
}}
auth = MyAuthSAML(form_values, 'linuxfr', saml2_config)
linuxfr_mapping = [
{
{{
'path': r'/mandaye/associate$',
'method': 'GET',
'on_response': [{
'on_response': [{{
'filter': ReplayFilter.associate,
'values': {
'values': {{
'action': '/mandaye/associate',
'template': 'associate.html',
'sp_name': 'Linux FR',
'login_name': form_values['username_field'],
'password_name': form_values['password_field'],
},
},]
},
{
}},
}},]
}},
{{
'path': r'/mandaye/associate$',
'method': 'POST',
'response': [
{
{{
'filter': auth.associate_submit,
'values': {
'values': {{
'connection_url': '/mandaye/sso',
'associate_url': '/mandaye/associate',
},
}},
'condition': "response.code==302"
},
}},
]
},
}},
]
linuxfr_mapping.extend(auth.get_default_mapping())

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 8.2 KiB

After

Width:  |  Height:  |  Size: 8.2 KiB

View File

Before

Width:  |  Height:  |  Size: 407 B

After

Width:  |  Height:  |  Size: 407 B

View File

Before

Width:  |  Height:  |  Size: 158 B

After

Width:  |  Height:  |  Size: 158 B

View File

Before

Width:  |  Height:  |  Size: 43 B

After

Width:  |  Height:  |  Size: 43 B

View File

Before

Width:  |  Height:  |  Size: 367 B

After

Width:  |  Height:  |  Size: 367 B

View File

Before

Width:  |  Height:  |  Size: 121 B

After

Width:  |  Height:  |  Size: 121 B

View File

Before

Width:  |  Height:  |  Size: 295 B

After

Width:  |  Height:  |  Size: 295 B

View File

Before

Width:  |  Height:  |  Size: 222 B

After

Width:  |  Height:  |  Size: 222 B

View File

Before

Width:  |  Height:  |  Size: 7.6 KiB

After

Width:  |  Height:  |  Size: 7.6 KiB

View File

Before

Width:  |  Height:  |  Size: 666 B

After

Width:  |  Height:  |  Size: 666 B

View File

Before

Width:  |  Height:  |  Size: 781 B

After

Width:  |  Height:  |  Size: 781 B

View File

@ -3,10 +3,10 @@ import os
from mandaye.server import MandayeApp
from {module_name} import config
from {project_name} import config
from beaker.middleware import SessionMiddleware
os.environ['MANDAYE_CONFIG_MODULE'] = '{module_name}.config'
os.environ['MANDAYE_CONFIG_MODULE'] = '{project_name}.config'
application = SessionMiddleware(MandayeApp(), config.session_opts)

View File

@ -1,14 +1,14 @@
## Virtual hosts configuration
hosts = {
hosts = {{
'linuxfrsaml.local:8000': [
{
{{
'path': r'/',
'target': 'http://linuxfr.org',
'mapping': '{module_name}.configs.linuxfr_saml_example.linuxfr_mapping'
},
'mapping': '{project_name}.configs.linuxfr_saml_example.linuxfr_mapping'
}},
],
}
}}
## SQL Backend config
# http://docs.sqlalchemy.org/en/rel_0_7/core/engines.html

View File

@ -5,7 +5,7 @@
"""
import os
os.environ['MANDAYE_CONFIG_MODULE'] = '{module_name}.config'
os.environ['MANDAYE_CONFIG_MODULE'] = '{project_name}.config'
import base64

View File

@ -5,7 +5,7 @@
"""
import os
os.environ['MANDAYE_CONFIG_MODULE'] = '{module_name}.config'
os.environ['MANDAYE_CONFIG_MODULE'] = '{project_name}.config'
import sys
@ -15,8 +15,8 @@ from gunicorn.app.wsgiapp import WSGIApplication
class MandayeWSGIApplication(WSGIApplication):
def init(self, parser, opts, args):
self.cfg.set("default_proc_name", "{module_name}.wsgi:application")
self.app_uri = "{module_name}.wsgi:application"
self.cfg.set("default_proc_name", "{project_name}.wsgi:application")
self.app_uri = "{project_name}.wsgi:application"
def main():
""" The ``gunicorn`` command line runner for launcing Gunicorn with

View File

@ -10,7 +10,7 @@ import subprocess
from setuptools import setup, find_packages
from sys import version
import {module_name}
import {project_name}
install_requires=[
'gunicorn>=0.17',
@ -29,7 +29,7 @@ def get_version():
result = p.communicate()[0]
version = result.split()[0][1:]
return version.replace('-','.')
return {module_name}.VERSION
return {project_name}.__version__
setup(name="{project_name}",
version=get_version(),
@ -40,7 +40,7 @@ setup(name="{project_name}",
author_email="author@example.com",
maintainer="Maintainer",
maintainer_email="maintainer@exmaple.com",
scripts=['{module_name}_manager', '{module_name}_server'],
scripts=['{project_name}_manager', '{project_name}_server'],
packages=find_packages(),
include_package_data=True,
install_requires=install_requires

View File

@ -1,5 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" Script to manage mandaye project
"""

63
scripts/mandaye-admin.py Executable file
View File

@ -0,0 +1,63 @@
#! /usr/bin/python
# -*- coding: utf-8 -*-
""" Script to create mandaye projects
"""
import os
import re
import shutil
import sys
from optparse import OptionParser
from mandaye import config, global_config
from mandaye.log import logger
def get_cmd_options():
usage = "usage: %prog --newproject"
parser = OptionParser(usage=usage)
parser.add_option("-n", "--newproject",
dest="project_name",
metavar="PROJECT_NAME",
help="PROJECT_NAME: the name of teh new mandaye's project"
)
(options, args) = parser.parse_args()
if not options.project_name:
parser.error("You must set --newproject option")
if options.project_name:
if not re.search(r'^[_a-zA-Z]\w*$', options.project_name):
parser.error("project_name %s is not a valid name."
"Please use use only numbers, letters and underscores.")
return options
def main():
options = get_cmd_options()
if options.project_name:
project_name = options.project_name
module = os.path.join(project_name,
project_name)
modue_example = os.path.join(project_name,
"example.module")
skel = global_config.skel_root
logger.info("Creating project %s ..." % project_name)
if os.path.exists(project_name):
print "%s folder already exist" % project_name
sys.exit(1)
shutil.copytree(skel, project_name)
for root, dirs, files in os.walk(project_name):
if not "templates" in root and not "static" in root:
print root
for filename in files:
file_path = os.path.join(root, filename)
print file_path
with open(file_path, "r") as f:
content = f.read()
with open(file_path, "w") as f:
print content.format(project_name=project_name)
f.write(content.format(project_name=project_name))
shutil.move(modue_example, module)
if __name__ == "__main__":
main()

View File

@ -48,7 +48,7 @@ setup(name="mandaye",
author_email="info@entrouvert.org",
maintainer="Jerome Schneider",
maintainer_email="jschneider@entrouvert.com",
scripts=['scripts/mandaye-admin'],
scripts=['scripts/mandaye-admin.py'],
include_package_data = True,
packages=find_packages(),
install_requires=install_requires

View File

@ -1,3 +0,0 @@
include COPYING MANIFEST.in VERSION
recursive-include {module_name}/templates *.html
recursive-include {module_name}/static *