Esempio n. 1
0
 def test_echo_formatted_dataframe_uses_pager_when_len_rows_gt_threshold_const(
         self, mocker):
     mock_echo = mocker.patch("click.echo")
     mock_pager = mocker.patch("click.echo_via_pager")
     formatter = DataFrameOutputFormatter(OutputFormat.TABLE)
     rows_len = output_formats_module.OUTPUT_VIA_PAGER_THRESHOLD + 1
     big_df = DataFrame([{"column": val} for val in range(rows_len)])
     small_df = DataFrame([{"column": val} for val in range(5)])
     formatter.echo_formatted_dataframe(big_df)
     formatter.echo_formatted_dataframe(small_df)
     assert mock_echo.call_count == 1
     assert mock_pager.call_count == 1
Esempio n. 2
0
def list_users(state, org_uid, role_name, active, inactive, format):
    """List users in your Code42 environment."""
    if inactive:
        active = False
    role_id = _get_role_id(state.sdk, role_name) if role_name else None
    columns = (["userUid", "status", "username", "orgUid"]
               if format == OutputFormat.TABLE else None)
    df = _get_users_dataframe(state.sdk, columns, org_uid, role_id, active)
    if df.empty:
        click.echo("No results found.")
    else:
        formatter = DataFrameOutputFormatter(format)
        formatter.echo_formatted_dataframe(df)
Esempio n. 3
0
def list_backup_sets(
    state, active, org_uid, include_usernames, format,
):
    """Outputs a list of all devices."""
    columns = ["guid", "userUid"]
    devices_dataframe = _get_device_dataframe(state.sdk, columns, active, org_uid)
    if include_usernames:
        devices_dataframe = _add_usernames_to_device_dataframe(
            state.sdk, devices_dataframe
        )
    devices_dataframe = _add_backup_set_settings_to_dataframe(
        state.sdk, devices_dataframe
    )
    formatter = DataFrameOutputFormatter(format)
    formatter.echo_formatted_dataframe(devices_dataframe)
Esempio n. 4
0
def list_backup_sets(
    state, active, inactive, org_uid, include_usernames, format,
):
    """Get information about many devices and their backup sets."""
    if inactive:
        active = False
    columns = ["guid", "userUid"]
    df = _get_device_dataframe(state.sdk, columns, active, org_uid)
    if include_usernames:
        df = _add_usernames_to_device_dataframe(state.sdk, df)
    df = _add_backup_set_settings_to_dataframe(state.sdk, df)
    if df.empty:
        click.echo("No results found.")
    else:
        formatter = DataFrameOutputFormatter(format)
        formatter.echo_formatted_dataframe(df)
Esempio n. 5
0
def list_devices(
    state,
    active,
    days_since_last_connected,
    drop_most_recent,
    org_uid,
    include_backup_usage,
    include_usernames,
    include_settings,
    format,
):
    """Outputs a list of all devices."""
    columns = [
        "computerId",
        "guid",
        "name",
        "osHostname",
        "status",
        "lastConnected",
        "productVersion",
        "osName",
        "osVersion",
        "userUid",
    ]
    devices_dataframe = _get_device_dataframe(
        state.sdk, columns, active, org_uid, include_backup_usage
    )
    if drop_most_recent:
        devices_dataframe = _drop_n_devices_per_user(
            devices_dataframe, drop_most_recent
        )
    if days_since_last_connected:
        devices_dataframe = _drop_devices_which_have_not_connected_in_some_number_of_days(
            devices_dataframe, days_since_last_connected
        )
    if include_settings:
        devices_dataframe = _add_settings_to_dataframe(state.sdk, devices_dataframe)
    if include_usernames:
        devices_dataframe = _add_usernames_to_device_dataframe(
            state.sdk, devices_dataframe
        )
    formatter = DataFrameOutputFormatter(format)
    formatter.echo_formatted_dataframe(devices_dataframe)
Esempio n. 6
0
def list_devices(
    state,
    active,
    inactive,
    org_uid,
    include_backup_usage,
    include_usernames,
    include_settings,
    include_legal_hold_membership,
    include_total_storage,
    exclude_most_recently_connected,
    last_connected_after,
    last_connected_before,
    created_after,
    created_before,
    format,
):
    """Get information about many devices."""
    if inactive:
        active = False
    columns = [
        "computerId",
        "guid",
        "name",
        "osHostname",
        "status",
        "lastConnected",
        "creationDate",
        "productVersion",
        "osName",
        "osVersion",
        "userUid",
    ]
    df = _get_device_dataframe(
        state.sdk,
        columns,
        active,
        org_uid,
        (include_backup_usage or include_total_storage),
    )
    if last_connected_after:
        df = df.loc[to_datetime(df.lastConnected) > last_connected_after]
    if last_connected_before:
        df = df.loc[to_datetime(df.lastConnected) < last_connected_before]
    if created_after:
        df = df.loc[to_datetime(df.creationDate) > created_after]
    if created_before:
        df = df.loc[to_datetime(df.creationDate) < created_before]
    if exclude_most_recently_connected:
        most_recent = (
            df.sort_values(["userUid", "lastConnected"], ascending=False)
            .groupby("userUid")
            .head(exclude_most_recently_connected)
        )
        df = df.drop(most_recent.index)
    if include_total_storage:
        df = _add_storage_totals_to_dataframe(df, include_backup_usage)
    if include_settings:
        df = _add_settings_to_dataframe(state.sdk, df)
    if include_usernames:
        df = _add_usernames_to_device_dataframe(state.sdk, df)
    if include_legal_hold_membership:
        df = _add_legal_hold_membership_to_device_dataframe(state.sdk, df)
    if df.empty:
        click.echo("No results found.")
    else:
        formatter = DataFrameOutputFormatter(format)
        formatter.echo_formatted_dataframe(df)