Example #1
0
 def _ls_versions_tbl_output(cls, versions):
     tbl = PrettyTable()
     # TODO: number of invalid blocks, used disk space, shared disk space
     tbl.field_names = [
         'date', 'uid', 'name', 'snapshot_name', 'size', 'block_size',
         'valid', 'protected', 'tags'
     ]
     tbl.align['name'] = 'l'
     tbl.align['snapshot_name'] = 'l'
     tbl.align['tags'] = 'l'
     tbl.align['size'] = 'r'
     tbl.align['block_size'] = 'r'
     for version in versions:
         tbl.add_row([
             PrettyPrint.local_time(version.date),
             version.uid.readable,
             version.name,
             version.snapshot_name,
             PrettyPrint.bytes(version.size),
             PrettyPrint.bytes(version.block_size),
             version.valid,
             version.protected,
             ",".join(sorted([t.name for t in version.tags])),
         ])
     print(tbl)
Example #2
0
 def _storage_usage_table_output(usage: Dict[str, Dict[str, int]]) -> None:
     tbl = PrettyTable()
     tbl.field_names = [
         'storage',
         'virtual',
         'sparse',
         'shared',
         'exclusive',
         'deduplicated_exclusive',
     ]
     tbl.align['storage'] = 'l'
     tbl.align['virtual'] = 'l'
     tbl.align['sparse'] = 'l'
     tbl.align['shared'] = 'r'
     tbl.align['exclusive'] = 'r'
     tbl.align['deduplicated_exclusive'] = 'r'
     for storage_name, usage in usage.items():
         row = [
             storage_name,
             PrettyPrint.bytes(usage['virtual']),
             PrettyPrint.bytes(usage['sparse']),
             PrettyPrint.bytes(usage['shared']),
             PrettyPrint.bytes(usage['exclusive']),
             PrettyPrint.bytes(usage['deduplicated_exclusive']),
         ]
         tbl.add_row(row)
     print(tbl)
Example #3
0
 def _ls_versions_table_output(cls, versions: List[Version],
                               include_labels: bool) -> None:
     tbl = PrettyTable()
     # tbls.field_names.append won't work due to magic inside of PrettyTable
     if include_labels:
         tbl.field_names = [
             'date',
             'uid',
             'name',
             'snapshot_name',
             'size',
             'block_size',
             'status',
             'protected',
             'storage',
             'labels',
         ]
     else:
         tbl.field_names = [
             'date',
             'uid',
             'name',
             'snapshot_name',
             'size',
             'block_size',
             'status',
             'protected',
             'storage',
         ]
     tbl.align['name'] = 'l'
     tbl.align['snapshot_name'] = 'l'
     tbl.align['storage'] = 'l'
     tbl.align['size'] = 'r'
     tbl.align['block_size'] = 'r'
     tbl.align['labels'] = 'l'
     for version in versions:
         row = [
             PrettyPrint.local_time(version.date),
             version.uid.v_string,
             version.name,
             version.snapshot_name,
             PrettyPrint.bytes(version.size),
             PrettyPrint.bytes(version.block_size),
             version.status,
             version.protected,
             StorageFactory.storage_id_to_name(version.storage_id),
         ]
         if include_labels:
             row.append('\n'.join(
                 sorted([
                     '{}={}'.format(label.name, label.value)
                     for label in version.labels
                 ])))
         tbl.add_row(row)
     print(tbl)
Example #4
0
    def _ls_versions_table_output(versions: List[Version], include_labels: bool, include_stats: bool) -> None:
        tbl = PrettyTable()

        field_names = ['date', 'uid', 'volume', 'snapshot', 'size', 'block_size', 'status', 'protected', 'storage']
        if include_stats:
            field_names.extend(['read', 'written', 'deduplicated', 'sparse', 'duration'])
        if include_labels:
            field_names.append('labels')
        tbl.field_names = field_names

        tbl.align['uid'] = 'l'
        tbl.align['volume'] = 'l'
        tbl.align['snapshot'] = 'l'
        tbl.align['storage'] = 'l'
        tbl.align['size'] = 'r'
        tbl.align['block_size'] = 'r'

        tbl.align['read'] = 'r'
        tbl.align['written'] = 'r'
        tbl.align['deduplicated'] = 'r'
        tbl.align['sparse'] = 'r'
        tbl.align['duration'] = 'r'

        tbl.align['labels'] = 'l'

        for version in versions:
            row = [
                PrettyPrint.local_time(version.date),
                version.uid,
                version.volume,
                version.snapshot,
                PrettyPrint.bytes(version.size),
                PrettyPrint.bytes(version.block_size),
                version.status,
                version.protected,
                version.storage.name,
            ]

            if include_stats:
                row.extend([
                    PrettyPrint.bytes(version.bytes_read) if version.bytes_read is not None else '',
                    PrettyPrint.bytes(version.bytes_written) if version.bytes_written is not None else '',
                    PrettyPrint.bytes(version.bytes_deduplicated) if version.bytes_deduplicated is not None else '',
                    PrettyPrint.bytes(version.bytes_sparse) if version.bytes_sparse is not None else '',
                    PrettyPrint.duration(version.duration) if version.duration is not None else '',
                ])

            if include_labels:
                row.append('\n'.join(
                    sorted(['{}={}'.format(label.name, label.value) for label in version.labels.values()])))
            tbl.add_row(row)
        print(tbl)
