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
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)
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)
# Now we can generate a little matrix of similarity scores! print('Calculating (non optimized) score matrix!') for container1 in containers: score_row = [] for container2 in containers: 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": containers, "Y": containers} with open('%s/data.json' % webroot, 'w') as filey: filey.writelines(json.dumps(data)) serve_template(webroot, port=9779)