From 5c65415c46fefdf826e61ee12da6f5b4171924cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Schneider?= Date: Sun, 27 Apr 2014 13:11:59 +0200 Subject: [PATCH] add support for new project creation Closes #3524 --- MANIFEST.in | 2 +- mandaye/global_config.py | 2 + mandaye/skel/MANIFEST.in | 3 + {skel => mandaye/skel}/data/README | 0 mandaye/skel/example.module/__init__.py | 1 + mandaye/skel/example.module/auth/__init__.py | 0 .../skel}/example.module/auth/example.py | 0 .../skel}/example.module/config.py | 19 +++--- .../configs/linuxfr_saml_example.py | 34 +++++----- .../skel/example.module/filters/__init__.py | 0 .../skel}/example.module/filters/example.py | 0 .../skel}/example.module/static/css/style.css | 0 .../skel}/example.module/static/images/a1.gif | Bin .../example.module/static/images/a10.jpg | Bin .../example.module/static/images/a16.gif | Bin .../example.module/static/images/a18.gif | Bin .../example.module/static/images/a22.gif | Bin .../example.module/static/images/a33.gif | Bin .../example.module/static/images/a50.gif | Bin .../skel}/example.module/static/images/a8.gif | Bin .../skel}/example.module/static/images/a8.png | Bin .../skel}/example.module/static/images/eo.png | Bin .../skel}/example.module/static/images/ko.png | Bin .../skel}/example.module/static/images/ok.png | Bin .../example.module/templates/associate.html | 0 {skel => mandaye/skel}/example.module/wsgi.py | 4 +- .../skel}/local_config.py.example | 10 +-- .../skel/manager.py | 2 +- {skel => mandaye/skel}/requirements.txt | 0 .../server.template => mandaye/skel/server.py | 6 +- .../skel/setup.py | 6 +- scripts/mandaye-admin | 5 -- scripts/mandaye-admin.py | 63 ++++++++++++++++++ setup.py | 2 +- skel/MANIFEST.in | 3 - 35 files changed, 111 insertions(+), 51 deletions(-) create mode 100644 mandaye/skel/MANIFEST.in rename {skel => mandaye/skel}/data/README (100%) create mode 100644 mandaye/skel/example.module/__init__.py create mode 100644 mandaye/skel/example.module/auth/__init__.py rename {skel => mandaye/skel}/example.module/auth/example.py (100%) rename {skel => mandaye/skel}/example.module/config.py (91%) rename {skel => mandaye/skel}/example.module/configs/linuxfr_saml_example.py (71%) create mode 100644 mandaye/skel/example.module/filters/__init__.py rename {skel => mandaye/skel}/example.module/filters/example.py (100%) rename {skel => mandaye/skel}/example.module/static/css/style.css (100%) rename {skel => mandaye/skel}/example.module/static/images/a1.gif (100%) rename {skel => mandaye/skel}/example.module/static/images/a10.jpg (100%) rename {skel => mandaye/skel}/example.module/static/images/a16.gif (100%) rename {skel => mandaye/skel}/example.module/static/images/a18.gif (100%) rename {skel => mandaye/skel}/example.module/static/images/a22.gif (100%) rename {skel => mandaye/skel}/example.module/static/images/a33.gif (100%) rename {skel => mandaye/skel}/example.module/static/images/a50.gif (100%) rename {skel => mandaye/skel}/example.module/static/images/a8.gif (100%) rename {skel => mandaye/skel}/example.module/static/images/a8.png (100%) rename {skel => mandaye/skel}/example.module/static/images/eo.png (100%) rename {skel => mandaye/skel}/example.module/static/images/ko.png (100%) rename {skel => mandaye/skel}/example.module/static/images/ok.png (100%) rename {skel => mandaye/skel}/example.module/templates/associate.html (100%) rename {skel => mandaye/skel}/example.module/wsgi.py (63%) rename {skel => mandaye/skel}/local_config.py.example (73%) rename skel/manager.template => mandaye/skel/manager.py (97%) rename {skel => mandaye/skel}/requirements.txt (100%) rename skel/server.template => mandaye/skel/server.py (74%) rename skel/setup.py.template => mandaye/skel/setup.py (90%) delete mode 100755 scripts/mandaye-admin create mode 100755 scripts/mandaye-admin.py delete mode 100644 skel/MANIFEST.in diff --git a/MANIFEST.in b/MANIFEST.in index 4c071b6..7d4cf72 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -4,4 +4,4 @@ include mandaye/alembic.ini recursive-include mandaye/alembic * recursive-include mandaye/templates *.html -recursive-include skel * +recursive-include mandya/skel * diff --git a/mandaye/global_config.py b/mandaye/global_config.py index eb6be3f..d7f8192 100644 --- a/mandaye/global_config.py +++ b/mandaye/global_config.py @@ -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 diff --git a/mandaye/skel/MANIFEST.in b/mandaye/skel/MANIFEST.in new file mode 100644 index 0000000..50d6756 --- /dev/null +++ b/mandaye/skel/MANIFEST.in @@ -0,0 +1,3 @@ +include COPYING MANIFEST.in VERSION +recursive-include {project_name}/templates *.html +recursive-include {project_name}/static * diff --git a/skel/data/README b/mandaye/skel/data/README similarity index 100% rename from skel/data/README rename to mandaye/skel/data/README diff --git a/mandaye/skel/example.module/__init__.py b/mandaye/skel/example.module/__init__.py new file mode 100644 index 0000000..1bb629e --- /dev/null +++ b/mandaye/skel/example.module/__init__.py @@ -0,0 +1 @@ +__version__="0.1" diff --git a/mandaye/skel/example.module/auth/__init__.py b/mandaye/skel/example.module/auth/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/skel/example.module/auth/example.py b/mandaye/skel/example.module/auth/example.py similarity index 100% rename from skel/example.module/auth/example.py rename to mandaye/skel/example.module/auth/example.py diff --git a/skel/example.module/config.py b/mandaye/skel/example.module/config.py similarity index 91% rename from skel/example.module/config.py rename to mandaye/skel/example.module/config.py index ccc272e..2b9c47c 100644 --- a/skel/example.module/config.py +++ b/mandaye/skel/example.module/config.py @@ -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 diff --git a/skel/example.module/configs/linuxfr_saml_example.py b/mandaye/skel/example.module/configs/linuxfr_saml_example.py similarity index 71% rename from skel/example.module/configs/linuxfr_saml_example.py rename to mandaye/skel/example.module/configs/linuxfr_saml_example.py index ca3742f..1165127 100644 --- a/skel/example.module/configs/linuxfr_saml_example.py +++ b/mandaye/skel/example.module/configs/linuxfr_saml_example.py @@ -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()) diff --git a/mandaye/skel/example.module/filters/__init__.py b/mandaye/skel/example.module/filters/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/skel/example.module/filters/example.py b/mandaye/skel/example.module/filters/example.py similarity index 100% rename from skel/example.module/filters/example.py rename to mandaye/skel/example.module/filters/example.py diff --git a/skel/example.module/static/css/style.css b/mandaye/skel/example.module/static/css/style.css similarity index 100% rename from skel/example.module/static/css/style.css rename to mandaye/skel/example.module/static/css/style.css diff --git a/skel/example.module/static/images/a1.gif b/mandaye/skel/example.module/static/images/a1.gif similarity index 100% rename from skel/example.module/static/images/a1.gif rename to mandaye/skel/example.module/static/images/a1.gif diff --git a/skel/example.module/static/images/a10.jpg b/mandaye/skel/example.module/static/images/a10.jpg similarity index 100% rename from skel/example.module/static/images/a10.jpg rename to mandaye/skel/example.module/static/images/a10.jpg diff --git a/skel/example.module/static/images/a16.gif b/mandaye/skel/example.module/static/images/a16.gif similarity index 100% rename from skel/example.module/static/images/a16.gif rename to mandaye/skel/example.module/static/images/a16.gif diff --git a/skel/example.module/static/images/a18.gif b/mandaye/skel/example.module/static/images/a18.gif similarity index 100% rename from skel/example.module/static/images/a18.gif rename to mandaye/skel/example.module/static/images/a18.gif diff --git a/skel/example.module/static/images/a22.gif b/mandaye/skel/example.module/static/images/a22.gif similarity index 100% rename from skel/example.module/static/images/a22.gif rename to mandaye/skel/example.module/static/images/a22.gif diff --git a/skel/example.module/static/images/a33.gif b/mandaye/skel/example.module/static/images/a33.gif similarity index 100% rename from skel/example.module/static/images/a33.gif rename to mandaye/skel/example.module/static/images/a33.gif diff --git a/skel/example.module/static/images/a50.gif b/mandaye/skel/example.module/static/images/a50.gif similarity index 100% rename from skel/example.module/static/images/a50.gif rename to mandaye/skel/example.module/static/images/a50.gif diff --git a/skel/example.module/static/images/a8.gif b/mandaye/skel/example.module/static/images/a8.gif similarity index 100% rename from skel/example.module/static/images/a8.gif rename to mandaye/skel/example.module/static/images/a8.gif diff --git a/skel/example.module/static/images/a8.png b/mandaye/skel/example.module/static/images/a8.png similarity index 100% rename from skel/example.module/static/images/a8.png rename to mandaye/skel/example.module/static/images/a8.png diff --git a/skel/example.module/static/images/eo.png b/mandaye/skel/example.module/static/images/eo.png similarity index 100% rename from skel/example.module/static/images/eo.png rename to mandaye/skel/example.module/static/images/eo.png diff --git a/skel/example.module/static/images/ko.png b/mandaye/skel/example.module/static/images/ko.png similarity index 100% rename from skel/example.module/static/images/ko.png rename to mandaye/skel/example.module/static/images/ko.png diff --git a/skel/example.module/static/images/ok.png b/mandaye/skel/example.module/static/images/ok.png similarity index 100% rename from skel/example.module/static/images/ok.png rename to mandaye/skel/example.module/static/images/ok.png diff --git a/skel/example.module/templates/associate.html b/mandaye/skel/example.module/templates/associate.html similarity index 100% rename from skel/example.module/templates/associate.html rename to mandaye/skel/example.module/templates/associate.html diff --git a/skel/example.module/wsgi.py b/mandaye/skel/example.module/wsgi.py similarity index 63% rename from skel/example.module/wsgi.py rename to mandaye/skel/example.module/wsgi.py index a676882..b967d5a 100644 --- a/skel/example.module/wsgi.py +++ b/mandaye/skel/example.module/wsgi.py @@ -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) diff --git a/skel/local_config.py.example b/mandaye/skel/local_config.py.example similarity index 73% rename from skel/local_config.py.example rename to mandaye/skel/local_config.py.example index 30d41a1..a88f84d 100644 --- a/skel/local_config.py.example +++ b/mandaye/skel/local_config.py.example @@ -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 diff --git a/skel/manager.template b/mandaye/skel/manager.py similarity index 97% rename from skel/manager.template rename to mandaye/skel/manager.py index b5e6821..34a32b1 100755 --- a/skel/manager.template +++ b/mandaye/skel/manager.py @@ -5,7 +5,7 @@ """ import os -os.environ['MANDAYE_CONFIG_MODULE'] = '{module_name}.config' +os.environ['MANDAYE_CONFIG_MODULE'] = '{project_name}.config' import base64 diff --git a/skel/requirements.txt b/mandaye/skel/requirements.txt similarity index 100% rename from skel/requirements.txt rename to mandaye/skel/requirements.txt diff --git a/skel/server.template b/mandaye/skel/server.py similarity index 74% rename from skel/server.template rename to mandaye/skel/server.py index 65c8d9a..2bd3447 100755 --- a/skel/server.template +++ b/mandaye/skel/server.py @@ -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 diff --git a/skel/setup.py.template b/mandaye/skel/setup.py similarity index 90% rename from skel/setup.py.template rename to mandaye/skel/setup.py index 6fee003..925833c 100644 --- a/skel/setup.py.template +++ b/mandaye/skel/setup.py @@ -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 diff --git a/scripts/mandaye-admin b/scripts/mandaye-admin deleted file mode 100755 index 08bd871..0000000 --- a/scripts/mandaye-admin +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -""" Script to manage mandaye project -""" diff --git a/scripts/mandaye-admin.py b/scripts/mandaye-admin.py new file mode 100755 index 0000000..d8a17c1 --- /dev/null +++ b/scripts/mandaye-admin.py @@ -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() + diff --git a/setup.py b/setup.py index 4d91f65..d97b266 100644 --- a/setup.py +++ b/setup.py @@ -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 diff --git a/skel/MANIFEST.in b/skel/MANIFEST.in deleted file mode 100644 index 40d7924..0000000 --- a/skel/MANIFEST.in +++ /dev/null @@ -1,3 +0,0 @@ -include COPYING MANIFEST.in VERSION -recursive-include {module_name}/templates *.html -recursive-include {module_name}/static *