Produce output from the report dictionary generated by _generate_report
17781
def _produce_output(report, failed, setup):
    '''
    
    '''
    report_format = setup.get('report_format', 'yaml')

    log.debug('highstate output format: %s', report_format)

    if report_format == 'json':
        report_text = salt.utils.json.dumps(report)
    elif report_format == 'yaml':
        string_file = StringIO()
        salt.utils.yaml.safe_dump(report, string_file, default_flow_style=False)
        string_file.seek(0)
        report_text = string_file.read()
    else:
        string_file = StringIO()
        _generate_html(report, string_file)
        string_file.seek(0)
        report_text = string_file.read()

    report_delivery = setup.get('report_delivery', 'file')

    log.debug('highstate report_delivery: %s', report_delivery)

    if report_delivery == 'file':
        output_file = _sprinkle(setup.get('file_output', '/tmp/test.rpt'))
        with salt.utils.files.fopen(output_file, 'w') as out:
            out.write(salt.utils.stringutils.to_str(report_text))
    else:
        msg = MIMEText(report_text, report_format)

        sender = setup.get('smtp_sender', '')
        recipients = setup.get('smtp_recipients', '')

        host = setup.get('smtp_server', '')
        port = int(setup.get('smtp_port', 25))
        tls = setup.get('smtp_tls')
        username = setup.get('smtp_username')
        password = setup.get('smtp_password')

        if failed:
            subject = setup.get('smtp_failure_subject', 'Installation failure')
        else:
            subject = setup.get('smtp_success_subject', 'Installation success')

        subject = _sprinkle(subject)

        msg['Subject'] = subject
        msg['From'] = sender
        msg['To'] = recipients

        log.debug('highstate smtp port: %d', port)
        smtp = smtplib.SMTP(host=host, port=port)

        if tls is True:
            smtp.starttls()
            log.debug('highstate smtp tls enabled')

        if username and password:
            smtp.login(username, password)
            log.debug('highstate smtp authenticated')

        smtp.sendmail(
            sender,
            [x.strip() for x in recipients.split(',')], msg.as_string())
        log.debug('highstate message sent.')

        smtp.quit()
147142
def get_report_data(self, report):
        
        ar = report.getAnalysisRequest()
        attachments = map(self.get_attachment_data, ar.getAttachment())
        pdf = self.get_pdf(report)
        filesize = "{} Kb".format(self.get_filesize(pdf))
        filename = "{}.pdf".format(ar.getId())

        return {
            "ar": ar,
            "attachments": attachments,
            "pdf": pdf,
            "obj": report,
            "uid": api.get_uid(report),
            "filesize": filesize,
            "filename": filename,
        }
947211
def write_template(data, results_dir, parent):
    
    print("Generating html report...")
    partial = time.time()
    j_env = Environment(loader=FileSystemLoader(os.path.join(results_dir, parent, 'templates')))
    template = j_env.get_template('report.html')

    report_writer = ReportWriter(results_dir, parent)
    report_writer.write_report(template.render(data))
    print("HTML report generated in {} seconds\n".format(time.time() - partial))
839263
def process_module_output(self, module):
        
        outputs = module["module"].get_latest()
        color = module["color"]
        if color:
            for output in outputs:
                # Color: substitute the config defined color
                if "color" not in output:
                    output["color"] = color
        # Create the json string output.
        return ",".join([dumps(x) for x in outputs])
603572
def output_results(results, metric, options):
    
    formatter = options['Formatter']
    context = metric.copy()  # XXX might need to sanitize this
    try:
        context['dimension'] = list(metric['Dimensions'].values())[0]
    except AttributeError:
        context['dimension'] = ''
    for result in results:
        stat_keys = metric['Statistics']
        if not isinstance(stat_keys, list):
            stat_keys = [stat_keys]
        for statistic in stat_keys:
            context['statistic'] = statistic
            # get and then sanitize metric name, first copy the unit name from the
            # result to the context to keep the default format happy
            context['Unit'] = result['Unit']
            metric_name = (formatter % context).replace('/', '.').lower()
            line = '{0} {1} {2}\n'.format(
                metric_name,
                result[statistic],
                timegm(result['Timestamp'].timetuple()),
            )
            sys.stdout.write(line)