Example #5
0
 def _ls_storage_stats_table_output(objects_count: int, objects_size: int) -> None:
     tbl = PrettyTable()
     tbl.field_names = [
         'objects_count',
         'objects_size',
     ]
     tbl.align['objects_count'] = 'r'
     tbl.align['objects_size'] = 'r'
     row = [
         objects_count,
         PrettyPrint.bytes(objects_size),
     ]
     tbl.add_row(row)
     print(tbl)
Example #6
0
 def _stats_table_output(cls, stats: List[VersionStatistic]) -> None:
     tbl = PrettyTable()
     tbl.field_names = [
         'date', 'uid', 'name', 'snapshot_name', 'size', 'block_size',
         'storage', 'read', 'written', 'dedup', 'sparse', 'duration'
     ]
     tbl.align['uid'] = 'l'
     tbl.align['name'] = 'l'
     tbl.align['snapshot_name'] = 'l'
     tbl.align['storage'] = 'l'
     tbl.align['size'] = 'r'
     tbl.align['block_size'] = 'r'
     tbl.align['read'] = 'r'
     tbl.align['written'] = 'r'
     tbl.align['dedup'] = 'r'
     tbl.align['sparse'] = 'r'
     tbl.align['duration'] = 'r'
     for stat in stats:
         augmented_version_uid = '{}{}{}'.format(
             stat.uid.v_string, ',\nbase {}'.format(stat.base_uid.v_string)
             if stat.base_uid else '',
             ', hints' if stat.hints_supplied else '')
         tbl.add_row([
             PrettyPrint.local_time(stat.date),
             augmented_version_uid,
             stat.name,
             stat.snapshot_name,
             PrettyPrint.bytes(stat.size),
             PrettyPrint.bytes(stat.block_size),
             StorageFactory.storage_id_to_name(stat.storage_id),
             PrettyPrint.bytes(stat.bytes_read),
             PrettyPrint.bytes(stat.bytes_written),
             PrettyPrint.bytes(stat.bytes_dedup),
             PrettyPrint.bytes(stat.bytes_sparse),
             PrettyPrint.duration(stat.duration),
         ])
     print(tbl)
Example #7
0
 def _stats_tbl_output(cls, stats):
     tbl = PrettyTable()
     tbl.field_names = [
         'date', 'uid', 'name', 'snapshot_name', 'size', 'block_size',
         'read', 'written', 'dedup', 'sparse', 'duration (s)'
     ]
     tbl.align['uid'] = 'l'
     tbl.align['name'] = 'l'
     tbl.align['snapshot_name'] = 'l'
     tbl.align['size'] = 'r'
     tbl.align['block_size'] = 'r'
     tbl.align['read'] = 'r'
     tbl.align['written'] = 'r'
     tbl.align['dedup'] = 'r'
     tbl.align['sparse'] = 'r'
     tbl.align['duration (s)'] = 'r'
     for stat in stats:
         augmented_version_uid = '{}{}{}'.format(
             stat.version_uid.readable,
             ',\nbase {}'.format(stat.base_version_uid.readable)
             if stat.base_version_uid else '',
             ', hints' if stat.hints_supplied else '')
         tbl.add_row([
             PrettyPrint.local_time(stat.version_date),
             augmented_version_uid,
             stat.version_name,
             stat.version_snapshot_name,
             PrettyPrint.bytes(stat.version_size),
             PrettyPrint.bytes(stat.version_block_size),
             PrettyPrint.bytes(stat.bytes_read),
             PrettyPrint.bytes(stat.bytes_written),
             PrettyPrint.bytes(stat.bytes_dedup),
             PrettyPrint.bytes(stat.bytes_sparse),
             PrettyPrint.duration(stat.duration_seconds),
         ])
     print(tbl)