예제 #1
0
def make_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.
    """
    wiz = Wizard(children=[
        Message(message=WIZARD_HEAD),
        Load(default_file=default_file, check=True),
        Message(message=WIZARD_FS),
        make_fs(),
        Message(message=WIZARD_ENV),
        YesNo(question=WIZARD_ENV_QUESTION, yes=make_env(), no=Pass()),
        Message(message='\n' + HR + '\n'),
        Save(default_file=default_file, check=True),
        Message(message=WIZARD_TAIL),
    ])
    if confirm:
        q = 'Would you like to run the xonsh configuration wizard now, ' + YN
        wiz = YesNo(question=q, yes=wiz, no=Pass())
    return wiz
예제 #2
0
파일: xonfig.py 프로젝트: pgoelz/xonsh
def make_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.
    """
    wiz = Wizard(children=[
            Message(message=WIZARD_HEAD),
            Load(default_file=default_file, check=True),
            Message(message=WIZARD_FS),
            make_fs(),
            Message(message=WIZARD_ENV),
            YesNo(question=WIZARD_ENV_QUESTION, yes=make_env(), no=Pass()),
            Message(message=WIZARD_XONTRIB),
            YesNo(question=WIZARD_XONTRIB_QUESTION, yes=make_xontribs(), no=Pass()),
            Message(message='\n' + HR + '\n'),
            Save(default_file=default_file, check=True),
            Message(message=WIZARD_TAIL),
            ])
    if confirm:
        q = ("Would you like to run the xonsh configuration wizard now?\n\n"
             "1. Yes\n2. No, but ask me later.\n3. No, and don't ask me again."
             "\n\n1, 2, or 3 [default: 2]? ")
        passer = Pass()
        saver = Save(check=False, ask_filename=False, default_file=default_file)
        wiz = Question(q, {1: wiz, 2: passer, 3: saver},
                       converter=lambda x: int(x) if x != '' else 2)
    return wiz
예제 #3
0
파일: xonfig.py 프로젝트: pgoelz/xonsh
def _make_flat_wiz(kidfunc, *args):
    kids = map(kidfunc, *args)
    flatkids = []
    for k in kids:
        if k is None:
            continue
        flatkids.extend(k)
    wiz = Wizard(children=flatkids)
    return wiz
예제 #4
0
def make_env():
    """Makes an environment variable wizard."""
    kids = map(make_envvar, sorted(builtins.__xonsh_env__.docs.keys()))
    flatkids = []
    for k in kids:
        if k is None:
            continue
        flatkids.extend(k)
    wiz = Wizard(children=flatkids)
    return wiz
예제 #5
0
# -*- coding: utf-8 -*-
"""Tests the xonsh lexer."""
from __future__ import unicode_literals, print_function
import os

import nose
from nose.tools import assert_equal, assert_true, assert_false

from xonsh.wizard import (Node, Wizard, Pass, PrettyFormatter, Message,
                          Question, StateVisitor)

TREE0 = Wizard(children=[Pass(), Message(message='yo')])
TREE1 = Question('wakka?', {'jawaka': Pass()})


def test_pretty_format_tree0():
    exp = ('Wizard(children=[\n' ' Pass(),\n' " Message('yo')\n" '])')
    obs = PrettyFormatter(TREE0).visit()
    yield assert_equal, exp, obs
    yield assert_equal, exp, str(TREE0)
    yield assert_equal, exp.replace('\n', ''), repr(TREE0)


def test_pretty_format_tree1():
    exp = ('Question(\n'
           " question='wakka?',\n"
           ' responses={\n'
           "  'jawaka': Pass()\n"
           ' }\n'
           ')')
    obs = PrettyFormatter(TREE1).visit()
예제 #6
0
"""Tests the xonsh lexer."""
import os

import pytest  # noqa F401

from xonsh.wizard import (
    FileInserter,
    Message,
    Pass,
    PrettyFormatter,
    Question,
    StateVisitor,
    Wizard,
)

TREE0 = Wizard(children=[Pass(), Message(message="yo")])
TREE1 = Question("wakka?", {"jawaka": Pass()})


def test_pretty_format_tree0():
    exp = "Wizard(children=[\n" " Pass(),\n" " Message('yo')\n" "])"
    obs = PrettyFormatter(TREE0).visit()
    assert exp == obs
    assert exp == str(TREE0)
    assert exp.replace("\n", "") == repr(TREE0)


def test_pretty_format_tree1():
    exp = ("Question(\n"
           " question='wakka?',\n"
           " responses={\n"
예제 #7
0
def make_env():
    """Makes an environment variable wizard."""
    kids = map(make_envvar, sorted(builtins.__xonsh_env__.docs.keys()))
    kids = [k for k in kids if k is not None]
    wiz = Wizard(children=kids)
    return wiz