コード例 #1
0
ファイル: tables.py プロジェクト: derdon/sunpy
def display_entries(database_entries, columns, sort=False):
    """Generate a table to display the database entries.

    Parameters
    ----------
    database_entries : iterable of :class:`DatabaseEntry` instances
        The database entries will be the rows in the resulting table.

    columns : iterable of str
        The columns that will be displayed in the resulting table. Possible
        values for the strings are all attributes of :class:`DatabaseEntry`.

    sort : bool (optional)
        If True, sorts the entries before displaying them.

    Returns
    -------
    str
        A formatted table that can be printed on the console or written to a
        file.

    """
    header = [columns]
    rulers = [['-' * len(col) for col in columns]]
    data = []
    for entry in database_entries:
        row = []
        for col in columns:
            if col == 'starred':
                row.append('Yes' if entry.starred else 'No')
            elif col == 'tags':
                row.append(', '.join(imap(str, entry.tags)) or 'N/A')
            # do not display microseconds in datetime columns
            elif col in (
                    'observation_time_start',
                    'observation_time_end',
                    'download_time'):
                time = getattr(entry, col, None)
                if time is None:
                    formatted_time = 'N/A'
                else:
                    formatted_time = time.strftime(TIME_FORMAT)
                row.append(formatted_time)
            else:
                row.append(str(getattr(entry, col) or 'N/A'))
        if not row:
            raise TypeError('at least one column must be given')
        data.append(row)
    if not data:
        raise TypeError('given iterable is empty')
    if sort:
        data.sort()
    return print_table(header + rulers + data)
コード例 #2
0
ファイル: tables.py プロジェクト: s0nskar/sunpy
def display_entries(database_entries, columns, sort=False):
    """Generate a table to display the database entries.

    Parameters
    ----------
    database_entries : iterable of :class:`DatabaseEntry` instances
        The database entries will be the rows in the resulting table.

    columns : iterable of str
        The columns that will be displayed in the resulting table. Possible
        values for the strings are all attributes of :class:`DatabaseEntry`.

    sort : bool (optional)
        If True, sorts the entries before displaying them.

    Returns
    -------
    str
        A formatted table that can be printed on the console or written to a
        file.

    """
    header = [columns]
    rulers = [['-' * len(col) for col in columns]]
    data = []
    for entry in database_entries:
        row = []
        for col in columns:
            if col == 'starred':
                row.append('Yes' if entry.starred else 'No')
            elif col == 'tags':
                row.append(', '.join(map(str, entry.tags)) or 'N/A')
            # do not display microseconds in datetime columns
            elif col in ('observation_time_start', 'observation_time_end',
                         'download_time'):
                time = getattr(entry, col, None)
                if time is None:
                    formatted_time = 'N/A'
                else:
                    formatted_time = time.strftime(TIME_FORMAT)
                row.append(formatted_time)
            else:
                row.append(str(getattr(entry, col) or 'N/A'))
        if not row:
            raise TypeError('at least one column must be given')
        data.append(row)
    if not data:
        raise TypeError('given iterable is empty')
    if sort:
        data.sort()
    return print_table(header + rulers + data)
コード例 #3
0
ファイル: vso.py プロジェクト: gunner272/sunpy
    def show(self):
        """Print out human-readable summary of records retrieved"""

        table = [[
            str(datetime.strptime(record.time.start, TIME_FORMAT))
            if record.time.start is not None else 'N/A',
            str(datetime.strptime(record.time.end, TIME_FORMAT))
            if record.time.end is not None else 'N/A', record.source,
            record.instrument,
            record.extent.type if record.extent.type is not None else 'N/A'
        ] for record in self]
        table.insert(
            0, ['----------', '--------', '------', '----------', '----'])
        table.insert(
            0, ['Start time', 'End time', 'Source', 'Instrument', 'Type'])

        print(print_table(table, colsep='  ', linesep='\n'))
コード例 #4
0
ファイル: tables.py プロジェクト: samuelvonstachelski/sunpy
def display_entries(database_entries, columns):
    """Generate a table to display the database entries.

    Parameters
    ----------
    database_entries : iterable of :class:`DatabaseEntry` instances
        The database entries will be the rows in the resulting table.

    columns : iterable of str
        The columns that will be displayed in the resulting table. Possible
        values for the strings are all attributes of :class:`DatabaseEntry`.

    Returns
    -------
    str
        A formatted table that can be printed on the console or written to a
        file.

    """
    header = [columns]
    rulers = [["-" * len(col) for col in columns]]
    data = []
    for entry in database_entries:
        row = []
        for col in columns:
            if col == "starred":
                row.append("Yes" if entry.starred else "No")
            elif col == "tags":
                row.append(", ".join(imap(str, entry.tags)) or "N/A")
            # do not display microseconds in datetime columns
            elif col in ("observation_time_start", "observation_time_end", "download_time"):
                time = getattr(entry, col, None)
                if time is None:
                    formatted_time = "N/A"
                else:
                    formatted_time = time.strftime(TIME_FORMAT)
                row.append(formatted_time)
            else:
                row.append(str(getattr(entry, col) or "N/A"))
        if not row:
            raise TypeError("at least one column must be given")
        data.append(row)
    if not data:
        raise TypeError("given iterable is empty")
    return print_table(header + rulers + data)
コード例 #5
0
ファイル: vso.py プロジェクト: abooij/sunpy
    def show(self):
        """Print out human-readable summary of records retrieved"""

        table = [
            [
                str(datetime.strptime(record.time.start, TIMEFORMAT))
                    if record.time.start is not None else 'N/A',
                str(datetime.strptime(record.time.end, TIMEFORMAT))
                    if record.time.end is not None else 'N/A',
                record.source,
                record.instrument,
                record.extent.type
                    if record.extent.type is not None else 'N/A'
            ] for record in self]
        table.insert(0, ['----------', '--------', '------', '----------', '----'])
        table.insert(0, ['Start time', 'End time', 'Source', 'Instrument', 'Type'])

        print(print_table(table, colsep='  ', linesep='\n'))
コード例 #6
0
ファイル: tables.py プロジェクト: examon/sunpy
def display_entries(database_entries, columns):
    """Generate a table to display the database entries.

    Parameters
    ----------
    database_entries : iterable of :class:`DatabaseEntry` instances
        The database entries will be the rows in the resulting table.

    columns : iterable of str
        The columns that will be displayed in the resulting table. Possible
        values for the strings are all attributes of :class:`DatabaseEntry`.

    Returns
    -------
    str
        A formatted table that can be printed on the console or written to a
        file.

    """
    header = [columns]
    rulers = [['-' * len(col) for col in columns]]
    data = []
    for entry in database_entries:
        row = []
        for col in columns:
            if col == 'starred':
                row.append('Yes' if entry.starred else 'No')
            elif col == 'tags':
                row.append(', '.join(imap(str, entry.tags)) or 'N/A')
            else:
                row.append(str(getattr(entry, col) or 'N/A'))
        if not row:
            raise TypeError('at least one column must be given')
        data.append(row)
    if not data:
        raise TypeError('given iterable is empty')
    return print_table(header + rulers + data)