port Meyzieu to the last Mandaye version
This commit is contained in:
parent
e348585364
commit
a363e2686b
|
@ -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()
|
||||
|
|
@ -1,3 +1,3 @@
|
|||
gunicorn>=0.17
|
||||
mandaye>=0.8.0
|
||||
mandaye>=0.10.2
|
||||
whitenoise>=1.0
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
@ -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__":
|
4
setup.py
4
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
|
||||
|
|
Reference in New Issue