Пример #1
0
def _two_to_one(datadir):
    """After this command, your environment will be converted to format version {}
and will not work with Datacats versions beyond and including 1.0.0.
This format version doesn't support multiple sites, and after this only your
"primary" site will be usable, though other sites will be maintained if you
wish to do a migration back to a version which supports multisite.

Would you like to continue the migration? (y/n) [n]:"""
    _, env_name = _split_path(datadir)

    print 'Making sure that containers are stopped...'
    # New-style names
    remove_container('datacats_web_{}_primary'.format(env_name))
    remove_container('datacats_postgres_{}_primary'.format(env_name))
    remove_container('datacats_solr_{}_primary'.format(env_name))

    print 'Doing conversion...'

    if exists(path_join(datadir, '.version')):
        os.remove(path_join(datadir, '.version'))

    to_move = (['files', 'passwords.ini', 'run', 'solr'] +
               (['postgres'] if not is_boot2docker() else []))

    web_command(
        command=['/scripts/migrate.sh',
                 '/project/data/sites/primary',
                 '/project/data'] + to_move,
        ro={scripts.get_script_path('migrate.sh'): '/scripts/migrate.sh'},
        rw={datadir: '/project/data'}
    )

    pgdata_name = 'datacats_pgdata_{}_primary'.format(env_name)
    if is_boot2docker() and inspect_container(pgdata_name):
        rename_container(pgdata_name, 'datacats_pgdata_{}'.format(env_name))

    print 'Doing cleanup...'
    with open(path_join(datadir, 'project-dir')) as pd:
        datacats_env_location = path_join(pd.read(), '.datacats-environment')

    cp = SafeConfigParser()
    cp.read(datacats_env_location)

    # We need to move the port OUT of site_primary section and INTO datacats
    cp.set('datacats', 'port', cp.get('site_primary', 'port'))
    cp.remove_section('site_primary')

    with open(datacats_env_location, 'w') as config:
        cp.write(config)

    cp = SafeConfigParser()
    cp.read(path_join(datadir, 'passwords.ini'))

    # This isn't needed in this version
    cp.remove_option('passwords', 'beaker_session_secret')

    with open(path_join(datadir, 'passwords.ini'), 'w') as config:
        cp.write(config)
Пример #2
0
def _one_to_two(datadir):
    """After this command, your environment will be converted to format version {}.
and will only work with datacats version exceeding and including 1.0.0.
This migration is necessary to support multiple sites within the same environment.
Your current site will be kept and will be named "primary".

Would you like to continue the migration? (y/n) [n]:"""
    new_site_name = 'primary'

    split = _split_path(datadir)

    print 'Making sure that containers are stopped...'
    env_name = split[1]
    # Old-style names on purpose! We need to stop old containers!
    remove_container('datacats_web_' + env_name)
    remove_container('datacats_solr_' + env_name)
    remove_container('datacats_postgres_' + env_name)

    print 'Doing conversion...'
    # Begin the actual conversion
    to_move = (['files', 'passwords.ini', 'run', 'solr'] +
               (['postgres'] if not is_boot2docker() else []))
    # Make a primary site
    site_path = path_join(datadir, 'sites', new_site_name)
    if not exists(site_path):
        makedirs(site_path)

    web_command(
        command=['/scripts/migrate.sh',
                 '/project/data',
                 '/project/data/sites/' + new_site_name] +
        to_move,
        ro={scripts.get_script_path('migrate.sh'): '/scripts/migrate.sh'},
        rw={datadir: '/project/data'},
        clean_up=True
        )

    if is_boot2docker():
        rename_container('datacats_pgdata_' + env_name,
                         'datacats_pgdata_' + env_name + '_' + new_site_name)

    # Lastly, grab the project directory and update the ini file
    with open(path_join(datadir, 'project-dir')) as pd:
        project = pd.read()

    cp = SafeConfigParser()
    config_loc = path_join(project, '.datacats-environment')
    cp.read([config_loc])

    new_section = 'site_' + new_site_name
    cp.add_section(new_section)

    # Ports need to be moved into the new section
    port = cp.get('datacats', 'port')
    cp.remove_option('datacats', 'port')

    cp.set(new_section, 'port', port)

    with open(config_loc, 'w') as config:
        cp.write(config)

    # Make a session secret for it (make it per-site)
    cp = SafeConfigParser()
    config_loc = path_join(site_path, 'passwords.ini')
    cp.read([config_loc])

    # Generate a new secret
    cp.set('passwords', 'beaker_session_secret', generate_password())

    with open(config_loc, 'w') as config:
        cp.write(config)

    with open(path_join(datadir, '.version'), 'w') as f:
        f.write('2')