# -*- coding: utf-8 -*-

import warnings
import pkg_resources

from migrate.versioning.shell import main

from pyramid.paster import get_app

def run():

    # Ignores pyramid deprecation warnings
    warnings.simplefilter('ignore', DeprecationWarning) 

    usage = """%%prog COMMAND ...

    This script is a wrapper to the sqlalchemy-migrate migrate script.

    COMMAND can be any command of sqlalchemy-migrate migrate script. See the
    sqlalchemy-migrate doc for details on its migrate script.

    This script passes the path to the c2cgeoportal migrate repository to the
    underlying migrate command.

    It also adds two options: -c|--app-config and -n|--app-name. These options
    define the target WSGI application. The --app-config option is mandatory. The
    --app-name option is mandatory, unless the value for --app-config is of
    this form: production.ini#mymapp.
    """

    parser = optparse.OptionParser()
    parser.add_option('-c', '--app-config', default='CONST_production.ini',
                      dest='app_config', help='The application config file')
    parser.add_option('-n', '--app-name', default=None,
                      dest='app_name', help='The application name')
    (options, args) = parser.parse_args()

    app_config = options.app_config
    app_name = options.app_name

    if '#' in app_config:
        if app_name is None:
            app_config, app_name = app_config.split('#', 1)
        else:
            app_config = app_config.split('#', 1)[0]

    app = get_app(app_config, app_name)
    db = app.registry.settings['sqlalchemy.url']

    repository = pkg_resources.resource_filename('c2cgeoportal', 'migration')

    main(url=db, repository=repository)

@@ -22,46 +22,8 @@
 *-%0A%0A
-import warnings%0Aimport pkg_resources%0A%0A
 from
@@ -60,17 +60,16 @@
 rt main%0A
-%0A
 from pyr
@@ -94,16 +94,70 @@
  get_app
+%0Afrom ConfigParser import ConfigParser%0Aimport warnings
 %0A%0Adef ru
@@ -161,17 +161,16 @@
  run():%0A
-%0A
     # Ig
@@ -270,1294 +270,157 @@
     
-usage = %22%22%22%25%25prog COMMAND ...%0A%0A    This script is a wrapper to the sqlalchemy-migrate migrate script.%0A%0A    COMMAND can be any command of sqlalchemy-migrate migrate script. See the%0A    sqlalchemy-migrate doc for details on its migrate script.%0A%0A    This script passes the path to the c2cgeoportal migrate repository to the%0A    underlying migrate command.%0A%0A    It also adds two options: -c%7C--app-config and -n%7C--app-name. These options%0A    define the target WSGI application. The --app-config option is mandatory. The%0A    --app-name option is mandatory, unless the value for --app-config is of%0A    this form: production.ini#mymapp.%0A    %22%22%22%0A%0A    parser = optparse.OptionParser()%0A    parser.add_option('-c', '--app-config', default='CONST_production.ini',%0A                      dest='app_config', help='The application config file')%0A    parser.add_option('-n', '--app-name', default=None,%0A                      dest='app_name', help='The application name')%0A    (options, args) = parser.parse_args()%0A%0A    app_config = options.app_config%0A    app_name = options.app_name%0A%0A    if '#' in app_config:%0A        if app_name is None:%0A            app_config, app_name = app_config.split('#', 1)%0A        else:%0A            app_config = app_config.split('#', 1)%5B0%5D%0A%0A    app = get_app(app_config, app_name)
+config = ConfigParser()%0A    config.read(%22CONST_production.ini%22)%0A    app = get_app(%22CONST_production.ini%22, config.get(%22app:c2cgeoportal%22, %22project%22))%0A
 %0A   
@@ -469,59 +469,65 @@
 l'%5D%0A
-%0A
     
-repository = pkg_resources.resource_filename('
+main(url=db, debug='False', repository='c2cgeoportal/
 c2cg
@@ -538,12 +538,9 @@
 rtal
-', '
+/
 migr
@@ -551,45 +551,4 @@
 n')%0A
-%0A    main(url=db, repository=repository)%0A

revert changeset 1728 for c2cgeoportal/scripts/manage_db.py