示例#1
0
def run_domain_compile(options, config):
    panc_env = os.environ.copy()

    if config.has_option("broker", "ant_home"):
        ant_home = config.get("broker", "ant_home")
        panc_env["PATH"] = "%s/bin:%s" % (ant_home, panc_env.get("PATH", ""))
        # The ant wrapper is silly and it may pick up the wrong set of .jars if
        # ANT_HOME is not set
        panc_env["ANT_HOME"] = ant_home

    if config.has_option("broker", "java_home"):
        java_home = config.get("broker", "java_home")
        panc_env["PATH"] = "%s/bin:%s" % (java_home, panc_env.get("PATH", ""))
        panc_env["JAVA_HOME"] = java_home

    if config.has_option("broker", "ant_options"):
        panc_env["ANT_OPTS"] = config.get("broker", "ant_options")

    args = ["ant", "--noconfig", "-f"]
    args.append(lookup_file_path("build.xml"))
    args.append("-Dbasedir=%s" % options.basedir)

    if options.swrep:
        args.append("-Dswrep=%s" % options.swrep)

    if options.panc_jar:
        panc = options.panc_jar
    else:
        panc = config.get("panc", "pan_compiler")
    args.append("-Dpanc.jar=%s" % panc)

    if options.compress_output:
        compress_suffix = ".gz"
    else:
        compress_suffix = ""

    formats = []
    suffixes = []
    if config.getboolean("panc", "xml_profiles"):
        formats.append("pan" + compress_suffix)
        suffixes.append(".xml" + compress_suffix)
    if config.getboolean("panc", "json_profiles"):
        formats.append("json" + compress_suffix)
        suffixes.append(".json" + compress_suffix)

    args.append("-Dpanc.formats=%s" % ",".join(formats))
    args.append("-Dprofile.suffixes=%s" % ",".join(suffixes))
    args.append("-Dpanc.template_extension=%s" %
                config.get("panc", "template_extension"))
    args.append("-Ddomain.templates=%s" % options.templates)
    args.append("-Ddomain=%s" % options.domain)

    if options.batch_size:
        args.append("-Dpanc.batch.size=%d" % options.batch_size)
    else:
        args.append("-Dpanc.batch.size=%s" % config.get("panc", "batch_size"))

    print "Running %s" % " ".join(args)
    return call(args, env=panc_env, cwd=options.basedir)
示例#2
0
def main():
    parser = argparse.ArgumentParser(description="Compile templates")
    parser.add_argument("-c", "--config", dest="config", action="store",
                        help="location of the config file",
                        default=lookup_file_path("aqd.conf.defaults"))
    parser.add_argument("--basedir", action="store", required=True,
                        help="base directory")
    parser.add_argument("--domain", action="store", required=True,
                        help="domain name to compile")
    parser.add_argument("--compress_output", action="store_true",
                        help="compress the generated profiles")
    parser.add_argument("--panc_jar", action="store",
                        help="location of panc.jar")
    parser.add_argument("--templates", action="store", required=True,
                        help="location of the domain templates")
    parser.add_argument("--swrep", action="store",
                        help="location of the swrep templates")
    parser.add_argument("--batch_size", action="store", type=int,
                        help="compiler batch size")

    options = parser.parse_args()
    config = Config(configfile=options.config)

    return run_domain_compile(options, config)
示例#3
0
import aquilon.aqdb.depends

import argparse
parser = argparse.ArgumentParser(description='generate schema graphs')
parser.add_argument('--outputdir', '-o', dest='dir', default='.',
                    help='directory to put generated files')
parser.add_argument('--prefix', '-p', dest='prefix', default='aqdb_schema',
                    help='basename of files to generate')
opts = parser.parse_args()

if not os.path.exists(opts.dir):
    os.makedirs(opts.dir)

from aquilon.config import Config, lookup_file_path
config = Config(configfile=lookup_file_path('aqd.conf.mem'))

from aquilon.aqdb.db_factory import DbFactory
from aquilon.aqdb.model import Base
db = DbFactory()
Base.metadata.bind = db.engine
Base.metadata.create_all()

