How to use the humanfriendly.format_size function in humanfriendly

To help you get started, we’ve selected a few humanfriendly examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xolox / python-humanfriendly / humanfriendly / tests.py View on Github external
"""Test :func:`humanfriendly.format_size()`."""
        self.assertEqual('0 bytes', humanfriendly.format_size(0))
        self.assertEqual('1 byte', humanfriendly.format_size(1))
        self.assertEqual('42 bytes', humanfriendly.format_size(42))
        self.assertEqual('1 KB', humanfriendly.format_size(1000 ** 1))
        self.assertEqual('1 MB', humanfriendly.format_size(1000 ** 2))
        self.assertEqual('1 GB', humanfriendly.format_size(1000 ** 3))
        self.assertEqual('1 TB', humanfriendly.format_size(1000 ** 4))
        self.assertEqual('1 PB', humanfriendly.format_size(1000 ** 5))
        self.assertEqual('1 EB', humanfriendly.format_size(1000 ** 6))
        self.assertEqual('1 ZB', humanfriendly.format_size(1000 ** 7))
        self.assertEqual('1 YB', humanfriendly.format_size(1000 ** 8))
        self.assertEqual('1 KiB', humanfriendly.format_size(1024 ** 1, binary=True))
        self.assertEqual('1 MiB', humanfriendly.format_size(1024 ** 2, binary=True))
        self.assertEqual('1 GiB', humanfriendly.format_size(1024 ** 3, binary=True))
        self.assertEqual('1 TiB', humanfriendly.format_size(1024 ** 4, binary=True))
        self.assertEqual('1 PiB', humanfriendly.format_size(1024 ** 5, binary=True))
        self.assertEqual('1 EiB', humanfriendly.format_size(1024 ** 6, binary=True))
        self.assertEqual('1 ZiB', humanfriendly.format_size(1024 ** 7, binary=True))
        self.assertEqual('1 YiB', humanfriendly.format_size(1024 ** 8, binary=True))
        self.assertEqual('45 KB', humanfriendly.format_size(1000 * 45))
        self.assertEqual('2.9 TB', humanfriendly.format_size(1000 ** 4 * 2.9))
github alexiswl / poreduck / poreduck / promethion_plotter.post.py View on Github external
def print_stats(sample_df):
    percentiles = [0.1, 0.25, 0.5, 0.75, 0.9]
    # Get total yield
    total_bp = sample_df['SeqLength'].sum()
    total_bp_h = reformat_human_friendly(humanfriendly.format_size(total_bp, binary=False))
    # Describe length
    length_describe = sample_df['SeqLength'].describe(percentiles=percentiles).to_string()
    # Describe quality
    qual_describe = sample_df['AvQual'].describe(percentiles=percentiles).to_string()

    # Reformat each of the methods such that they're rounded to two decimal places
    length_describe = '\n'.join([qual_line.split()[0].ljust(8) + "\t" + 
                                 "{:21.2f}".format(float(qual_line.split()[1]))
                                 for qual_line in length_describe.split("\n")])
    qual_describe = '\n'.join([qual_line.split()[0].ljust(8) + "\t" + 
                               "{:21.2f}".format(float(qual_line.split()[1]))
                               for qual_line in qual_describe.split("\n")])
    
    # Calculate the N50:
    nx = []
    seq_length_sorted_as_series = sample_df['SeqLength'].sort_values().reset_index(drop=True)
github alexiswl / poreduck / poreduck / promethion_plotter.post.py View on Github external
def y_hist_to_human_readable_seq(y, position):
        # Convert distribution to base pairs
        if y == 0:
            return 0
        s = humanfriendly.format_size(bin_width * sample_df["SeqLength"].sum() * y, binary=False)
        return reformat_human_friendly(s)
    ax.yaxis.set_major_formatter(FuncFormatter(y_hist_to_human_readable_seq))
github mozilla-services / socorro / webapp-django / crashstats / crashstats / templatetags / jinja_helpers.py View on Github external
)

    try:
        bytes = int(bytes)
    except (ValueError, TypeError):
        # ValueErrors happen when `bytes` is not a number.
        # TypeErrors happen when you try to convert a None to an integer.

        # Bail but note how it's NOT marked as safe.
        # That means that if `bytes` is literally '
github kz26 / dottorrent-gui / dottorrentGUI / gui.py View on Github external
self.fileRadioButton.toggled.connect(self.inputModeToggle)
        self.fileRadioButton.setChecked(True)
        self.directoryRadioButton.toggled.connect(self.inputModeToggle)

        self.browseButton.clicked.connect(self.browseInput)
        self.batchModeCheckBox.stateChanged.connect(self.batchModeChanged)

        self.inputEdit.dragEnterEvent = self.inputDragEnterEvent
        self.inputEdit.dropEvent = self.inputDropEvent
        self.pasteButton.clicked.connect(self.pasteInput)

        self.pieceCountLabel.hide()
        self.pieceSizeComboBox.addItem('Auto')
        for x in PIECE_SIZES[1:]:
            self.pieceSizeComboBox.addItem(
                humanfriendly.format_size(x, binary=True))

        self.pieceSizeComboBox.currentIndexChanged.connect(
            self.pieceSizeChanged)

        self.privateTorrentCheckBox.stateChanged.connect(
            self.privateTorrentChanged)

        self.commentEdit.textEdited.connect(
            self.commentEdited)

        self.sourceEdit.textEdited.connect(
            self.sourceEdited)

        self.md5CheckBox.stateChanged.connect(
            self.md5Changed)
github alexiswl / poreduck / poreduck / promethion_plotter.py View on Github external
def y_hist_to_human_readable_seq(y, position):
        # Convert distribution to base pairs
        if y == 0:
            return 0
        s = humanfriendly.format_size(lengths.sum() * y, binary=False)
        return reformat_human_friendly(s)
    ax.yaxis.set_major_formatter(FuncFormatter(y_hist_to_human_readable_seq))
github adamrehn / ue4-docker / ue4docker / info.py View on Github external
def _formatSize(size):
	return humanfriendly.format_size(size, binary=True)
github kz26 / dottorrent-gui / dottorrentGUI / gui.py View on Github external
def updatePieceCountLabel(self, ps, pc):
        ps = humanfriendly.format_size(ps, binary=True)
        self.pieceCountLabel.setText("{} pieces @ {} each".format(pc, ps))
github the-okn3 / volafile-downloader / volafile-downloader / downloader.py View on Github external
downloaded=0,
            already_exist=0,
            too_big=0,
            failed=0,
            forbidden_extension=0,
            user_ignored=0
        )

        for f in files:

            self.logger.info(u"[%s of %s] [%s] [%s] [%s] [%s] [by %s]" % (
                file_index,
                info["total"],
                f["name"],
                f["extension"],
                humanfriendly.format_size(f["size"]),
                f["expiration"],
                f["tag"]
            ))

            download_directory_path = self.download_directory

            # Change directory if it's to archive
            if self.archive:
                archive_dir_name = datetime.now().strftime(config.archive_date_format)

                if self.archive_type == "CREATION_DATE":
                    archive_dir_name = expiration_to_date(f["expiration"])\
                        .strftime(config.archive_date_format)

                download_directory_path = os.path.join(
                    self.download_directory, archive_dir_name)