Exemplo n.º 1
0
def _configloc():
    _, config_file_name = prmreader.get_user_dir_and_dst()
    click.echo("[cellpy] ->%s" % config_file_name)
    if not os.path.isfile(config_file_name):
        click.echo("[cellpy] File does not exist!")
    else:
        return config_file_name
Exemplo n.º 2
0
def _main():
    file_name = prmreader.create_custom_init_filename()
    click.echo(file_name)
    user_directory, destination_file_name = prmreader.get_user_dir_and_dst(file_name)
    click.echo(user_directory)
    click.echo(destination_file_name)
    click.echo("trying to save it")
    save_prm_file(destination_file_name + "_dummy")

    click.echo(" Testing setup ".center(80, "="))
    setup(["--interactive", "--reset"])
Exemplo n.º 3
0
def setup(interactive, not_relative, dry_run, reset, root_dir, testuser):
    """This will help you to setup cellpy."""

    click.echo("[cellpy] (setup)")

    # generate variables
    init_filename = prmreader.create_custom_init_filename()
    userdir, dst_file = prmreader.get_user_dir_and_dst(init_filename)

    if dry_run:
        click.echo(
            "Create custom init filename and get userdir and destination")
        click.echo(f"Got the following parameters:")
        click.echo(f" - init_filename: {init_filename}")
        click.echo(f" - userdir: {userdir}")
        click.echo(f" - dst_file: {dst_file}")
        click.echo(f" - not_relative: {not_relative}")

    if not root_dir:
        root_dir = userdir
        # root_dir = pathlib.Path(os.getcwd())
    root_dir = pathlib.Path(root_dir)
    if dry_run:
        click.echo(f" - root_dir: {root_dir}")

    if testuser:
        click.echo(f"[cellpy] (setup) DEV-MODE testuser: {testuser}")
        init_filename = prmreader.create_custom_init_filename(testuser)
        userdir = root_dir
        dst_file = get_dst_file(userdir, init_filename)
        click.echo(f"[cellpy] (setup) DEV-MODE userdir: {userdir}")
        click.echo(f"[cellpy] (setup) DEV-MODE dst_file: {dst_file}")

    if not pathlib.Path(dst_file).is_file():
        reset = True

    if interactive:
        click.echo(" interactive mode ".center(80, "-"))
        _update_paths(root_dir, not not_relative, dry_run=dry_run, reset=reset)
        _write_config_file(userdir, dst_file, init_filename, dry_run)
        _check(dry_run=dry_run)

    else:
        if reset:
            _update_paths(userdir,
                          False,
                          dry_run=dry_run,
                          reset=True,
                          silent=True)
        _write_config_file(userdir, dst_file, init_filename, dry_run)
        _check(dry_run=dry_run)
Exemplo n.º 4
0
def _write_config_file(userdir, dst_file, init_filename, dry_run):
    click.echo(" update configuration ".center(80, "-"))
    click.echo("[cellpy] (setup) Writing configurations to user directory:")
    click.echo(f"\n         {userdir}\n")

    if os.path.isfile(dst_file):
        click.echo("[cellpy] (setup) File already exists!")
        click.echo("[cellpy] (setup) Keeping most of the old configuration parameters")
    try:
        if dry_run:
            click.echo(
                f"*** dry-run: skipping actual saving of {dst_file} ***", color="red"
            )
        else:
            click.echo(f"[cellpy] (setup) Saving file ({dst_file})")
            save_prm_file(dst_file)

    except ConfigFileNotWritten:
        click.echo("[cellpy] (setup) Something went wrong! Could not write the file")
        click.echo(
            "[cellpy] (setup) Trying to write a file"
            + f"called {prmreader.DEFAULT_FILENAME} instead"
        )

        try:
            userdir, dst_file = prmreader.get_user_dir_and_dst(init_filename)
            if dry_run:
                click.echo(
                    f"*** dry-run: skipping actual saving of {dst_file} ***",
                    color="red",
                )
            else:
                save_prm_file(dst_file)

        except ConfigFileNotWritten:
            _txt = "[cellpy] (setup) No, that did not work either.\n"
            _txt += "[cellpy] (setup) Well, guess you have to talk to the developers."
            click.echo(_txt)
    else:
        click.echo(f"[cellpy] (setup) Configuration file written!")
        click.echo(
            f"[cellpy] (setup) OK! Now you can edit it. For example by "
            f"issuing \n\n         [your-favourite-editor] {init_filename}\n"
        )