예제 #1
0
파일: workflow.py 프로젝트: Kotti/Kotti
def reset_workflow_command():
    __doc__ = """Reset the workflow of all content objects in the database.

    This is useful when you want to migrate an existing database to
    use a different workflow.  When run, this script will reset all
    your content objects to use the new workflow, while trying to
    preserve workflow state information.

    For this command to work, all currently persisted states must map
    directly to a state in the new workflow.  As an example, if
    there's a 'public' object in the database, the new workflow must
    define 'public' also.

    If this is not the case, you may choose to reset all your content
    objects to the new workflow's *initial state* by passing the
    '--purge-existing' option.

    Usage:
      kotti-reset-workflow <config_uri> [--purge-existing]

    Options:
      -h --help          Show this screen.
      --purge-existing   Reset all objects to new workflow's initial state.
    """
    return command(
        lambda args: reset_workflow(purge_existing=args["--purge-existing"]), __doc__
    )
예제 #2
0
def reset_workflow_command():
    __doc__ = """Reset the workflow of all content objects in the database.

    This is useful when you want to migrate an existing database to
    use a different workflow.  When run, this script will reset all
    your content objects to use the new workflow, while trying to
    preserve workflow state information.

    For this command to work, all currently persisted states must map
    directly to a state in the new workflow.  As an example, if
    there's a 'public' object in the database, the new workflow must
    define 'public' also.

    If this is not the case, you may choose to reset all your content
    objects to the new workflow's *initial state* by passing the
    '--purge-existing' option.

    Usage:
      kotti-reset-workflow <config_uri> [--purge-existing]

    Options:
      -h --help          Show this screen.
      --purge-existing   Reset all objects to new workflow's initial state.
    """
    return command(
        lambda args: reset_workflow(purge_existing=args['--purge-existing']),
        __doc__,
    )
예제 #3
0
파일: resources.py 프로젝트: 5urprise/Kotti
def migrate_blobs_command():  # pragma: no cover
    __doc__ = """
Migrate BLOBs between the blobstore configured in the config file and the DB.

Make sure you have a backup of your data and you know what you're doing.

RUNNING THIS COMMAND WITH THE SAME OPTIONS TWICE IN A ROW WILL CAUSE PERMANENT
LOSS OF DATA!

    Usage:
      kotti-migrate-blobs <config_uri> --from-db
      kotti-migrate-blobs <config_uri> --to-db

    Options:
      --from-db   Migrate FROM the DB TO the provider configured in your config
      --to-db     Migrate TO the DB FROM the provider configured in your config
      -h --help   Show this screen.
    """

    def callback(arguments):
        migrate_blobs(
            from_db=arguments['--from-db'],
            to_db=arguments['--to-db'])

        commit()

    return command(callback, __doc__)
예제 #4
0
파일: test_util.py 프로젝트: cruxlog/Kotti
    def test_it(self):
        from kotti.util import command

        func = Mock()
        closer = Mock()
        with patch('kotti.util.docopt') as docopt:
            with patch('kotti.util.bootstrap') as bootstrap:
                docopt.return_value = {'<config_uri>': 'uri'}
                bootstrap.return_value = {'closer': closer}
                assert command(func, 'doc') == 0
                func.assert_called_with({'<config_uri>': 'uri'})
                docopt.assert_called_with('doc')
                bootstrap.assert_called_with('uri')
                assert closer.call_count == 1
예제 #5
0
    def test_it(self):
        from kotti.util import command

        func = Mock()
        closer = Mock()
        with patch("kotti.util.docopt") as docopt:
            with patch("kotti.util.bootstrap") as bootstrap:
                docopt.return_value = {"<config_uri>": "app.ini"}
                bootstrap.return_value = {"closer": closer}
                assert command(func, "doc") == 0
                func.assert_called_with({"<config_uri>": "app.ini"})
                docopt.assert_called_with("doc")
                bootstrap.assert_called_with("app.ini")
                assert closer.call_count == 1
예제 #6
0
파일: filedepot.py 프로젝트: altereg0/Kotti
def migrate_storages_command():  # pragma: no cover
    __doc__ = """ Migrate blobs between two configured filedepot storages

    Usage:
      kotti-migrate-storage <config_uri> --from-storage <name> --to-storage <name>

    Options:
      -h --help                 Show this screen.
      --from-storage <name>   The storage name that has blob data to migrate
      --to-storage <name>     The storage name where we want to put the blobs
    """
    return command(
        lambda args: migrate_storage(from_storage=args["--from-storage"], to_storage=args["--to-storage"]), __doc__
    )
예제 #7
0
파일: test_util.py 프로젝트: Kotti/Kotti
    def test_it(self):
        from kotti.util import command

        func = Mock()
        closer = Mock()
        with patch("kotti.util.docopt") as docopt:
            with patch("kotti.util.bootstrap") as bootstrap:
                docopt.return_value = {"<config_uri>": "app.ini"}
                bootstrap.return_value = {"closer": closer}
                assert command(func, "doc") == 0
                func.assert_called_with({"<config_uri>": "app.ini"})
                docopt.assert_called_with("doc")
                bootstrap.assert_called_with("app.ini")
                assert closer.call_count == 1
