/usr/lib/python2.7/dist-packages/charmtools/build/inspector.py is in charm-tools 2.1.2-0ubuntu4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | # coding=utf-8
import json
from ruamel import yaml
from charmtools.build import config
from charmtools import utils
theme = {
0: "normal",
1: "green",
2: "cyan",
3: "magenta",
4: "yellow",
5: "red",
}
def scan_for(col, cur, depth):
for e, (rel, d) in col[cur:]:
if d and d == depth:
return True
return False
def get_prefix(walk, cur, depth, next_depth):
guide = []
for i in range(depth):
# scan forward in walk from i seeing if a subsequent
# entry happens at each depth
if scan_for(walk, cur, i):
guide.append(" │ ")
else:
guide.append(" ")
if depth == next_depth:
prefix = " ├─── "
else:
prefix = " └─── "
return "{}{}".format("".join(guide), prefix)
def inspect(charm, force_styling=False):
tw = utils.TermWriter(force_styling=force_styling)
manp = charm / ".build.manifest"
comp = charm / "layer.yaml"
if not manp.exists() or not comp.exists():
return
manifest = json.loads(manp.text())
composer = yaml.load(comp.open())
a, c, d = utils.delta_signatures(manp)
# ordered list of layers used for legend
layers = list(manifest['layers'])
def get_depth(e):
rel = e.relpath(charm)
depth = len(rel.splitall()) - 2
return rel, depth
def get_suffix(rel):
suffix = ""
if rel in a:
suffix = "+"
elif rel in c:
suffix = "*"
return suffix
def get_color(rel):
# name of layer this belongs to
color = tw.term.normal
if rel in manifest['signatures']:
layer = manifest['signatures'][rel][0]
layer_key = layers.index(layer)
color = getattr(tw, theme.get(layer_key, "normal"))
else:
if entry.isdir():
color = tw.blue
return color
tw.write("Inspect %s\n" % composer["is"])
for layer in layers:
tw.write("# {color}{layer}{t.normal}\n",
color=getattr(tw, theme.get(
layers.index(layer), "normal")),
layer=layer)
tw.write("\n")
tw.write("{t.blue}{target}{t.normal}\n", target=charm)
ignorer = utils.ignore_matcher(config.DEFAULT_IGNORES)
walk = sorted(utils.walk(charm, get_depth),
key=lambda x: x[1][0])
for i in range(len(walk) - 1):
entry, (rel, depth) = walk[i]
nEnt, (nrel, ndepth) = walk[i + 1]
if not ignorer(rel):
continue
tw.write("{prefix}{layerColor}{entry} "
"{t.bold}{suffix}{t.normal}\n",
prefix=get_prefix(walk, i, depth, ndepth),
layerColor=get_color(rel),
suffix=get_suffix(rel),
entry=rel.name)
|