summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérôme Schneider <jschneider@entrouvert.com>2014-12-09 10:37:52 (GMT)
committerJérôme Schneider <jschneider@entrouvert.com>2014-12-09 10:39:57 (GMT)
commita363e2686b40288427b0b35503879967cdb4582a (patch)
treeaf8891a07db20c7d694e30897d2bf9431aa131b2
parente348585364f82a8236babbaa9a72fea4f59a5c62 (diff)
downloadmandaye-meyzieu-a363e2686b40288427b0b35503879967cdb4582a.zip
mandaye-meyzieu-a363e2686b40288427b0b35503879967cdb4582a.tar.gz
mandaye-meyzieu-a363e2686b40288427b0b35503879967cdb4582a.tar.bz2
port Meyzieu to the last Mandaye version
-rwxr-xr-xmanager.py56
-rw-r--r--requirements.txt2
-rw-r--r--rp_meyzieu/__init__.py5
-rw-r--r--rp_meyzieu/default-config.ini6
-rw-r--r--rp_meyzieu/wsgi.py20
-rwxr-xr-xrp_meyzieu_manager72
-rwxr-xr-xserver.py (renamed from rp_meyzieu_server)15
-rw-r--r--setup.py4
8 files changed, 95 insertions, 85 deletions
diff --git a/manager.py b/manager.py
new file mode 100755
index 0000000..c8fe9a6
--- /dev/null
+++ b/manager.py
@@ -0,0 +1,56 @@
+#! /usr/bin/python
+# -*- coding: utf-8 -*-
+
+""" Script to administrate mandaye server
+"""
+
+import os
+
+from optparse import OptionParser
+from rp_meyzieu import default_config
+
+def get_cmd_options():
+ usage = "usage: %prog --config=/path/to/config.ini --createdb|--upgradedb"
+ parser = OptionParser(usage=usage)
+ parser.add_option("--config",
+ dest="config",
+ type="string",
+ help="Path of the configuration file"
+ )
+ parser.add_option("--createdb",
+ dest="createdb",
+ default=False,
+ action="store_true",
+ help="Create Mandaye database"
+ )
+ parser.add_option("--upgradedb",
+ dest="upgradedb",
+ default=False,
+ action="store_true",
+ help="Upgrade Mandaye database"
+ )
+ (options, args) = parser.parse_args()
+ return options
+
+def main():
+ options = get_cmd_options()
+
+ config_files = [default_config]
+ if options.config:
+ config_files.append(options.config)
+ os.environ['MANDAYE_CONFIG_FILES'] = ' '.join(config_files)
+
+ from mandaye import config
+ from mandaye.log import logger
+ if options.createdb or options.upgradedb:
+ logger.info("Creating or upgrading database...")
+ from alembic.config import Config
+ from alembic import command
+ alembic_cfg = Config(config.alembic_cfg)
+ alembic_cfg.set_main_option("script_location", config.alembic_script_path)
+ command.upgrade(alembic_cfg, "head")
+ logger.info("Database upgraded")
+
+if __name__ == "__main__":
+ main()
+
diff --git a/requirements.txt b/requirements.txt
index 8096cbb..3667af9 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,3 +1,3 @@
gunicorn>=0.17
-mandaye>=0.8.0
+mandaye>=0.10.2
whitenoise>=1.0
diff --git a/rp_meyzieu/__init__.py b/rp_meyzieu/__init__.py
index d699702..a74f77d 100644
--- a/rp_meyzieu/__init__.py
+++ b/rp_meyzieu/__init__.py
@@ -1 +1,6 @@
__version__="0.2.2"
+
+import os
+
+BASE_DIR = os.path.dirname(os.path.abspath(__file__))
+default_config = os.path.join(BASE_DIR, 'default-config.ini')
diff --git a/rp_meyzieu/default-config.ini b/rp_meyzieu/default-config.ini
index 46ca86d..421b6f5 100644
--- a/rp_meyzieu/default-config.ini
+++ b/rp_meyzieu/default-config.ini
@@ -6,6 +6,7 @@ base_dir: .
url: sqlite:///%(base_dir)s/mandaye_meyzieu.db
[dirs]
+module_name: rp_meyzieu
config_root: %(base_dir)s/conf.d
data_dir: %(base_dir)s/data
static_root: %(base_dir)s/mandaye_meyzieu/static
@@ -26,7 +27,7 @@ portal_url: https://mon.meyzieu.fr
toolbar: false
offline_toolbar: false
a2_auto_connection: false
-; only sql at the moment
+; sql or ldap
storage_backend: sql
auto_decompress: true
; if you want to encypt password set to true
@@ -36,6 +37,9 @@ encrypt_sp_password: false
; must be a 16, 24, or 32 bytes long
encrypt_secret:
+[mappers]
+portail_famille_ecities: rp_meyzieu.mappers.portail_famille_ecities
+
[session]
; file, dbm, memory or memcached
; if memcached you need to install python-memcached and memcached
diff --git a/rp_meyzieu/wsgi.py b/rp_meyzieu/wsgi.py
index 034c2a3..23035fa 100644
--- a/rp_meyzieu/wsgi.py
+++ b/rp_meyzieu/wsgi.py
@@ -1,15 +1,25 @@
-
import os
+from rp_meyzieu import default_config
-os.environ.setdefault("MANDAYE_CONFIG_MODULE", "rp_meyzieu.config")
+if os.environ.has_key('MANDAYE_CONFIG_FILES'):
+ os.environ['MANDAYE_CONFIG_FILES'] = default_config + ' ' + \
+ os.environ['MANDAYE_CONFIG_FILES']
+else:
+ os.environ['MANDAYE_CONFIG_FILES'] = default_config
from beaker.middleware import SessionMiddleware
from whitenoise import WhiteNoise
-from rp_meyzieu import config
+import mandaye
+from mandaye import config
from mandaye.server import MandayeApp
+# production
application = SessionMiddleware(MandayeApp(), config.session_opts)
-application_dev = WhiteNoise(application, root=config.static_root, prefix=config.static_url)
-
+# development
+mandaye_path = os.path.dirname(mandaye.__file__)
+application_dev = WhiteNoise(application,
+ root=os.path.join(mandaye_path, 'static'),
+ prefix=config.static_url)
+application_dev.add_files(config.static_root, prefix=config.static_url)
diff --git a/rp_meyzieu_manager b/rp_meyzieu_manager
deleted file mode 100755
index c7e3785..0000000
--- a/rp_meyzieu_manager
+++ /dev/null
@@ -1,72 +0,0 @@
-#! /usr/bin/python
-# -*- coding: utf-8 -*-
-
-""" Script to administrate mandaye server
-"""
-
-import os
-os.environ['MANDAYE_CONFIG_MODULE'] = 'rp_meyzieu.config'
-
-import base64
-
-from optparse import OptionParser
-
-from mandaye import config
-from mandaye.log import logger
-
-def get_cmd_options():
- usage = "usage: %prog --createdb|--upgradedb"
- parser = OptionParser(usage=usage)
- parser.add_option("--createdb",
- dest="createdb",
- default=False,
- action="store_true",
- help="Create Mandaye database"
- )
- parser.add_option("--upgradedb",
- dest="upgradedb",
- default=False,
- action="store_true",
- help="Upgrade Mandaye database"
- )
- parser.add_option("--cryptpwd",
- dest="cryptpwd",
- default=False,
- action="store_true",
- help="Crypt external password in Mandaye's database"
- )
- (options, args) = parser.parse_args()
- return options
-
-def encrypt_pwd(pwd):
- from Crypto.Cipher import AES
- logger.debug("Encrypt password")
- enc_pwd = pwd
- if config.encrypt_secret:
- try:
- cipher = AES.new(config.encrypt_secret, AES.MODE_CFB)
- enc_pwd = cipher.encrypt(pwd)
- enc_pwd = base64.b64encode(enc_pwd)
- except Exception, e:
- if config.debug:
- traceback.print_exc()
- logger.warning('Password encrypting failed %s' % e)
- else:
- logger.warning("You must set a secret to use pwd encryption")
- return enc_pwd
-
-def main():
- options = get_cmd_options()
- if options.createdb or options.upgradedb:
- logger.info("Creating or upgrading database...")
- from alembic.config import Config
- from alembic import command
- from mandaye import global_config
- alembic_cfg = Config(global_config.alembic_cfg)
- alembic_cfg.set_main_option("script_location", global_config.alembic_script_path)
- command.upgrade(alembic_cfg, "head")
- logger.info("Database upgraded")
-
-if __name__ == "__main__":
- main()
-
diff --git a/rp_meyzieu_server b/server.py
index 0a26a84..d2f28f0 100755
--- a/rp_meyzieu_server
+++ b/server.py
@@ -5,10 +5,8 @@
"""
import os
+import sys
-os.environ.setdefault("MANDAYE_CONFIG_MODULE", "rp_meyzieu.config")
-
-from mandaye.log import logger
from gunicorn.app.wsgiapp import WSGIApplication
class MandayeWSGIApplication(WSGIApplication):
@@ -21,7 +19,16 @@ def main():
""" The ``gunicorn`` command line runner for launcing Gunicorn with
generic WSGI applications.
"""
- logger.info('rp_meyzieu reverse-proxy start')
+ config_file = None
+ config_arg_pos = None
+ for i, arg in enumerate(sys.argv[1:]):
+ if arg.startswith('--config='):
+ config_file = arg.split('=')[1]
+ config_arg_pos = i
+ if config_file:
+ os.environ['MANDAYE_CONFIG_FILES'] = config_file
+ if config_arg_pos is not None:
+ del sys.argv[config_arg_pos + 1]
MandayeWSGIApplication("%(prog)s [OPTIONS]").run()
if __name__ == "__main__":
diff --git a/setup.py b/setup.py
index b515f40..537f663 100644
--- a/setup.py
+++ b/setup.py
@@ -14,7 +14,7 @@ import rp_meyzieu
install_requires=[
'gunicorn>=0.17',
- 'mandaye>=0.8.0',
+ 'mandaye>=0.10.2',
'whitenoise>=1.0'
]
@@ -41,7 +41,7 @@ setup(name="rp_meyzieu",
author_email="author@example.com",
maintainer="Maintainer",
maintainer_email="maintainer@exmaple.com",
- scripts=['rp_meyzieu_manager', 'rp_meyzieu_server'],
+ scripts=['manager.py', 'server.py'],
packages=find_packages(),
include_package_data=True,
install_requires=install_requires