예제 #8
0
def migrate_storages_command():  # pragma: no cover
    __doc__ = """ Migrate blobs between two configured filedepot storages

    Usage:
      kotti-migrate-storage <config_uri> --from-storage <name> --to-storage <name>

    Options:
      -h --help                 Show this screen.
      --from-storage <name>   The storage name that has blob data to migrate
      --to-storage <name>     The storage name where we want to put the blobs
    """
    return command(
        lambda args: migrate_storage(
            from_storage=args['--from-storage'],
            to_storage=args['--to-storage'],
        ),
        __doc__,
    )
예제 #9
0
def kotti_migrate_command():
    __doc__ = """Migrate Kotti and Kotti add-ons.

    Usage:
      kotti-migrate <config_uri> list_all
      kotti-migrate <config_uri> upgrade [--scripts=<location>] [--rev=<rev>]
      kotti-migrate <config_uri> upgrade_all
      kotti-migrate <config_uri> stamp_head [--scripts=<location>] [--rev=<rev>]

    o 'list_all' prints a list of all available migrations of Kotti
      and registered add-ons.

    o 'upgrade' will run Kotti's upgrades to upgrade the database to
    the latest version.

      Use '--scripts=kotti_myaddon:alembic' to run the upgrades of the
      'kotti_myaddon' package instead.

    o 'upgrade_all' will run all upgrades of all packages registered
      with Kotti.

    o 'stamp_head' allows you to manually set the stamped version to
      the latest version inside the 'kotti_alembic_version' table,
      that is, without actually running any migrations.

      You may use this command for a different package by using the
      '--scripts' option.

    Options:
      -h --help     Show this screen.
    """
    # We need to turn off populators and root_factory when we run
    # migrations, because they would access the database, which may
    # not be possible prior to the migration.
    #
    # Unfortunately, we're not able to just set the 'kotti.populators'
    # setting to an empty list.  Since add-ons might add to this list
    # again later, when we call 'bootstrap' (and thus their
    # 'includeme' function).
    save_conf_defaults = conf_defaults.copy()

    os.environ['KOTTI_DISABLE_POPULATORS'] = '1'
    conf_defaults['kotti.root_factory'] = [lambda req: None]

    def callback(arguments):
        args = ()
        args_with_location = (arguments['--scripts'] or DEFAULT_LOCATION,)
        if arguments['list_all']:
            func = list_all
        elif arguments['upgrade']:
            func = upgrade
            args = args_with_location + (arguments['--rev'],)
        elif arguments['upgrade_all']:
            func = upgrade_all
        elif arguments['stamp_head']:
            func = stamp_head
            args = args_with_location + (arguments['--rev'],)
        func(*args)

    try:
        return command(callback, __doc__)
    finally:
        conf_defaults.clear()
        conf_defaults.update(save_conf_defaults)
        del os.environ['KOTTI_DISABLE_POPULATORS']
예제 #10
0
파일: migrate.py 프로젝트: alecnsilva/Kotti
def kotti_migrate_command():
    __doc__ = """Migrate Kotti and Kotti add-ons.

    Usage:
      kotti-migrate <config_uri> list_all
      kotti-migrate <config_uri> upgrade [--scripts=<location>] [--rev=<rev>]
      kotti-migrate <config_uri> upgrade_all
      kotti-migrate <config_uri> stamp_head [--scripts=<location>] [--rev=<rev>]

    o 'list_all' prints a list of all available migrations of Kotti
      and registered add-ons.

    o 'upgrade' will run Kotti's upgrades to upgrade the database to
    the latest version.

      Use '--scripts=kotti_myaddon:alembic' to run the upgrades of the
      'kotti_myaddon' package instead.

    o 'upgrade_all' will run all upgrades of all packages registered
      with Kotti.

    o 'stamp_head' allows you to manually set the stamped version to
      the latest version inside the 'kotti_alembic_version' table,
      that is, without actually running any migrations.

      You may use this command for a different package by using the
      '--scripts' option.

    Options:
      -h --help     Show this screen.
    """
    # We need to turn off populators and root_factory when we run
    # migrations, because they would access the database, which may
    # not be possible prior to the migration.
    #
    # Unfortunately, we're not able to just set the 'kotti.populators'
    # setting to an empty list.  Since add-ons might add to this list
    # again later, when we call 'bootstrap' (and thus their
    # 'includeme' function).
    save_conf_defaults = conf_defaults.copy()

    os.environ["KOTTI_DISABLE_POPULATORS"] = "1"
    conf_defaults["kotti.root_factory"] = [lambda req: None]

    def callback(arguments):
        args = ()
        args_with_location = (arguments["--scripts"] or DEFAULT_LOCATION,)
        if arguments["list_all"]:
            func = list_all
        elif arguments["upgrade"]:
            func = upgrade
            args = args_with_location + (arguments["--rev"],)
        elif arguments["upgrade_all"]:
            func = upgrade_all
        elif arguments["stamp_head"]:
            func = stamp_head
            args = args_with_location + (arguments["--rev"],)
        else:
            raise ValueError("Unknown command")
        func(*args)

    try:
        return command(callback, __doc__)
    finally:
        conf_defaults.clear()
        conf_defaults.update(save_conf_defaults)
        del os.environ["KOTTI_DISABLE_POPULATORS"]