Ejemplo n.º 1
0
def _make_flat_wiz(kidfunc, *args):
    kids = map(kidfunc, *args)
    flatkids = []
    for k in kids:
        if k is None:
            continue
        flatkids.extend(k)
    wizard = wiz.Wizard(children=flatkids)
    return wizard
Ejemplo n.º 2
0
def make_xonfig_wizard(default_file=None, confirm=False, no_wizard_file=None):
    """Makes a configuration wizard for xonsh config file.

    Parameters
    ----------
    default_file : str, optional
        Default filename to save and load to. User will still be prompted.
    confirm : bool, optional
        Confirm that the main part of the wizard should be run.
    no_wizard_file : str, optional
        Filename for that will flag to future runs that the wizard should not be
        run again. If None (default), this defaults to default_file.
    """
    w = wiz.Wizard(children=[
        wiz.Message(message=WIZARD_HEAD),
        make_exit_message(),
        wiz.Message(message=WIZARD_FS),
        make_fs_wiz(),
        wiz.Message(message=WIZARD_ENV),
        wiz.YesNo(
            question=WIZARD_ENV_QUESTION, yes=make_env_wiz(), no=wiz.Pass()),
        wiz.Message(message=WIZARD_XONTRIB),
        wiz.YesNo(question=WIZARD_XONTRIB_QUESTION,
                  yes=make_xontribs_wiz(),
                  no=wiz.Pass()),
        wiz.Message(message="\n" + HR + "\n"),
        wiz.FileInserter(
            prefix="# XONSH WIZARD START",
            suffix="# XONSH WIZARD END",
            dump_rules=XONFIG_DUMP_RULES,
            default_file=default_file,
            check=True,
        ),
        wiz.Message(message=WIZARD_TAIL),
    ])
    if confirm:
        q = ("Would you like to run the xonsh configuration wizard now?\n\n"
             "1. Yes (You can abort at any time)\n"
             "2. No, but ask me next time.\n"
             "3. No, and don't ask me again.\n\n"
             "1, 2, or 3 [default: 2]? ")
        no_wizard_file = default_file if no_wizard_file is None else no_wizard_file
        passer = wiz.Pass()
        saver = wiz.SaveJSON(check=False,
                             ask_filename=False,
                             default_file=no_wizard_file)
        w = wiz.Question(q, {
            1: w,
            2: passer,
            3: saver
        },
                         converter=lambda x: int(x) if x != "" else 2)
    return w
Ejemplo n.º 3
0
def make_xonfig_wizard(default_file=None, confirm=False):
    """Makes a configuration wizard for xonsh config file.

    Parameters
    ----------
    default_file : str, optional
        Default filename to save and load to. User will still be prompted.
    confirm : bool, optional
        Confirm that the main part of the wizard should be run.
    """
    w = wiz.Wizard(children=[
        wiz.Message(message=WIZARD_HEAD),
        make_exit_message(),
        wiz.Load(default_file=default_file, check=True),
        wiz.Message(message=WIZARD_FS),
        make_fs_wiz(),
        wiz.Message(message=WIZARD_ENV),
        wiz.YesNo(
            question=WIZARD_ENV_QUESTION, yes=make_env_wiz(), no=wiz.Pass()),
        wiz.Message(message=WIZARD_XONTRIB),
        wiz.YesNo(question=WIZARD_XONTRIB_QUESTION,
                  yes=make_xontribs_wiz(),
                  no=wiz.Pass()),
        wiz.Message(message='\n' + HR + '\n'),
        wiz.Save(default_file=default_file, check=True),
        wiz.Message(message=WIZARD_TAIL),
    ])
    if confirm:
        q = ("Would you like to run the xonsh configuration wizard now?\n\n"
             "1. Yes (You can abort at any time)\n"
             "2. No, but ask me next time.\n"
             "3. No, and don't ask me again.\n\n"
             "1, 2, or 3 [default: 2]? ")
        passer = wiz.Pass()
        saver = wiz.Save(check=False,
                         ask_filename=False,
                         default_file=default_file)
        w = wiz.Question(q, {
            1: w,
            2: passer,
            3: saver
        },
                         converter=lambda x: int(x) if x != '' else 2)
    return w