Update configuration to work with the mast mandaye version
This commit is contained in:
parent
39e6417b3c
commit
01e2c477f9
|
@ -1 +1,6 @@
|
|||
VERSION="0.1"
|
||||
__version__="0.2.0"
|
||||
|
||||
import os
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
default_config = os.path.join(BASE_DIR, 'default-config.ini')
|
||||
|
|
|
@ -5,6 +5,7 @@ base_dir: .
|
|||
url: sqlite:///%(base_dir)s/cam.db
|
||||
|
||||
[dirs]
|
||||
module_name: cam
|
||||
config_root: %(base_dir)s/conf.d
|
||||
data_dir: %(base_dir)s/data
|
||||
static_root: %(base_dir)s/cam/static
|
||||
|
@ -18,6 +19,7 @@ log_debug: false
|
|||
sentry_dsn:
|
||||
|
||||
[mandaye]
|
||||
toolbar: false
|
||||
; only sql at the moment
|
||||
storage_backend: sql
|
||||
auto_decompress: true
|
||||
|
|
20
cam/wsgi.py
20
cam/wsgi.py
|
@ -1,17 +1,27 @@
|
|||
|
||||
import os
|
||||
from cam import default_config
|
||||
|
||||
from mandaye.server import MandayeApp
|
||||
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 cam import config
|
||||
from beaker.middleware import SessionMiddleware
|
||||
from whitenoise import WhiteNoise
|
||||
|
||||
os.environ['MANDAYE_CONFIG_MODULE'] = 'cam.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,78 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
""" Script to administrate mandaye server
|
||||
"""
|
||||
|
||||
import os
|
||||
os.environ['MANDAYE_CONFIG_MODULE'] = 'cam.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|--cryptpwd"
|
||||
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 options.cryptpwd:
|
||||
pass
|
||||
#from mandaye.backends.default import ManagerSPUser
|
||||
#for user in ManagerSPUser.all():
|
||||
# user.password = encrypt_pwd(user.password)
|
||||
#ManagerSPUser.save()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
#! /usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
""" Script to administrate mandaye server
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from optparse import OptionParser
|
||||
from cam 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()
|
||||
|
|
@ -5,11 +5,8 @@
|
|||
"""
|
||||
|
||||
import os
|
||||
os.environ['MANDAYE_CONFIG_MODULE'] = 'cam.config'
|
||||
|
||||
import sys
|
||||
|
||||
from mandaye.log import logger
|
||||
from gunicorn.app.wsgiapp import WSGIApplication
|
||||
|
||||
class MandayeWSGIApplication(WSGIApplication):
|
||||
|
@ -22,7 +19,16 @@ def main():
|
|||
""" The ``gunicorn`` command line runner for launcing Gunicorn with
|
||||
generic WSGI applications.
|
||||
"""
|
||||
logger.info('CAM 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
|
@ -27,7 +27,7 @@ def get_version():
|
|||
result = p.communicate()[0]
|
||||
return result.split()[0].replace('-','.')
|
||||
import cam
|
||||
return cam.VERSION
|
||||
return cam.__version__
|
||||
|
||||
setup(name="mandaye-cam",
|
||||
version=get_version(),
|
||||
|
@ -38,7 +38,7 @@ setup(name="mandaye-cam",
|
|||
author_email="info@entrouvert.org",
|
||||
maintainer="Jerome Schneider",
|
||||
maintainer_email="jschneider@entrouvert.com",
|
||||
scripts=['cam_mandaye_manager', 'cam_mandaye_server'],
|
||||
scripts=['manager.py', 'server.py'],
|
||||
packages=find_packages(),
|
||||
include_package_data=True,
|
||||
install_requires=install_requires
|
||||
|
|
Reference in New Issue