Exemplo n.º 1
0
 def report(self):
     output.error(self.cmd)
     output.tabular("Return code", str(self.returncode), red=True)
     output.line('STDOUT', red=True)
     output.annotate(self.stdout)
     output.line('STDERR', red=True)
     output.annotate(self.stderr)
Exemplo n.º 2
0
 def call(*args, **kw):
     output.annotate("rpc {}: {}(*{}, **{})".format(
         self.host.fqdn, name, args, kw),
                     debug=True)
     self.host.channel.send((name, args, kw))
     while True:
         message = self.host.channel.receive()
         output.annotate("{}: message: {}".format(
             self.host.fqdn, message),
                         debug=True)
         type = message[0]
         if type == "batou-result":
             return message[1]
         elif type == "batou-output":
             _, output_cmd, args, kw = message
             getattr(output, output_cmd)(*args, **kw)
         elif type == "batou-configuration-error":
             raise SilentConfigurationError()
         elif type == "batou-deployment-error":
             raise DeploymentError()
         elif type == "batou-unknown-error":
             output.error(message[1])
             raise RuntimeError(
                 "{}: Remote exception encountered.".format(
                     self.host.fqdn))
         elif type == "batou-error":
             # Remote put out the details already.
             raise RuntimeError(
                 "{}: Remote exception encountered.".format(
                     self.host.fqdn))
         else:
             raise RuntimeError("{}: Unknown message type {}".format(
                 self.host.fqdn, type))
Exemplo n.º 3
0
 def expand(self, templatestr, args, identifier="<template>"):
     if len(templatestr) > 100 * 1024:
         output.error(
             "You are trying to render a template that is bigger than "
             "100KiB we've seen that Jinja can crash at large templates "
             "and suggest you find alternatives for this. The affected "
             "template starts with:")
         output.annotate(templatestr[:100])
     tmpl = self.env.from_string(templatestr)
     tmpl.filename = identifier
     return tmpl.render(**args)
Exemplo n.º 4
0
    def verify(self):
        # Safety belt that we're acting on a clean repository.
        if self.environment.deployment.dirty:
            output.annotate(
                "You are running a dirty deployment. This can cause "
                "inconsistencies -- continuing on your own risk!", red=True)
            return

        try:
            status, _ = cmd('hg -q stat')
        except CmdExecutionError:
            output.error('Unable to check repository status. '
                         'Is there an HG repository here?')
            raise
        else:
            status = status.strip()
            if status.strip():
                output.error("Your repository has uncommitted changes.")
                output.annotate("""\
I am refusing to deploy in this situation as the results will be unpredictable.
Please commit and push first.
""", red=True)
                output.annotate(status, red=True)
                raise DeploymentError()
        try:
            cmd('hg -q outgoing -l 1', acceptable_returncodes=[1])
        except CmdExecutionError:
            output.error("""\
Your repository has outgoing changes.

I am refusing to deploy in this situation as the results will be unpredictable.
Please push first.
""")
            raise DeploymentError()
Exemplo n.º 5
0
    def verify(self):
        # Safety belt that we're acting on a clean repository.
        if self.environment.deployment.dirty:
            output.annotate(
                "You are running a dirty deployment. This can cause "
                "inconsistencies -- continuing on your own risk!",
                red=True,
            )
            return

        try:
            status, _ = cmd("git status --porcelain")
        except CmdExecutionError:
            output.error("Unable to check repository status. "
                         "Is there a Git repository here?")
            raise
        else:
            status = status.strip()
            if status.strip():
                output.error("Your repository has uncommitted changes.")
                output.annotate(
                    """\
I am refusing to deploy in this situation as the results will be unpredictable.
Please commit and push first.
""",
                    red=True,
                )
                output.annotate(status, red=True)
                raise DeploymentError()
        outgoing, _ = cmd(
            "git log {remote}/{branch}..{branch} --pretty=oneline".format(
                remote=self.remote, branch=self.branch),
            acceptable_returncodes=[0, 128],
        )
        if outgoing.strip():
            output.error("""\
Your repository has outgoing changes.

I am refusing to deploy in this situation as the results will be unpredictable.
Please push first.
""")
            raise DeploymentError()
Exemplo n.º 6
0
    def verify(self):
        # Safety belt that we're acting on a clean repository.
        if self.environment.deployment.dirty:
            output.annotate(
                "You are running a dirty deployment. This can cause "
                "inconsistencies -- continuing on your own risk!",
                red=True)
            return

        try:
            status = hg_cmd("hg stat")
        except CmdExecutionError:
            output.error("Unable to check repository status. "
                         "Is there an HG repository here?")
            raise
        else:
            if status:
                output.error("Your repository has uncommitted changes.")
                output.annotate(
                    """\
I am refusing to deploy in this situation as the results will be unpredictable.
Please commit and push first.
""",
                    red=True)
                for item in status:
                    output.annotate(
                        "{} {}".format(item['status'], item['path']), red=True)
                raise DeploymentError("Uncommitted changes")
        try:
            cmd("hg -q outgoing -l 1", acceptable_returncodes=[1])
        except CmdExecutionError:
            output.error("""\
Your repository has outgoing changes.

I am refusing to deploy in this situation as the results will be unpredictable.
Please push first.
""")
            raise DeploymentError("Outgoing changes")