Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if not exists(config):
handle_no_cache(ctx)
if not metrics:
metrics = get_default_metrics(config)
logger.info(f"Using default metrics {metrics}")
new_output = Path().cwd()
if output:
new_output = new_output / Path(output)
else:
new_output = new_output / "wily_report" / "index.html"
from wily.commands.report import report
logger.debug(f"Running report on {file} for metric {metrics}")
logger.debug(f"Output format is {format}")
report(
config=config,
path=file,
metrics=metrics,
n=number,
output=new_output,
include_message=message,
format=ReportFormat[format],
console_format=console_format,
)
def clean(config):
"""
Delete a wily cache.
:param config: The configuration
:type config: :class:`wily.config.WilyConfig`
"""
if not exists(config):
logger.debug("Wily cache does not exist, skipping")
return
shutil.rmtree(config.cache_path)
logger.debug("Deleted wily cache")
def save(self):
"""Save the index data back to the wily cache."""
data = [i.asdict() for i in self._revisions.values()]
logger.debug("Saving data")
cache.store_archiver_index(self.config, self.archiver, data)
def run_operator(
operator: Operator, revision: Revision, config: WilyConfig, targets: List[str]
) -> Tuple[str, Dict]:
"""
Run an operator for the multiprocessing pool.
:param operator: The operator name
:param revision: The revision index
:param config: The runtime configuration
:param targets: Files/paths to scan
:returns: A tuple of operator name (``str``), and data (``dict``)
"""
instance = operator.cls(config, targets)
logger.debug(f"Running {operator.name} operator on {revision}")
data = instance.run(revision, config)
# Normalize paths for non-seed passes
for key in list(data.keys()):
if os.path.isabs(key):
rel = os.path.relpath(key, config.path)
data[rel] = data[key]
del data[key]
return operator.name, data
def index(config, include_message=False):
"""
Show information about the cache and runtime.
:param config: The wily configuration
:type config: :namedtuple:`wily.config.WilyConfig`
:param include_message: Include revision messages
:type include_message: ``bool``
"""
state = State(config=config)
logger.debug("Running show command")
logger.info("--------Configuration---------")
logger.info(f"Path: {config.path}")
logger.info(f"Archiver: {config.archiver}")
logger.info(f"Operators: {config.operators}")
logger.info("")
logger.info("-----------History------------")
data = []
for archiver in state.archivers:
for rev in state.index[archiver].revisions[::-1]:
if include_message:
data.append(
(
format_revision(rev.revision.key),
rev.revision.author_name,
rev.revision.message[:MAX_MESSAGE_WIDTH],