def _print(self, resp, get_content=False): # Avoid to pprint the content attribute. fmt.pprint(resp, ignore_attrs=['content']) if get_content: print('--') print resp.get('status').get('content') sys.stdout.write('--\n')
def print_responses(self): """ Gets responses and displays them asynchronously. """ try: for i in range(len(self.disco_hosts)): resp = self.response_queue.get(True, ayear) if resp in (STOP, STOPALRM): break fmt.pprint(resp) finally: # At the end, dont't forget to reset the number of # discovered host. self.disco_hosts = []
def _save_files(self, responses, path): for resp in responses: if not resp.get('error'): filename = os.path.basename(resp['status']['name']) folder = os.path.join(os.path.abspath(path), resp['uuid']) try: os.makedirs(folder, 0755) except OSError: pass filepath = os.path.join(folder, filename) try: with open(filepath, 'w') as fd: fd.write(resp['status']['content']) except IOError as err: raise ControllerException(err) print "File content saved to %s" % filepath else: fmt.pprint(resp)