def _nodelist_fetch(ff): ''' Determines if ``--nodelist`` was a file or a url, and tries to fetch it. Validates nodelist to be json and to have the *version*, *nodes* and *updated_at* keys. :param ff: running :class:`ffflash.main.FFFlash` instance :return: the unpickled nodelist or ``False``/``None`` on error ''' if not ff.access_for('nodelist'): return False ff.log('fetching nodelist {}'.format(ff.args.nodelist)) nodelist = (load_file(ff.args.nodelist, fallback=None, as_yaml=False) if check_file_location(ff.args.nodelist, must_exist=True) else fetch_www_struct( ff.args.nodelist, fallback=None, as_yaml=False)) if not nodelist or not isinstance(nodelist, dict): return ff.log('could not fetch nodelist {}'.format(ff.args.nodelist), level=False) if not all([(a in nodelist) for a in ['version', 'nodes', 'updated_at']]): return ff.log('this is no nodelist {}'.format(ff.args.nodelist), level=False) ff.log('successfully fetched nodelist from {}'.format(ff.args.nodelist)) return nodelist
def _nodelist_fetch(ff): ''' Determines if ``--nodelist`` was a file or a url, and tries to fetch it. Validates nodelist to be json and to have the *version*, *nodes* and *updated_at* keys. :param ff: running :class:`ffflash.main.FFFlash` instance :return: the unpickled nodelist or ``False``/``None`` on error ''' if not ff.access_for('nodelist'): return False ff.log('fetching nodelist {}'.format(ff.args.nodelist)) nodelist = ( load_file(ff.args.nodelist, fallback=None, as_yaml=False) if check_file_location(ff.args.nodelist, must_exist=True) else fetch_www_struct(ff.args.nodelist, fallback=None, as_yaml=False) ) if not nodelist or not isinstance(nodelist, dict): return ff.log( 'could not fetch nodelist {}'.format(ff.args.nodelist), level=False ) if not all([(a in nodelist) for a in ['version', 'nodes', 'updated_at']]): return ff.log( 'this is no nodelist {}'.format(ff.args.nodelist), level=False ) ff.log('successfully fetched nodelist from {}'.format(ff.args.nodelist)) return nodelist
def __init__(self, args): self.args = args self.location = check_file_location(self.args.APIfile, must_exist=True) self.api = None self.load_api()