How to use the humanfriendly.parse_timespan 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
def test_parse_timespan(self):
        """Test :func:`humanfriendly.parse_timespan()`."""
        self.assertEqual(0, humanfriendly.parse_timespan('0'))
        self.assertEqual(0, humanfriendly.parse_timespan('0s'))
        self.assertEqual(0.001, humanfriendly.parse_timespan('1ms'))
        self.assertEqual(0.001, humanfriendly.parse_timespan('1 millisecond'))
        self.assertEqual(0.5, humanfriendly.parse_timespan('500 milliseconds'))
        self.assertEqual(0.5, humanfriendly.parse_timespan('0.5 seconds'))
        self.assertEqual(5, humanfriendly.parse_timespan('5s'))
        self.assertEqual(5, humanfriendly.parse_timespan('5 seconds'))
        self.assertEqual(60 * 2, humanfriendly.parse_timespan('2m'))
        self.assertEqual(60 * 2, humanfriendly.parse_timespan('2 minutes'))
        self.assertEqual(60 * 3, humanfriendly.parse_timespan('3 min'))
        self.assertEqual(60 * 3, humanfriendly.parse_timespan('3 mins'))
        self.assertEqual(60 * 60 * 3, humanfriendly.parse_timespan('3 h'))
        self.assertEqual(60 * 60 * 3, humanfriendly.parse_timespan('3 hours'))
        self.assertEqual(60 * 60 * 24 * 4, humanfriendly.parse_timespan('4d'))
        self.assertEqual(60 * 60 * 24 * 4, humanfriendly.parse_timespan('4 days'))
        self.assertEqual(60 * 60 * 24 * 7 * 5, humanfriendly.parse_timespan('5 w'))
        self.assertEqual(60 * 60 * 24 * 7 * 5, humanfriendly.parse_timespan('5 weeks'))
        self.assertRaises(humanfriendly.InvalidTimespan, humanfriendly.parse_timespan, '1z')
github xolox / python-humanfriendly / humanfriendly / tests.py View on Github external
def test_parse_timespan(self):
        """Test :func:`humanfriendly.parse_timespan()`."""
        self.assertEqual(0, humanfriendly.parse_timespan('0'))
        self.assertEqual(0, humanfriendly.parse_timespan('0s'))
        self.assertEqual(0.001, humanfriendly.parse_timespan('1ms'))
        self.assertEqual(0.001, humanfriendly.parse_timespan('1 millisecond'))
        self.assertEqual(0.5, humanfriendly.parse_timespan('500 milliseconds'))
        self.assertEqual(0.5, humanfriendly.parse_timespan('0.5 seconds'))
        self.assertEqual(5, humanfriendly.parse_timespan('5s'))
        self.assertEqual(5, humanfriendly.parse_timespan('5 seconds'))
        self.assertEqual(60 * 2, humanfriendly.parse_timespan('2m'))
        self.assertEqual(60 * 2, humanfriendly.parse_timespan('2 minutes'))
        self.assertEqual(60 * 3, humanfriendly.parse_timespan('3 min'))
        self.assertEqual(60 * 3, humanfriendly.parse_timespan('3 mins'))
        self.assertEqual(60 * 60 * 3, humanfriendly.parse_timespan('3 h'))
        self.assertEqual(60 * 60 * 3, humanfriendly.parse_timespan('3 hours'))
        self.assertEqual(60 * 60 * 24 * 4, humanfriendly.parse_timespan('4d'))
        self.assertEqual(60 * 60 * 24 * 4, humanfriendly.parse_timespan('4 days'))
        self.assertEqual(60 * 60 * 24 * 7 * 5, humanfriendly.parse_timespan('5 w'))
