def _rankfile_dump(ff, rankfile, ranks): ''' Store ranks in ``rankfile``. Also sets a timestamp and writes the release string into the output. :param ff: running :class:`ffflash.main.FFFlash` instance :param rankfile: validated path to the ``rankfile`` :param ranks: content to store :return: ``True`` on success, or ``False`` on error ''' if not ff.access_for('rankfile'): return False if not all([ rankfile, ranks, isinstance(ranks, dict), all([ (a in ranks) for a in ['nodes', 'updated_at'] if ranks ]) ]): return ff.log('wrong input data passed', level=False) ranks['updated_at'] = get_iso_timestamp() ranks['version'] = info.release if ff.args.dry: ff.log('\n{}'.format(make_pretty(ranks)), level='rankfile preview') return False dump_file(rankfile, ranks, as_yaml=False) ff.log('successfully stored rankfile {}'.format(rankfile)) return True
def test_make_pretty(): for u in [ None, False, True, 0, 23, 42, 13.37, list(), dict(), set(), 'a', 'b', ['c', 'd'], {'e': 'f'}, {'g', 'h', 'i'} ]: assert make_pretty(u) == pformat(u)
def test_make_pretty_unprintables(): for u in [ list, dict, set, str, int, bool, type, vars, dir, len, max, min, range, isinstance, pformat, make_pretty ]: assert make_pretty(u) is None
def pretty(self): ''' :return str: current content in a human readable way using **pprint.pformat** ''' return make_pretty(self.c)