storyboard/storyboard/migrate/cli.py

66 lines
2.3 KiB
Python

# Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy
# of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from oslo_config import cfg
from oslo_log import log
from storyboard.db.api import base as db_api
from storyboard.migrate.launchpad.loader import LaunchpadLoader
IMPORT_OPTS = [
cfg.StrOpt("from-project",
default="storyboard",
help="The name of the remote project to import."),
cfg.StrOpt("to-project",
default="openstack-infra/storyboard",
help="The local destination project for the remote stories."),
cfg.StrOpt("origin",
default="launchpad",
help="The origin system from which to import."),
cfg.IntOpt("auto-increment",
default=None,
help="Optionally set the auto-increment on the stories table.")
]
CONF = cfg.CONF
LOG = log.getLogger(__name__)
def main():
CONF.register_cli_opts(IMPORT_OPTS)
try:
log.register_options(CONF)
except cfg.ArgsAlreadyParsedError:
pass
log.setup(CONF, 'storyboard')
CONF(project='storyboard')
# If the user requested an autoincrement value, set that before we start
# importing things. Note that mysql will automatically set the
# autoincrement to the next-available id equal to or larger than the
# requested one.
auto_increment = CONF.auto_increment
if auto_increment:
print('Setting stories.AUTO_INCREMENT to %d' % (auto_increment,))
session = db_api.get_session(in_request=False)
session.execute('ALTER TABLE stories AUTO_INCREMENT = %d;'
% (auto_increment,))
if CONF.origin is 'launchpad':
loader = LaunchpadLoader(CONF.from_project, CONF.to_project)
loader.run()
else:
print('Unsupported import origin: %s' % CONF.origin)
return