927751
def getOutputBlocks():
    """"""
    raw=open("output.txt").read()
    d={}
    for block in raw.split("\n####### ")[1:]:
        title=block.split("\n")[0].split("(")[0]
        block=block.split("\n",1)[1].strip()
        d[title]=block.split("\nfinished in ")[0]
    return d
294788
def _output_to_dict(cmdoutput, values_mapper=None):
    '''
    
    '''
    if isinstance(cmdoutput, dict):
        if cmdoutput['retcode'] != 0 or cmdoutput['stderr']:
            raise CommandExecutionError(
                'RabbitMQ command failed: {0}'.format(cmdoutput['stderr'])
            )
        cmdoutput = cmdoutput['stdout']

    ret = {}
    if values_mapper is None:
        values_mapper = lambda string: string.split('\t')

    # remove first and last line: Listing ... - ...done
    data_rows = _strip_listing_to_done(cmdoutput.splitlines())

    for row in data_rows:
        try:
            key, values = row.split('\t', 1)
        except ValueError:
            # If we have reached this far, we've hit an edge case where the row
            # only has one item: the key. The key doesn't have any values, so we
            # set it to an empty string to preserve rabbitmq reporting behavior.
            # e.g. A user's permission string for '/' is set to ['', '', ''],
            # Rabbitmq reports this only as '/' from the rabbitmqctl command.
            log.debug('Could not find any values for key \'%s\'. '
                      'Setting to \'%s\' to an empty string.', row, row)
            ret[row] = ''
            continue
        ret[key] = values_mapper(values)
    return ret
230217
def _generate_report(ret, setup):
    '''
    
    '''

    retdata = ret.get('return', {})

    sorted_data = sorted(
        retdata.items(),
        key=lambda s: s[1].get('__run_num__', 0)
    )

    total = 0
    failed = 0
    changed = 0
    duration = 0.0

    # gather stats
    for _, data in sorted_data:
        if not data.get('result', True):
            failed += 1
        total += 1

        try:
            duration += float(data.get('duration', 0.0))
        except ValueError:
            pass

        if data.get('changes', {}):
            changed += 1

    unchanged = total - failed - changed

    log.debug('highstate total: %s', total)
    log.debug('highstate failed: %s', failed)
    log.debug('highstate unchanged: %s', unchanged)
    log.debug('highstate changed: %s', changed)

    # generate report if required
    if setup.get('report_everything', False) or \
       (setup.get('report_changes', True) and changed != 0) or \
       (setup.get('report_failures', True) and failed != 0):

        report = [
            {'stats': [
                {'total': total},
                {'failed': failed, '__style__': 'failed'},
                {'unchanged': unchanged, '__style__': 'unchanged'},
                {'changed': changed, '__style__': 'changed'},
                {'duration': duration}
            ]},
            {'job': [
                {'function': ret.get('fun', '')},
                {'arguments': ret.get('fun_args', '')},
                {'jid': ret.get('jid', '')},
                {'success': ret.get('success', True)},
                {'retcode': ret.get('retcode', 0)}
            ]},
            {'states': _generate_states_report(sorted_data)}
        ]

        if failed:
            function = setup.get('failure_function', None)
        else:
            function = setup.get('success_function', None)

        if function:
            func_result = __salt__[function]()
            report.insert(
                0,
                {'extra': [{function: _dict_to_name_value(func_result)}]}
            )

    else:
        report = []

    return report, failed
467059
def get_outputs(self, input_value):
        
        output_value = self.convert_to_xmlrpc(input_value)

        output = {}
        for name in self.output_names:
            output[name] = output_value

        return output
876525
def process_results(output_dir, config):
    
    print('\nanalyzing results...\n')
    res = output_results(output_dir, config)
    if res:
        print('created: %s/results.html\n' % output_dir)
    else:
        print('results cannot be processed')
944550
def get_output_dict(stack):
    
    outputs = {}
    if 'Outputs' not in stack:
        return outputs

    for output in stack['Outputs']:
        logger.debug("    %s %s: %s", stack['StackName'], output['OutputKey'],
                     output['OutputValue'])
        outputs[output['OutputKey']] = output['OutputValue']
    return outputs