import ms.modulecmd
ms.modulecmd.load("fsf/graphviz/2.28.0")

from aquilon.aqdb.utils import schema2dot


dot = schema2dot.create_schema_graph(metadata=db.meta)
dot.write(os.path.join(opts.dir, "%s.dot" % opts.prefix))
示例#4
0
文件: aq.py 项目: piojo/aquilon
    def create_bundle(self, commandOptions):
        from subprocess import Popen, PIPE
        from tempfile import mkstemp
        from base64 import b64encode

        p = Popen(("git", "fetch"), stderr=2)
        p.wait()  # wait for return, but it's okay if this fails
        p = Popen(("git", "status", "--porcelain"), stdout=PIPE, stderr=2)
        (out, err) = p.communicate()
        if p.returncode:
            print >> sys.stderr, "\nError running git status --porcelain, returncode %d" % p.returncode
            sys.exit(1)
        if out:
            print >> sys.stderr, "Not ready to publish, found:\n%s" % out
            sys.exit(1)

        # Locate the top of the sandbox for the purposes of executing the
        # unit tests in the t directory
        p = Popen(("git", "rev-parse", "--show-toplevel"), stdout=PIPE)
        (sandbox_dir, err) = p.communicate()
        sandbox_dir = sandbox_dir.strip()
        if p.returncode != 0:
            print >> sys.stderr, "Failed to find toplevel of sandbox, aborting"
            sys.exit(1)
        # Prevent the branch being published unless the unit tests pass
        testdir = os.path.join(sandbox_dir, "t")
        if os.path.exists(os.path.join(testdir, "Makefile")):
            p = Popen(
                [
                    "/usr/bin/make",
                    "-C",
                    testdir,
                    "test",
                    "AQCMD=%s" % os.path.realpath(sys.argv[0]),
                    "AQBUILDXML=%s" % lookup_file_path("build.xml"),
                ],
                cwd=testdir,
                env=self.env,
            )
            p.wait()
            if p.returncode != 0:
                print >> sys.stderr, "\nUnit tests failed, publish prohibited.",
                print >> sys.stderr, '(Do you need to run a "make clean test"?)'
                sys.exit(1)

        if "sandbox" in commandOptions:
            branch = commandOptions["sandbox"]
        else:
            branch = commandOptions["branch"]
        revlist = "origin/%s..HEAD" % branch
        p = Popen(("git", "log", revlist), stdout=PIPE, stderr=2)
        (out, err) = p.communicate()

        if out:
            print >> sys.stdout, "\nThe following changes will be included in this push:\n"
            print >> sys.stdout, "------------------------"
            print >> sys.stdout, str(out)
            print >> sys.stdout, "------------------------"
        else:
            print >> sys.stdout, "\nYou haven't made any changes on this branch\n"
            sys.exit(0)

        (handle, filename) = mkstemp()
        try:
            rc = Popen(("git", "bundle", "create", filename, revlist), stdout=1, stderr=2).wait()
            if rc:
                print >> sys.stderr, "Error running git bundle create, returncode %d" % rc
                sys.exit(1)

            commandOptions["bundle"] = b64encode(file(filename).read())
        finally:
            os.unlink(filename)
示例#5
0
文件: aq.py 项目: piojo/aquilon
def quoteOptions(options):
    return "&".join([urllib.quote(k) + "=" + urllib.quote(v) for k, v in options.iteritems()])


