def register_parser(self, subparsers): parser = subparsers.add_parser("run", help="run a test job") parser.set_defaults(command=self) group = parser.add_argument_group(title="user interface options") group.add_argument( '--not-interactive', action='store_true', help="Skip tests that require interactivity") group.add_argument( '-n', '--dry-run', action='store_true', help="Don't actually run any jobs") group = parser.add_argument_group("output options") assert 'text' in get_all_exporters() group.add_argument( '-f', '--output-format', default='text', metavar='FORMAT', choices=['?'] + list( get_all_exporters().keys()), help=('Save test results in the specified FORMAT' ' (pass ? for a list of choices)')) group.add_argument( '-p', '--output-options', default='', metavar='OPTIONS', help=('Comma-separated list of options for the export mechanism' ' (pass ? for a list of choices)')) group.add_argument( '-o', '--output-file', default='-', metavar='FILE', type=FileType("wt"), help=('Save test results to the specified FILE' ' (or to stdout if FILE is -)')) # Call enhance_parser from CheckBoxCommandMixIn self.enhance_parser(parser)
def register_parser(self, subparsers): parser = subparsers.add_parser("run", help="run a test job") parser.set_defaults(command=self) group = parser.add_argument_group(title="user interface options") group.add_argument( '--not-interactive', action='store_true', help="Skip tests that require interactivity") group.add_argument( '-n', '--dry-run', action='store_true', help="Don't actually run any jobs") group = parser.add_argument_group("output options") assert 'text' in get_all_exporters() group.add_argument( '-f', '--output-format', default='text', metavar='FORMAT', choices=['?'] + list( get_all_exporters().keys()), help=('Save test results in the specified FORMAT' ' (pass ? for a list of choices)')) group.add_argument( '-p', '--output-options', default='', metavar='OPTIONS', help=('Comma-separated list of options for the export mechanism' ' (pass ? for a list of choices)')) group.add_argument( '-o', '--output-file', default='-', metavar='FILE', type=FileType("wb"), help=('Save test results to the specified FILE' ' (or to stdout if FILE is -)')) group.add_argument( '-t', '--transport', metavar='TRANSPORT', choices=['?'] + list( get_all_transports().keys()), help=('use TRANSPORT to send results somewhere' ' (pass ? for a list of choices)')) group.add_argument( '--transport-where', metavar='WHERE', help=('Where to send data using the selected transport.' ' This is passed as-is and is transport-dependent.')) group.add_argument( '--transport-options', metavar='OPTIONS', help=('Comma-separated list of key-value options (k=v) to ' ' be passed to the transport.')) # Call enhance_parser from CheckBoxCommandMixIn self.enhance_parser(parser)
def save_results(self, session): if self.is_interactive: print("[ Results ]".center(80, '=')) exporter = get_all_exporters()['text']() exported_stream = io.BytesIO() data_subset = exporter.get_session_data_subset(session) exporter.dump(data_subset, exported_stream) exported_stream.seek(0) # Need to rewind the file, puagh # This requires a bit more finesse, as exporters output bytes # and stdout needs a string. translating_stream = ByteStringStreamTranslator( sys.stdout, "utf-8") copyfileobj(exported_stream, translating_stream) base_dir = os.path.join( os.getenv( 'XDG_DATA_HOME', os.path.expanduser("~/.local/share/")), "plainbox") if not os.path.exists(base_dir): os.makedirs(base_dir) results_file = os.path.join(base_dir, 'results.html') submission_file = os.path.join(base_dir, 'submission.xml') exporter_list = [XMLSessionStateExporter, HTMLSessionStateExporter] if 'xlsx' in get_all_exporters(): from plainbox.impl.exporter.xlsx import XLSXSessionStateExporter exporter_list.append(XLSXSessionStateExporter) for exporter_cls in exporter_list: # Options are only relevant to the XLSX exporter exporter = exporter_cls( ['with-sys-info', 'with-summary', 'with-job-description', 'with-text-attachments']) data_subset = exporter.get_session_data_subset(session) results_path = results_file if exporter_cls is XMLSessionStateExporter: results_path = submission_file if 'xlsx' in get_all_exporters(): if exporter_cls is XLSXSessionStateExporter: results_path = results_path.replace('html', 'xlsx') with open(results_path, "wb") as stream: exporter.dump(data_subset, stream) print("\nSaving submission file to {}".format(submission_file)) self.submission_file = submission_file print("View results (HTML): file://{}".format(results_file)) if 'xlsx' in get_all_exporters(): print("View results (XLSX): file://{}".format( results_file.replace('html', 'xlsx')))
def _prepare_exporter(self, ns): exporter_cls = get_all_exporters()[ns.output_format] if ns.output_options: option_list = ns.output_options.split(',') else: option_list = None try: exporter = exporter_cls(option_list) except ValueError as exc: raise SystemExit(str(exc)) return exporter
def _print_output_option_list(self, ns): print("Each format may support a different set of options") for name, exporter_cls in get_all_exporters().items(): print("{}: {}".format( name, ", ".join(exporter_cls.supported_option_list)))
def _print_output_format_list(self, ns): print("Available output formats: {}".format( ', '.join(get_all_exporters())))
def _export_session_to_stream(self, session, output_format, option_list, stream): exporter_cls = get_all_exporters()[output_format] exporter = exporter_cls(option_list) data_subset = exporter.get_session_data_subset(session) exporter.dump(data_subset, stream)
def get_all_exporters(self): return {name: exporter_cls.supported_option_list for name, exporter_cls in get_all_exporters().items()}
def _print_output_format_list(self, ns): print(_("Available output formats: {}").format( ', '.join(get_all_exporters())))
def get_all_exporters(self): return { name: exporter_cls.supported_option_list for name, exporter_cls in get_all_exporters().items() }