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')
def _one_to_two ( datadir ) : new_site_name = 'primary' split = _split_path ( datadir ) print 'Making sure that containers are stopped...' env_name = split [ 1 ] remove_container ( 'datacats_web_' + env_name ) remove_container ( 'datacats_solr_' + env_name ) remove_container ( 'datacats_postgres_' + env_name ) print 'Doing conversion...' to_move = ( [ 'files' , 'passwords.ini' , 'run' , 'solr' ] + ( [ 'postgres' ] if not is_boot2docker ( ) else [ ] ) ) 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 ) 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 ) 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 ) cp = SafeConfigParser ( ) config_loc = path_join ( site_path , 'passwords.ini' ) cp . read ( [ config_loc ] ) 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' )
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]: