<commit_before>#!/usr/bin/env python

import sys
import os
import re
import traceback

import anchore.anchore_utils

# main routine

try:
    config = anchore.anchore_utils.init_query_cmdline(sys.argv, "params: <thing> <thing> ...\nhelp: helpstring sentence")
except Exception as err:
    print str(err)
    sys.exit(1)

if not config:
    sys.exit(0)

if len(config['params']) <= 0:
    print "Query requires input: <packageA> <packageB> ..."

warns = list()
outlist = list()
outlist.append(["ImageId", "Repo/Tags", "StoredFileName", "StoredFileSizeBytes"])

tags = "none"
if config['meta']['humanname']:
    tags = config['meta']['humanname']
imgid = config['meta']['shortId']

try:
    # handle the good case, something is found resulting in data matching the required columns
    import tarfile, io
    
    stored_data_tarfile = anchore.anchore_utils.load_analysis_output(config['imgid'], 'retrieve_files', 'file_cache')
    if stored_data_tarfile:
        tar = tarfile.open(fileobj=stored_data_tarfile, mode='r:gz', format=tarfile.PAX_FORMAT)
        for f in tar.getmembers():
            if re.match(".*stored_files.tar.gz", f.name):
                data = tar.extractfile(f)
                filetar = tarfile.open(fileobj=data, mode='r:gz', format=tarfile.PAX_FORMAT)
                for ff in filetar.getmembers():
                    scrubbed_name = re.sub("imageroot", "", ff.name)
                    outlist.append([imgid, tags, scrubbed_name, str(ff.size)])
                filetar.close()<commit_msg>fix the helpstring for list_retrieved_files query<commit_after>#!/usr/bin/env python

import sys
import os
import re
import traceback

import anchore.anchore_utils

# main routine

try:
    config = anchore.anchore_utils.init_query_cmdline(sys.argv, "params: all | <file> <file> ...\nhelp: produce a list of all files that have been successfully retrieved and stored during analysis of this image.  Files listed here can be used as input to the get-retrieved-files query.")
except Exception as err:
    print str(err)
    sys.exit(1)

if not config:
    sys.exit(0)

if len(config['params']) <= 0:
    print "Query requires input: all | <fileA> <fileB> ..."

warns = list()
outlist = list()
outlist.append(["ImageId", "Repo/Tags", "StoredFileName", "StoredFileSizeBytes"])

tags = "none"
if config['meta']['humanname']:
    tags = config['meta']['humanname']
imgid = config['meta']['shortId']

try:
    # handle the good case, something is found resulting in data matching the required columns
    import tarfile, io
    
    stored_data_tarfile = anchore.anchore_utils.load_analysis_output(config['imgid'], 'retrieve_files', 'file_cache')
    if stored_data_tarfile:
        tar = tarfile.open(fileobj=stored_data_tarfile, mode='r:gz', format=tarfile.PAX_FORMAT)
        for f in tar.getmembers():
            if re.match(".*stored_files.tar.gz", f.name):
                data = tar.extractfile(f)
                filetar = tarfile.open(fileobj=data, mode='r:gz', format=tarfile.PAX_FORMAT)
                for ff in filetar.getmembers():
                    scrubbed_name = re.sub("imageroot", "", ff.name)
                    outlist.append([imgid, tags, scrubbed_name, str(ff.size)])
                filetar.close()
{'fraction_non_alphanumeric': 0.12978986402966625, 'fraction_numerical': 0.001854140914709518, 'mean_word_length': 3.356662180349933, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4665987', 'n_tokens_mistral': 1047, 'n_tokens_neox': 1027, 'n_words': 258}