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 save(self): ''' Save content from :attr:`api` (:class:`ffflash.lib.api.FFApi`) into :attr:`location`. A :meth:`ffflash.lib.api.FFApi.timestamp` is triggered before saving. ''' if self.access_for('api'): self.set_timestamp() return dump_file(self.location, self.api.c, as_yaml=False)
def _sidecar_dump(ff, sidepath, content, fields, as_yaml): ''' Stores ``content`` both in :attr:`api` and ``sidepath``. :param ff: running :class:`ffflash.main.FFFlash` instance :param sidepath: full path to the sidecar :param content: the value to store into sidecar/api-file :param fields: key-names into api-file :param as_yaml: dump as *yaml* instead of *json* :return: ``True`` if ``sidepath`` was modified else ``False`` ''' if not ff.access_for('sidecars'): return False if ff.api.pull(*fields) is None: return ff.log('{} does not exist. can\'t push'.format( '.'.join(fields)), level=None) ff.api.push(content, *fields) dump_file(sidepath, content, as_yaml=as_yaml) ff.log('saved sidecar {}'.format(sidepath)) return True
def _sidecar_dump(ff, sidepath, content, fields, as_yaml): ''' Stores ``content`` both in :attr:`api` and ``sidepath``. :param ff: running :class:`ffflash.main.FFFlash` instance :param sidepath: full path to the sidecar :param content: the value to store into sidecar/api-file :param fields: key-names into api-file :param as_yaml: dump as *yaml* instead of *json* :return: ``True`` if ``sidepath`` was modified else ``False`` ''' if not ff.access_for('sidecars'): return False if ff.api.pull(*fields) is None: return ff.log( '{} does not exist. can\'t push'.format('.'.join(fields)), level=None ) ff.api.push(content, *fields) dump_file(sidepath, content, as_yaml=as_yaml) ff.log('saved sidecar {}'.format(sidepath)) return True
def dy(loc, cont): return dump_file(loc, cont, as_yaml=True)
def dj(loc, cont): return dump_file(loc, cont, as_yaml=False)