def _get_next_int(self, default=None, validRange=None, optional=False): ''' Special case for int params, we only consume if the value is an int so we don't collide with cases where path\file is being specified. Through exceptions if error conditions found ''' if not optional or self.args.is_param_next(): try: nextInt = int(self.args.get_next()) except ValueError: if optional: return default else: raise utils.InputException( STR_ErrorParsingInt.format(self.args.get_current())) if validRange is not None and nextInt not in validRange: raise utils.InputException( STR_ErrorParsingValidValue.format(nextInt, self.args.get_current())) else: self.args.move_next() return nextInt else: return default
def _parse_measurement_path(self): ''' Ensure the path we've been asked to measure is a valid directory and seperate the path from any file filters that was provided If an entry is a valid directory, we'll treat it as a request to measure the folder; if not, we'll treat as a file filter ''' cmdLinePath = self.args.get_current() measurePath = cmdLinePath.rstrip('\\/') if not os.path.isdir(measurePath): filterList = measurePath.split(CMDLINE_SEPARATOR) requestedPath = None for filterItem in filterList: (directory, fileFilter) = os.path.split(filterItem) if ("" == directory) or os.path.isdir(directory): self._app._jobOpt.fileFilters.append(fileFilter) if requestedPath is None: requestedPath = directory else: raise utils.InputException( STR_ErrorBadPath.format(filterItem)) if requestedPath is not None: measurePath = requestedPath if measurePath: self._app._jobOpt.pathsToMeasure.append(measurePath)
def _get_next_param(self, optional=False, default=None): ''' Get next arg for an option Return None if optional and no param ''' if not optional and not self.args.is_param_next(): raise utils.InputException( STR_ErrorParsingValueRequired.format(self.args.get_current())) if self.args.is_param_next(): self.args.move_next() return self.args.get_current() else: return default
def _stash_aggregates(self, filePath, analysisResults): ''' As we receive results for files, if we have requests to aggregate results, store away aggregate information. The aggreate functionality is based on names of items generated by specific csmodules; we consider it a fatal error if what is requested for aggregation and what is present in analysisResults are out of sync ''' # For each set of aggregates we go through results and add # them to the appropriate aggregate set for aggKey, aggNames in self._aggregateNames.iteritems(): aggregateDict = self._aggregates.setdefault(aggKey, {}) trace.file(2, "Aggregating {0} items in {1}".format(len(analysisResults), aggKey)) for result in analysisResults: # aggKey has the name for the value from results that we # will be keying the aggreate dictionary on try: newKey = result[aggKey] except KeyError, e: raise utils.InputException(STR_AggregateKeyError.format(str(e))) else: aggregate = aggregateDict.setdefault(newKey, {'aggregate.count':0}) # Sepcific names can be provided to aggregate, or can do all namesToAggregate = aggNames if isinstance(aggNames, basestring): if aggNames == 'all': namesToAggregate = result.keys() # Take each value from the result and aggregate according to type for itemName in namesToAggregate: self._aggregate_update(itemName, result[itemName], aggregate) # Count the item aggregate['aggregate.count'] += 1 # Update the aggregate aggregateDict[newKey] = aggregate # The dictionary for this aggKey has been updated, so stash it self._aggregates[aggKey] = aggregateDict
def _write_aggregates(self): ''' For each set of aggregates, we create an output file with aggregates that exceed threshold. HACK - We use the output writer by creating a dummy OUT file tag ''' for keyName in self._aggregateNames.keys(): fileName = str(keyName).replace('.', '') hackOutTagMeasure = {'tag_write_aggregates': 'OUT:' + fileName} analysisRows = [] for valueRow in self._aggregates[keyName].values(): writeRow = self._aggregateThresholdKey is None if not writeRow: try: writeRow = valueRow[self._aggregateThresholdKey] > self._aggregateThreshold except KeyError, e: raise utils.InputException(STR_AggregateThresholdKeyError.format(str(e))) if writeRow: analysisRows.append(valueRow) trace.msg(1, "Aggregate: {0}".format(analysisRows)) self._writer.write_items(hackOutTagMeasure, analysisRows)
self._parse_aggregate_options() # Help/invalid parameter request else: return self._parse_help_options() # Setup the default measurement path if not provided if not self._app._jobOpt.pathsToMeasure: self._app._jobOpt.pathsToMeasure.append(utils.CURRENT_FOLDER) # Setup the default config name if not provided if not self.configOverrides and self.configCustom is None: self.configCustom = CONFIG_FILE_DEFAULT_NAME except Args.ArgsFinishedException, e: raise utils.InputException(STR_ErrorParsingEnd.format(str(e))) else: trace.config(4, vars(self._app)) def config_option_list(self): ''' Maps application modifiable config options to the name, value list format used by csmodules to process config file options ''' configOptions = [] configOptions.append(('METADATA', self._metaDataOptions)) if self._measureFilter is not None: if self._measureFilter == CMDARG_OUTPUT_FILTER_METADATA: configOptions.append(('METADATA_ONLY', None)) configOptions.append(('MEASURE_FILTER', '*')) else: