def execute(self, args): # pylint: disable=no-self-use,too-many-branches,too-many-statements loader = ExtensionLoader(packages=settings.extension_packages, paths=settings.extension_paths) agenda = OrderedDict() agenda['config'] = OrderedDict(instrumentation=[], result_processors=[]) agenda['global'] = OrderedDict(iterations=args.iterations) agenda['workloads'] = [] device = None device_config = None for name in args.extensions: extcls = loader.get_extension_class(name) config = loader.get_default_config(name) del config['modules'] if extcls.kind == 'workload': entry = OrderedDict() entry['name'] = extcls.name if name != extcls.name: entry['label'] = name entry['params'] = config agenda['workloads'].append(entry) elif extcls.kind == 'device': if device is not None: raise ConfigError('Specifying multiple devices: {} and {}'.format(device.name, name)) device = extcls device_config = config agenda['config']['device'] = name agenda['config']['device_config'] = config else: if extcls.kind == 'instrument': agenda['config']['instrumentation'].append(name) if extcls.kind == 'result_processor': agenda['config']['result_processors'].append(name) agenda['config'][name] = config if args.include_runtime_params: if not device: if settings.device: device = loader.get_extension_class(settings.device) device_config = loader.get_default_config(settings.device) else: raise ConfigError('-r option requires for a device to be in the list of extensions') rps = OrderedDict() for rp in device.runtime_parameters: if hasattr(rp, 'get_runtime_parameters'): # a core parameter needs to be expanded for each of the # device's cores, if they're avialable for crp in rp.get_runtime_parameters(device_config.get('core_names', [])): rps[crp.name] = None else: rps[rp.name] = None agenda['global']['runtime_params'] = rps if args.output: wfh = open(args.output, 'w') else: wfh = sys.stdout yaml.dump(agenda, wfh, indent=4, default_flow_style=False) if args.output: wfh.close()
def execute(self, args): # pylint: disable=unpacking-non-sequence ext_loader = ExtensionLoader(packages=settings.extension_packages, paths=settings.extension_paths) extension = ext_loader.get_extension_class(args.name) out = StringIO() term_width, term_height = get_terminal_size() format_extension(extension, out, term_width) text = out.getvalue() pager = get_pager() if len(text.split('\n')) > term_height and pager: try: sp = subprocess.Popen(pager, stdin=subprocess.PIPE) sp.communicate(text) except OSError: self.logger.warning('Could not use PAGER "{}"'.format(pager)) sys.stdout.write(text) else: sys.stdout.write(text)