581533
def generate(self, output_file=None):
        

        fd = output_file

        # Write to stdout if we do not have a file to write to
        if not fd:
            fd = stdout
        else:
            try:
                fd = open(output_file, 'w')
            except IOError as e:
                stderr.write('Unable to open outputfile %s: %s' % (output_file, e))

        with open(os.path.join(os.path.dirname(__file__), 'templates/base.html')) as template:
            html = Template(template.read())

            # Write potential build messages to stdout if we are writing to HTML file
            # If dest is stdout and supposed to be piped or redirected, build messages like TeamCity's will
            # have no effect, since they require to read from stdin.
            if output_file:
                self.report_build_messages()

            # Write our rendered template to the file descriptor
            fd.write(
                html.render(
                    files=sorted(self.files.values(), key=lambda x: x.path),
                    total_warnings=self.total_warnings,
                    total_errors=self.total_errors,
                    total_other=self.total_other,
                    violations=sorted(
                        ((code, count) for code, count in self.violations.items()),
                        key=lambda x: x[1],
                        reverse=True,
                    )
                )
            )

            # If file descriptor is stdout
            if not output_file:
                fd.flush()
            else:
                fd.close()
466397
def generate_output(listing, title, date):
    
    listing_string = '{0}\n{1}\n\n'.format(title, date)
    for entry in listing:
        listing_string += '\n'.join(entry) + '\n***\n'
    return listing_string
790925
def generate_specifications(self, count=1):
        

        out = {}

        # mapping of UID index to AR objects {1: <AR1>, 2: <AR2> ...}
        copy_from = self.get_copy_from()

        for arnum in range(count):
            # get the source object
            source = copy_from.get(arnum)

            if source is None:
                out[arnum] = {}
                continue

            # get the results range from the source object
            results_range = source.getResultsRange()

            # mapping of keyword -> rr specification
            specification = {}
            for rr in results_range:
                specification[rr.get("keyword")] = rr
            out[arnum] = specification

        return out
1263727
private void generateOutput() {
    final Filer filer = processingEnv.getFiler();
    writeJsonToFile(filer, "JSONClasses", jsonClasses);
    writeJsonToFile(filer, "debugcrud", debugMessages);

    final List<ResourceMethod> resources = Lists.newArrayList();
    for (ResourceClass klass : resourceClasses.values()) {
      final String path = klass.getPath();

      for (final ResourceMethod method : klass.getMembers()) {
        resources.add(new ResourceMethod("", method.getMethod(),
            computeDisplayPath(path, method.getPath()),
            method.getReturnContentType(), method.getReturnType(), method.getArguments(),
            method.getJavadoc()));
      }
    }
    writeJsonToFile(filer, "RESTEndpoints", resources);
  }
669054
def print_rendered_results(results_dict):
    
    class _HubComponentEncoder(json.JSONEncoder):
        def default(self, o):
            if isinstance(o, base.HubComponent):
                return repr(o)
            return json.JSONEncoder.default(self, o)
    formatted = json.dumps(results_dict, indent=4, cls=_HubComponentEncoder)
    # the returned string contains lines with trailing spaces, which causes
    # doctests to fail.  So fix that here.
    for s in formatted.splitlines():
        print(s.rstrip())
903202
def output(results_dir, config, parent='../../'):
    
    start = time.time()
    print("Compiling results...")
    results_dir = os.path.abspath(results_dir)
    results = ReportResults(config['run_time'], config['results_ts_interval'])
    results.compile_results()
    print("Results compiled in {} seconds\n".format(time.time() - start))

    if results.total_transactions == 0:
        print("No results, cannot create report")
        return False

    print_infos(results)

    data = {
        'report': results,
        'run_time': config['run_time'],
        'ts_interval': config['results_ts_interval'],
        'turrets_config': results.turrets,
        'results': {"all": results.main_results, "timers": results.timers_results}
    }

    print("Generating graphs...")
    partial = time.time()
    generate_graphs(results.main_results, 'All_Transactions', results_dir)

    for key, value in results.timers_results.items():
        generate_graphs(value, key, results_dir)
    print("All graphs generated in {} seconds\n".format(time.time() - partial))

    write_template(data, results_dir, parent)
    print("Full report generated in {} seconds".format(time.time() - start))
    return True