示例#1
0
def _xh_get_history(
    session="session",
    *,
    slices=None,
    datetime_format=None,
    start_time=None,
    end_time=None,
    location=None,
):
    """Get the requested portion of shell history.

    Parameters
    ----------
    session: {'session', 'all', 'xonsh', 'bash', 'zsh'}
        The history session to get.
    slices : list of slice-like objects, optional
        Get only portions of history.
    start_time, end_time: float, optional
        Filter commands by timestamp.
    location: string, optional
        The history file location (bash or zsh)

    Returns
    -------
    generator
       A filtered list of commands
    """
    cmds = []
    for i, item in enumerate(_XH_HISTORY_SESSIONS[session](location=location)):
        item["ind"] = i
        cmds.append(item)
    if slices:
        # transform/check all slices
        slices = [xt.ensure_slice(s) for s in slices]
        cmds = xt.get_portions(cmds, slices)
    if start_time or end_time:
        if start_time is None:
            start_time = 0.0
        else:
            start_time = xt.ensure_timestamp(start_time, datetime_format)
        if end_time is None:
            end_time = float("inf")
        else:
            end_time = xt.ensure_timestamp(end_time, datetime_format)
        cmds = _xh_filter_ts(cmds, start_time, end_time)
    return cmds
示例#2
0
文件: main.py 项目: ericmharris/xonsh
def _xh_get_history(
    session="session",
    *,
    slices=None,
    datetime_format=None,
    start_time=None,
    end_time=None,
    location=None
):
    """Get the requested portion of shell history.

    Parameters
    ----------
    session: {'session', 'all', 'xonsh', 'bash', 'zsh'}
        The history session to get.
    slices : list of slice-like objects, optional
        Get only portions of history.
    start_time, end_time: float, optional
        Filter commands by timestamp.
    location: string, optional
        The history file location (bash or zsh)

    Returns
    -------
    generator
       A filtered list of commands
    """
    cmds = []
    for i, item in enumerate(_XH_HISTORY_SESSIONS[session](location=location)):
        item["ind"] = i
        cmds.append(item)
    if slices:
        # transform/check all slices
        slices = [xt.ensure_slice(s) for s in slices]
        cmds = xt.get_portions(cmds, slices)
    if start_time or end_time:
        if start_time is None:
            start_time = 0.0
        else:
            start_time = xt.ensure_timestamp(start_time, datetime_format)
        if end_time is None:
            end_time = float("inf")
        else:
            end_time = xt.ensure_timestamp(end_time, datetime_format)
        cmds = _xh_filter_ts(cmds, start_time, end_time)
    return cmds
示例#3
0
def _hist_get(session='session',
              *,
              slices=None,
              datetime_format=None,
              start_time=None,
              end_time=None,
              location=None):
    """Get the requested portion of shell history.

    Parameters
    ----------
    session: {'session', 'all', 'xonsh', 'bash', 'zsh'}
        The history session to get.
    slices : list of slice-like objects, optional
        Get only portions of history.
    start_time, end_time: float, optional
        Filter commands by timestamp.
    location: string, optional
        The history file location (bash or zsh)

    Returns
    -------
    generator
       A filtered list of commands
    """
    cmds = _HIST_SESSIONS[session](location=location)
    if slices:
        # transform/check all slices
        slices = [ensure_slice(s) for s in slices]
        cmds = _hist_get_portion(cmds, slices)
    if start_time or end_time:
        if start_time is None:
            start_time = 0.0
        else:
            start_time = ensure_timestamp(start_time, datetime_format)
        if end_time is None:
            end_time = float('inf')
        else:
            end_time = ensure_timestamp(end_time, datetime_format)
        cmds = _hist_filter_ts(cmds, start_time, end_time)
    return cmds
示例#4
0
def _hist_get(session='session', *, slices=None, datetime_format=None,
              start_time=None, end_time=None, location=None):
    """Get the requested portion of shell history.

    Parameters
    ----------
    session: {'session', 'all', 'xonsh', 'bash', 'zsh'}
        The history session to get.
    slices : list of slice-like objects, optional
        Get only portions of history.
    start_time, end_time: float, optional
        Filter commands by timestamp.
    location: string, optional
        The history file location (bash or zsh)

    Returns
    -------
    generator
       A filtered list of commands
    """
    cmds = _HIST_SESSIONS[session](location=location)
    if slices:
        # transform/check all slices
        slices = [ensure_slice(s) for s in slices]
        cmds = get_portions(cmds, slices)
    if start_time or end_time:
        if start_time is None:
            start_time = 0.0
        else:
            start_time = ensure_timestamp(start_time, datetime_format)
        if end_time is None:
            end_time = float('inf')
        else:
            end_time = ensure_timestamp(end_time, datetime_format)
        cmds = _hist_filter_ts(cmds, start_time, end_time)
    return cmds
示例#5
0
def test_ensure_timestamp(inp, fmt, exp, xonsh_builtins):
    xonsh_builtins.__xonsh__.env["XONSH_DATETIME_FORMAT"] = "%Y-%m-%d %H:%M"
    obs = ensure_timestamp(inp, fmt)
    assert exp == obs
示例#6
0
def test_ensure_timestamp(inp, fmt, exp, xonsh_builtins):
    xonsh_builtins.__xonsh_env__['XONSH_DATETIME_FORMAT'] = '%Y-%m-%d %H:%M'
    obs = ensure_timestamp(inp, fmt)
    assert exp == obs
示例#7
0
def test_ensure_timestamp(inp, fmt, exp, xession):
    xession.env["XONSH_DATETIME_FORMAT"] = "%Y-%m-%d %H:%M"
    obs = ensure_timestamp(inp, fmt)
    assert exp == obs
示例#8
0
文件: test_tools.py 项目: mitnk/xonsh
def test_ensure_timestamp(inp, fmt, exp, xonsh_builtins):
    xonsh_builtins.__xonsh__.env["XONSH_DATETIME_FORMAT"] = "%Y-%m-%d %H:%M"
    obs = ensure_timestamp(inp, fmt)
    assert exp == obs
示例#9
0
def test_ensure_timestamp(inp, fmt, exp, xonsh_builtins):
    xonsh_builtins.__xonsh_env__['XONSH_DATETIME_FORMAT'] = '%Y-%m-%d %H:%M'
    obs = ensure_timestamp(inp, fmt)
    assert exp == obs