github xolox / python-humanfriendly / humanfriendly / tests.py View on Github external
def test_parse_timespan(self):
        """Test :func:`humanfriendly.parse_timespan()`."""
        self.assertEqual(0, humanfriendly.parse_timespan('0'))
        self.assertEqual(0, humanfriendly.parse_timespan('0s'))
        self.assertEqual(0.001, humanfriendly.parse_timespan('1ms'))
        self.assertEqual(0.001, humanfriendly.parse_timespan('1 millisecond'))
        self.assertEqual(0.5, humanfriendly.parse_timespan('500 milliseconds'))
        self.assertEqual(0.5, humanfriendly.parse_timespan('0.5 seconds'))
        self.assertEqual(5, humanfriendly.parse_timespan('5s'))
        self.assertEqual(5, humanfriendly.parse_timespan('5 seconds'))
        self.assertEqual(60 * 2, humanfriendly.parse_timespan('2m'))
        self.assertEqual(60 * 2, humanfriendly.parse_timespan('2 minutes'))
        self.assertEqual(60 * 3, humanfriendly.parse_timespan('3 min'))
        self.assertEqual(60 * 3, humanfriendly.parse_timespan('3 mins'))
        self.assertEqual(60 * 60 * 3, humanfriendly.parse_timespan('3 h'))
        self.assertEqual(60 * 60 * 3, humanfriendly.parse_timespan('3 hours'))
        self.assertEqual(60 * 60 * 24 * 4, humanfriendly.parse_timespan('4d'))
        self.assertEqual(60 * 60 * 24 * 4, humanfriendly.parse_timespan('4 days'))
        self.assertEqual(60 * 60 * 24 * 7 * 5, humanfriendly.parse_timespan('5 w'))
        self.assertEqual(60 * 60 * 24 * 7 * 5, humanfriendly.parse_timespan('5 weeks'))
        self.assertRaises(humanfriendly.InvalidTimespan, humanfriendly.parse_timespan, '1z')
github xolox / python-humanfriendly / humanfriendly / tests.py View on Github external
def test_parse_timespan(self):
        """Test :func:`humanfriendly.parse_timespan()`."""
        self.assertEqual(0, humanfriendly.parse_timespan('0'))
        self.assertEqual(0, humanfriendly.parse_timespan('0s'))
        self.assertEqual(0.001, humanfriendly.parse_timespan('1ms'))
        self.assertEqual(0.001, humanfriendly.parse_timespan('1 millisecond'))
        self.assertEqual(0.5, humanfriendly.parse_timespan('500 milliseconds'))
        self.assertEqual(0.5, humanfriendly.parse_timespan('0.5 seconds'))
        self.assertEqual(5, humanfriendly.parse_timespan('5s'))
        self.assertEqual(5, humanfriendly.parse_timespan('5 seconds'))
        self.assertEqual(60 * 2, humanfriendly.parse_timespan('2m'))
        self.assertEqual(60 * 2, humanfriendly.parse_timespan('2 minutes'))
        self.assertEqual(60 * 3, humanfriendly.parse_timespan('3 min'))
        self.assertEqual(60 * 3, humanfriendly.parse_timespan('3 mins'))
        self.assertEqual(60 * 60 * 3, humanfriendly.parse_timespan('3 h'))
        self.assertEqual(60 * 60 * 3, humanfriendly.parse_timespan('3 hours'))
        self.assertEqual(60 * 60 * 24 * 4, humanfriendly.parse_timespan('4d'))
        self.assertEqual(60 * 60 * 24 * 4, humanfriendly.parse_timespan('4 days'))
        self.assertEqual(60 * 60 * 24 * 7 * 5, humanfriendly.parse_timespan('5 w'))
        self.assertEqual(60 * 60 * 24 * 7 * 5, humanfriendly.parse_timespan('5 weeks'))
        self.assertRaises(humanfriendly.InvalidTimespan, humanfriendly.parse_timespan, '1z')
