def main(args = None): opts = docopt.docopt( doc = __doc__, argv = args) try: if opts["--no-color"]: fckit.disable_colors() if opts["--verbose"]: fckit.enable_tracing() if opts["--directory"]: fckit.chdir(opts["--directory"]) role = Role() targets = Targets( role = role, exclude = opts["--exclude"].split(","), warning_flags = opts["--warnings"].split(","), repository_url = opts["--repository"]) for key in opts["TARGETS"]: fckit.trace("at %s" % key) targets[key].build() if os.path.exists(targets["check"].path): with open(targets["check"].path, "r") as fp: print fckit.magenta(fp.read()) except fckit.Error as exc: raise SystemExit(fckit.red(exc))
def setup(toolid, settings, manifests): "render a tool configuration template" tools = {k: v for m in manifests for k, v in m.get("tools", {}).items()} if toolid == "help": name_width = max(map(len, tools)) path_width = max(map(lambda key: len(tools[key]["path"]), tools)) for key in tools: required = ", ".join(tools[key]["required_vars"]) optional = ", ".join("%s=%s" % (k, v) for k,v in tools[key]["defaults"].items()) print\ fckit.magenta(key.rjust(name_width)),\ tools[key]["path"].center(path_width),\ required,\ ("[%s]" % optional) if optional else "" else: suffix = ", call 'setup help' for details" if not toolid in tools: raise Error(toolid, "unknown tool", suffix) path = os.path.expanduser(tools[toolid]["path"]) if settings: settings = dict(tools[toolid]["defaults"], **(dict(map(lambda item: item.split("="), settings)))) else: settings = {} if not os.path.exists(path) or settings.get("overwrite", "no") == "yes": try: text = textwrap.dedent(tools[toolid]["template"]).lstrip() % settings except KeyError as exc: raise Error(" ".join(exc.args), "missing required variable" + suffix) with open(path, "w") as fp: fp.write(text) fckit.trace("%s: template instantiated" % path) else: raise Error(path, "file already exists, set overwrite=yes to force")
def main(args=None): opts = docopt.docopt(doc=__doc__, argv=args) try: if opts["--no-color"]: fckit.disable_colors() if opts["--verbose"]: fckit.enable_tracing() if opts["--directory"]: fckit.chdir(opts["--directory"]) role = Role() targets = Targets(role=role, exclude=opts["--exclude"].split(","), warning_flags=opts["--warnings"].split(","), repository_url=opts["--repository"]) for key in opts["TARGETS"]: fckit.trace("at %s" % key) targets[key].build() if os.path.exists(targets["check"].path): with open(targets["check"].path, "r") as fp: print fckit.magenta(fp.read()) except fckit.Error as exc: raise SystemExit(fckit.red(exc))
def print_warning(*strings): sys.stderr.write(fckit.magenta("WARNING! %s\n") % ": ".join(strings).encode("utf-8"))