Exemple #1
0
    def validate(self):
        p = self.target_dir / ".composer.manifest"
        if not p.exists():
            return [], [], []
        ignorer = utils.ignore_matcher(DEFAULT_IGNORES)
        a, c, d = utils.delta_signatures(p, ignorer)

        for f in a:
            log.warn(
                "Added unexpected file, should be in a base layer: %s", f)
        for f in c:
            log.warn(
                "Changed file owned by another layer: %s", f)
        for f in d:
            log.warn(
                "Deleted a file owned by another layer: %s", f)
        if a or c or d:
            if self.force is False:
                log.info(
                    "Continuing with known changes to target layer. "
                    "Changes will be overwritten")
            else:
                raise ValueError(
                    "Unable to continue due to unexpected modifications")
        return a, c, d
Exemple #2
0
 def __call__(self):
     if self.entity.isdir():
         return
     should_ignore = utils.ignore_matcher(self.target.config.ignores)
     if not should_ignore(self.relpath):
         return
     target = self.target_file
     log.debug("Copying %s: %s", self.layer_name, target)
     # Ensure the path exists
     target.dirname().makedirs_p()
     if (self.entity != target) and not target.exists() \
             or not self.entity.samefile(target):
         data = self.read()
         if data:
             target.write_bytes(data)
             self.entity.copymode(target)
         else:
             self.entity.copy2(target)
Exemple #3
0
 def __call__(self):
     if self.entity.isdir():
         return
     should_ignore = utils.ignore_matcher(self.target.config.ignores)
     if not should_ignore(self.relpath):
         return
     target = self.target_file
     log.debug("Copying %s: %s", self.layer_name, target)
     # Ensure the path exists
     target.dirname().makedirs_p()
     if (self.entity != target) and not target.exists() \
             or not self.entity.samefile(target):
         data = self.read()
         if data:
             target.write_bytes(data)
             self.entity.copymode(target)
         else:
             self.entity.copy2(target)
Exemple #4
0
 def __call__(self):
     # copy the entire tree into the
     # hooks/relations/<interface>
     # directory
     log.debug("Copying Interface %s: %s", self.interface.name, self.target)
     # Ensure the path exists
     if self.target.exists():
         # XXX: fix this to do actual updates
         return
     ignorer = utils.ignore_matcher(self.config.ignores)
     for entity, _ in utils.walk(self.interface.directory,
                                 lambda x: True,
                                 matcher=ignorer,
                                 kind="files"):
         target = entity.relpath(self.interface.directory)
         target = (self.target / target).normpath()
         target.parent.makedirs_p()
         entity.copy2(target)
     init = self.target / "__init__.py"
     if not init.exists():
         # ensure we can import from here directly
         init.touch()
Exemple #5
0
 def __call__(self):
     # copy the entire tree into the
     # hooks/relations/<interface>
     # directory
     log.debug("Copying Interface %s: %s",
               self.interface.name, self.target)
     # Ensure the path exists
     if self.target.exists():
         # XXX: fix this to do actual updates
         return
     ignorer = utils.ignore_matcher(self.config.ignores)
     for entity, _ in utils.walk(self.interface.directory,
                                 lambda x: True,
                                 matcher=ignorer,
                                 kind="files"):
         target = entity.relpath(self.interface.directory)
         target = (self.target / target).normpath()
         target.parent.makedirs_p()
         entity.copy2(target)
     init = self.target / "__init__.py"
     if not init.exists():
         # ensure we can import from here directly
         init.touch()
def inspect(charm):
    tw = utils.TermWriter()
    manp = charm / ".composer.manifest"
    comp = charm / "composer.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,
        )
Exemple #7
0
def inspect(charm):
    tw = utils.TermWriter()
    manp = charm / ".composer.manifest"
    comp = charm / "composer.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)