github xolox / python-humanfriendly / humanfriendly / tests.py View on Github external
"""Test :func:`humanfriendly.parse_timespan()`."""
        self.assertEqual(0, humanfriendly.parse_timespan('0'))
        self.assertEqual(0, humanfriendly.parse_timespan('0s'))
        self.assertEqual(0.001, humanfriendly.parse_timespan('1ms'))
        self.assertEqual(0.001, humanfriendly.parse_timespan('1 millisecond'))
        self.assertEqual(0.5, humanfriendly.parse_timespan('500 milliseconds'))
        self.assertEqual(0.5, humanfriendly.parse_timespan('0.5 seconds'))
        self.assertEqual(5, humanfriendly.parse_timespan('5s'))
        self.assertEqual(5, humanfriendly.parse_timespan('5 seconds'))
        self.assertEqual(60 * 2, humanfriendly.parse_timespan('2m'))
        self.assertEqual(60 * 2, humanfriendly.parse_timespan('2 minutes'))
        self.assertEqual(60 * 3, humanfriendly.parse_timespan('3 min'))
        self.assertEqual(60 * 3, humanfriendly.parse_timespan('3 mins'))
        self.assertEqual(60 * 60 * 3, humanfriendly.parse_timespan('3 h'))
        self.assertEqual(60 * 60 * 3, humanfriendly.parse_timespan('3 hours'))
        self.assertEqual(60 * 60 * 24 * 4, humanfriendly.parse_timespan('4d'))
        self.assertEqual(60 * 60 * 24 * 4, humanfriendly.parse_timespan('4 days'))
        self.assertEqual(60 * 60 * 24 * 7 * 5, humanfriendly.parse_timespan('5 w'))
        self.assertEqual(60 * 60 * 24 * 7 * 5, humanfriendly.parse_timespan('5 weeks'))
        self.assertRaises(humanfriendly.InvalidTimespan, humanfriendly.parse_timespan, '1z')
github xolox / python-humanfriendly / humanfriendly / tests.py View on Github external
def test_parse_timespan(self):
        """Test :func:`humanfriendly.parse_timespan()`."""
        self.assertEqual(0, humanfriendly.parse_timespan('0'))
        self.assertEqual(0, humanfriendly.parse_timespan('0s'))
        self.assertEqual(0.001, humanfriendly.parse_timespan('1ms'))
        self.assertEqual(0.001, humanfriendly.parse_timespan('1 millisecond'))
        self.assertEqual(0.5, humanfriendly.parse_timespan('500 milliseconds'))
        self.assertEqual(0.5, humanfriendly.parse_timespan('0.5 seconds'))
        self.assertEqual(5, humanfriendly.parse_timespan('5s'))
        self.assertEqual(5, humanfriendly.parse_timespan('5 seconds'))
        self.assertEqual(60 * 2, humanfriendly.parse_timespan('2m'))
        self.assertEqual(60 * 2, humanfriendly.parse_timespan('2 minutes'))
        self.assertEqual(60 * 3, humanfriendly.parse_timespan('3 min'))
        self.assertEqual(60 * 3, humanfriendly.parse_timespan('3 mins'))
        self.assertEqual(60 * 60 * 3, humanfriendly.parse_timespan('3 h'))
        self.assertEqual(60 * 60 * 3, humanfriendly.parse_timespan('3 hours'))
        self.assertEqual(60 * 60 * 24 * 4, humanfriendly.parse_timespan('4d'))
        self.assertEqual(60 * 60 * 24 * 4, humanfriendly.parse_timespan('4 days'))
        self.assertEqual(60 * 60 * 24 * 7 * 5, humanfriendly.parse_timespan('5 w'))
        self.assertEqual(60 * 60 * 24 * 7 * 5, humanfriendly.parse_timespan('5 weeks'))
        self.assertRaises(humanfriendly.InvalidTimespan, humanfriendly.parse_timespan, '1z')
