コード例 #1
0
 def test_get_template(self):
     '''test that template names / files are correctly returned'''
     from containertree.utils import get_templates, get_template
     templates = get_templates()
     self.assertTrue("treemap" in templates)
     template = get_template("treemap")
     self.assertTrue("treemap.html" in template)
     template = get_template("doesnt-exist")
     self.assertTrue(template == None)
コード例 #2
0
def main(args):

    # No image or uri provided, print help
    if len(args.image) == 0:
        subparser.print_help()
        sys.exit(1)

    image = args.image.pop(0)

    # Step 1: Generate container tree object from Docker URI
    tree = ContainerFileTree(image)
    bot.debug(tree)

    # Step 2: Create a webroot to serve from
    webroot = args.output
    if args.output is None:
        webroot = get_tmpdir('containertree-')

    if not os.path.exists(webroot):
        os.mkdir(webroot)

    bot.debug('Webroot: %s' % webroot)

    # Copy the template to the webroot
    template = get_template(args.template)
    shutil.copyfile(template, "%s/index.html" % webroot)

    # If the user wants to print to terminal, we don't save
    filename = None
    if args.printout == None:
        filename = '%s/data.json' % webroot

    # Export data.json
    bot.debug('Exporting data for d3 visualization')
    data = tree.export_tree(filename)

    # Does the user want to view the tree?
    if args.view:
        # Generate the data.json
        serve_template(webroot, 9779)

    # Does the user want to print output?
    elif args.printout != None:
        if args.printout == "data.json":
            print(data)
        elif args.printout == "index.html":
            template = read_file(template)
            print(template)

    return webroot
コード例 #3
0
import tempfile

# Path to database of container-api
database = "https://singularityhub.github.io/api/files"
print('Selecting container from %s...' %database)
containers = requests.get(database).json()
entry = containers[0]

# Google Container Diff Structure
print('Generating tree!')
tree = ContainerFileTree(entry['url'])
print(tree)
# ContainerTree<38008>

# Create temporary directory and copy file there
from containertree.utils import get_template
from containertree.server import serve_template
import shutil
import tempfile

# Copy the file to the webroot
webroot = tempfile.mkdtemp()
print('Webroot: %s' %webroot)
template = get_template('tree')
shutil.copyfile(template, "%s/index.html" %webroot)

# Generate the data.json
print('Exporting data for d3 visualization')
tree.export_tree(filename='%s/data.json' %webroot)
serve_template(webroot)
コード例 #4
0
# Now we can generate a little matrix of similarity scores!
print('Calculating (non optimized) score matrix!')
for container1 in names:
    score_row = []
    for container2 in names:
        tags = [container1, container2]
        result = tree.similarity_score(tags)
        score_row.append(result['score'])
    score_matrix.append(score_row)

# Create temporary directory and copy file there
from containertree.utils import get_template
from containertree.server import serve_template
import shutil
import tempfile

# Copy the file to the webroot
webroot = tempfile.mkdtemp()
print('Webroot: %s' % webroot)
template = get_template('heatmap')
shutil.copyfile(template, "%s/index.html" % webroot)

# Generate the data.json
print('Exporting data for d3 visualization')
data = {"data": score_matrix, "X": names, "Y": names}
with open('%s/data.json' % webroot, 'w') as filey:
    filey.writelines(json.dumps(data))

serve_template(webroot)
コード例 #5
0
database = "https://singularityhub.github.io/api/files"
print('Selecting container from %s...' %database)
containers = requests.get(database).json()
container1 = containers[0]
container2 = containers[1]

# Google Container Diff Structure
print('Generating files tree!')
tree = ContainerFileTree(container1['url'])
tree.update(container2['url'])

print(tree)
# ContainerTree<56386>

# Create temporary directory and copy file there
from containertree.utils import get_template
from containertree.server import serve_template
import shutil
import tempfile

# Copy the file to the webroot
webroot = tempfile.mkdtemp()
print('Webroot: %s' %webroot)
template = get_template('files_tree')
shutil.copyfile(template, "%s/index.html" %webroot)

# Generate the data.json
print('Exporting data for d3 visualization')
tree.export_tree(filename='%s/data.json' %webroot)
serve_template(webroot, 9779)
コード例 #6
0
df = scores.melt('container1')
df.columns = ['container1', 'container2', 'values']

# Create a data structure of rows and columns
rows = []
cols = []
for r in range(nrow):
    for c in range(ncol):
        rows.append(r + 1)
        cols.append(c + 1)

df['x'] = rows
df['y'] = cols

df.to_csv('data.tsv', sep='\t', index=None)
template = get_template('heatmap-large')
shutil.copyfile(template, "%s/index.html" % here)

# This is the only meaningful way!

# Here is a busy plot for ALL containers, a heatmap that isn't so usable
import seaborn as sns
import matplotlib.pylab as plt
plotdf = pandas.DataFrame(scores.values.tolist())
plotdf.columns = scores.columns
plotdf.index = scores.index
sns.heatmap(plotdf, fmt="g", cmap='viridis')
plt.show()

# Let's be selfish and remove row sums that are lowest
コード例 #7
0
database = "https://singularityhub.github.io/api/files"
print('Selecting container from %s...' % database)
containers = requests.get(database).json()
container1 = containers[0]
container2 = containers[1]

# Google Container Diff Structure
print('Generating tree!')
tree = ContainerFileTree(container1['url'])
tree.update(container2['url'])

print(tree)
# ContainerTree<38008>

# Create temporary directory and copy file there
from containertree.utils import get_template
from containertree.server import serve_template
import shutil
import tempfile

# Copy the file to the webroot
webroot = tempfile.mkdtemp()
print('Webroot: %s' % webroot)
template = get_template('shub_tree')
shutil.copyfile(template, "%s/index.html" % webroot)

# Generate the data.json
print('Exporting data for d3 visualization')
tree.export_tree(filename='%s/data.json' % webroot)
serve_template(webroot)