if __name__ == "__main__":
    # Set up the search path for man pages. "man" does not like ".." in the
    # path, so we have to normalize it
    BINDIR = os.path.dirname(os.path.realpath(sys.argv[0]))
    MANDIR = os.path.realpath(os.path.join(BINDIR, "..", "doc", "man"))
    if os.path.exists(MANDIR):
        if "MANPATH" in os.environ:
            os.environ["MANPATH"] = MANDIR + ":" + os.environ["MANPATH"]
        else:
            os.environ["MANPATH"] = MANDIR

    parser = OptParser(lookup_file_path("input.xml"))
    try:
        (command, transport, commandOptions, globalOptions) = parser.parse(sys.argv[1:])
    except ParsingError, e:
        print >> sys.stderr, "%s: %s" % (sys.argv[0], e.error)
        print >> sys.stderr, "%s: Try --help for usage details." % (sys.argv[0])
        sys.exit(1)

    # Setting this as a global default.  It might make sense to set
    # the default to the current running user when running out of a
    # shadow, though.
    default_aqservice = "cdb"

    # Default for /ms/dist
    if re.match(r"/ms(/.(global|local)/[^/]+)?/dist/", BINDIR):
        default_aqhost = "nyaqd1"
示例#6
0
    def __init__(self, config):
        formatter = ResponseFormatter()
        ResponsePage.__init__(self, '', formatter)
        self.config = config

        tree = ET.parse(lookup_file_path("input.xml"))

        for command in tree.getiterator("command"):
            for transport in command.getiterator("transport"):
                if "name" not in command.attrib \
                        or "method" not in transport.attrib \
                        or "path" not in transport.attrib:
                    continue
                name = command.attrib["name"]
                method = transport.attrib["method"]
                path = transport.attrib["path"]
                trigger = transport.attrib.get("trigger")

                fullcommand = name
                if trigger:
                    fullcommand = fullcommand + "_" + trigger
                mymodule = getattr(commands, fullcommand, None)
                if not mymodule:
                    log.msg("No module available in aquilon.worker.commands " +
                            "for %s" % fullcommand)
                # See commands/__init__.py for more info here...
                myinstance = getattr(mymodule, "broker_command", None)
                if not myinstance:
                    log.msg("No class instance available for %s" % fullcommand)
                    myinstance = BrokerCommand()
                myinstance.command = name
                rendermethod = method.upper()

                self.insert_instance(myinstance, rendermethod, path, formatter)

                # Since we are parsing input.xml anyway, record the possible
                # parameters...
                for option in command.getiterator("option"):
                    if "name" not in option.attrib:
                        continue
                    option_name = option.attrib["name"]
                    if option_name not in myinstance.optional_parameters:
                        myinstance.optional_parameters.append(option_name)
                    if "type" in option.attrib:
                        paramtype = option.attrib["type"]
                        if paramtype == "int":
                            myinstance.parameter_checks[option_name] = force_int
                        elif paramtype == "float":
                            myinstance.parameter_checks[option_name] = force_float
                        elif paramtype == "boolean" or paramtype == "flag":
                            myinstance.parameter_checks[option_name] = force_boolean
                        elif paramtype == "ipv4":
                            myinstance.parameter_checks[option_name] = force_ipv4
                        elif paramtype == "mac":
                            myinstance.parameter_checks[option_name] = force_mac
                        elif paramtype == "json":
                            myinstance.parameter_checks[option_name] = force_json_dict
                        elif paramtype == "string" or paramtype == "file":
                            # Current twisted can't handle unicode output, so
                            # do not allow non-ASCII input either
                            myinstance.parameter_checks[option_name] = force_ascii
                        elif paramtype == "list":
                            myinstance.parameter_checks[option_name] = force_list
                        elif paramtype == "enum":
                            enumtype = option.attrib["enum"]
                            try:
                                enumclass = StringEnum(enumtype)
                                myinstance.parameter_checks[option_name] = enumclass.from_argument
                            except ValueError, e:
                                log.msg("Unknown Enum: %s" % e)
                        else:  # pragma: no cover
                            log.msg("Warning: unknown option type %s" % paramtype)
                    else:  # pragma: no cover
                        log.msg("Warning: argument type not known for %s.%s" %
                                (myinstance.command, option_name))

                    for format in command.getiterator("format"):
                        if "name" not in format.attrib:
                            log.msg("Warning: incorrect format specification "
                                    "for %s." % myinstance.command)
                            continue

                        style = format.attrib["name"]
                        if hasattr(myinstance.formatter, "config_" + style):
                            meth = getattr(myinstance.formatter, "config_" +
                                           style)
                            meth(format, myinstance.command)