github xolox / python-humanfriendly / humanfriendly / tests.py View on Github external
def test_parse_timespan(self):
        """Test :func:`humanfriendly.parse_timespan()`."""
        self.assertEqual(0, humanfriendly.parse_timespan('0'))
        self.assertEqual(0, humanfriendly.parse_timespan('0s'))
        self.assertEqual(0.001, humanfriendly.parse_timespan('1ms'))
        self.assertEqual(0.001, humanfriendly.parse_timespan('1 millisecond'))
        self.assertEqual(0.5, humanfriendly.parse_timespan('500 milliseconds'))
        self.assertEqual(0.5, humanfriendly.parse_timespan('0.5 seconds'))
        self.assertEqual(5, humanfriendly.parse_timespan('5s'))
        self.assertEqual(5, humanfriendly.parse_timespan('5 seconds'))
        self.assertEqual(60 * 2, humanfriendly.parse_timespan('2m'))
        self.assertEqual(60 * 2, humanfriendly.parse_timespan('2 minutes'))
        self.assertEqual(60 * 3, humanfriendly.parse_timespan('3 min'))
        self.assertEqual(60 * 3, humanfriendly.parse_timespan('3 mins'))
        self.assertEqual(60 * 60 * 3, humanfriendly.parse_timespan('3 h'))
        self.assertEqual(60 * 60 * 3, humanfriendly.parse_timespan('3 hours'))
        self.assertEqual(60 * 60 * 24 * 4, humanfriendly.parse_timespan('4d'))
        self.assertEqual(60 * 60 * 24 * 4, humanfriendly.parse_timespan('4 days'))
        self.assertEqual(60 * 60 * 24 * 7 * 5, humanfriendly.parse_timespan('5 w'))
        self.assertEqual(60 * 60 * 24 * 7 * 5, humanfriendly.parse_timespan('5 weeks'))
        self.assertRaises(humanfriendly.InvalidTimespan, humanfriendly.parse_timespan, '1z')
github quarkslab / irma / frontend / api / tasks / frontend_app.py View on Github external
@frontend_app.task()
def clean_fs_age():
    try:
        cron_cfg = config.frontend_config['cron_clean_file_age']
        max_age_file = cron_cfg['clean_fs_max_age']
        # 0 means disabled
        if max_age_file == "0":
            log.debug("disabled by config")
            return 0
        # convert to seconds
        max_age_secs = int(humanfriendly.parse_timespan(max_age_file))
        nb_files = file_ctrl.remove_files(max_age_secs)
        log.info("removed %d files (older than %s)", nb_files, max_age_file)
        return nb_files
    except (IrmaDatabaseError, IrmaFileSystemError) as e:
        log.exception(type(e).__name__ + " : " + str(e))
github ShahriyarR / MySQL-AutoXtraBackup / general_conf / generalops.py View on Github external
else:
                self.full_backup_interval = 86400
            if 'archive_dir' in BCK:
                self.archive_dir = BCK['archive_dir']
            if 'prepare_archive' in BCK:
                self.prepare_archive = BCK['prepare_archive']
            if 'move_archive' in BCK:
                self.move_archive = BCK['move_archive']
            # backward compatible with old config 'max_archive_size' and newer 'archive_max_size'
            if 'max_archive_size' in BCK:
                self.archive_max_size = humanfriendly.parse_size(BCK['max_archive_size'])
            elif 'archive_max_size' in BCK:
                self.archive_max_size = humanfriendly.parse_size(BCK['archive_max_size'])
            # backward compatible with old config 'max_archive_duration' and newer 'archive_max_duration'
            if 'max_archive_duration' in BCK:
                self.archive_max_duration = humanfriendly.parse_timespan(BCK['max_archive_duration'])
            elif 'archive_max_duration' in BCK:
                self.archive_max_duration = humanfriendly.parse_timespan(BCK['archive_max_duration'])
            if 'partial_list' in BCK:
                self.partial_list = BCK['partial_list']

            if 'Remote' in con:
                RM = con['Remote']
                if 'remote_conn' in RM:
                    self.remote_conn = RM['remote_conn']
                if 'remote_dir' in RM:
                    self.remote_dir = RM['remote_dir']

            COM = con['Compress']
            if 'compress' in COM:
                self.compress = COM['compress']
            if 'compress_chunk_size' in COM: