示例#1
0
文件: sandbox.py 项目: jrha/aquilon
def get_sandbox(session, logger, sandbox, query_options=None):
    """Allow an optional author field."""
    sbx_split = sandbox.split('/')
    first, second = '', ''
    if len(sbx_split) <= 1:
        dbsandbox = Sandbox.get_unique(session, sandbox, compel=True,
                                       query_options=query_options)
        dbauthor = None
        return (dbsandbox, dbauthor)
    first = '/'.join(sbx_split[:-1])
    second = sbx_split[-1]
    dbsandbox = Sandbox.get_unique(session, second, compel=True,
                                   query_options=query_options)
    dbauthor = get_user_principal(session, first)
    return (dbsandbox, dbauthor)
示例#2
0
    def render(self, session, logger, dbuser, sandbox, **arguments):
        sandbox = self.force_my_sandbox(session, logger, dbuser, sandbox)
        dbsandbox = Sandbox.get_unique(session, sandbox, compel=True)

        if not dbuser:
            raise AuthorizationException("Cannot get a sandbox without"
                                         " an authenticated connection.")

        userdir = os.path.join(self.config.get("broker", "templatesdir"),
                               dbuser.name)
        sandboxdir = os.path.join(userdir, dbsandbox.name)
        if os.path.exists(sandboxdir):
            raise ArgumentError("Directory '%s' already exists.  Use git "
                                "fetch within the directory to update it." %
                                sandboxdir)

        if not os.path.exists(userdir):
            try:
                logger.client_info("creating %s" % userdir)
                os.makedirs(userdir, mode=0775)
            except OSError, e:
                raise ArgumentError("failed to mkdir %s: %s" % (userdir, e))

            args = [self.config.get("broker", "mean")]
            args.append("chown")
            args.append("-owner")
            args.append("%s" % dbuser.name)
            args.append("-path")
            args.append("%s" % userdir)
            try:
                run_command(args, logger=logger)
            except ProcessException, e:
                remove_dir(userdir)
                raise e
示例#3
0
文件: get.py 项目: piojo/aquilon
    def render(self, session, logger, dbuser, sandbox, **arguments):
        sandbox = self.force_my_sandbox(session, logger, dbuser, sandbox)
        dbsandbox = Sandbox.get_unique(session, sandbox, compel=True)

        if not dbuser:
            raise AuthorizationException("Cannot get a sandbox without"
                                         " an authenticated connection.")

        userdir = os.path.join(self.config.get("broker", "templatesdir"),
                               dbuser.name)
        sandboxdir = os.path.join(userdir, dbsandbox.name)
        if os.path.exists(sandboxdir):
            raise ArgumentError("Directory '%s' already exists.  Use git "
                                "fetch within the directory to update it." %
                                sandboxdir)

        if not os.path.exists(userdir):
            try:
                logger.client_info("creating %s" % userdir)
                os.makedirs(userdir, mode=0775)
            except OSError, e:
                raise ArgumentError("failed to mkdir %s: %s" % (userdir, e))

            args = [self.config.get("broker", "mean")]
            args.append("chown")
            args.append("-owner")
            args.append("%s" % dbuser.name)
            args.append("-path")
            args.append("%s" % userdir)
            try:
                run_command(args, logger=logger)
            except ProcessException, e:
                remove_dir(userdir)
                raise e
示例#4
0
文件: publish.py 项目: ned21/aquilon
    def render(self, session, logger, branch, sandbox, bundle, sync, rebase,
               **arguments):
        # Most of the logic here is duplicated in deploy
        if branch:
            sandbox = branch
        dbsandbox = Sandbox.get_unique(session, sandbox, compel=True)

        (handle, filename) = mkstemp()
        contents = b64decode(bundle)
        write_file(filename, contents, logger=logger)

        if sync and not dbsandbox.is_sync_valid and dbsandbox.trackers:
            # FIXME: Maybe raise an ArgumentError and request that the
            # command run with --nosync?  Maybe provide a --validate flag?
            # For now, we just auto-flip anyway (below) making the point moot.
            pass
        if not dbsandbox.is_sync_valid:
            dbsandbox.is_sync_valid = True

        if rebase and dbsandbox.trackers:
            raise ArgumentError(
                "{0} has trackers, rebasing is not allowed.".format(dbsandbox))

        kingdir = self.config.get("broker", "kingdir")
        rundir = self.config.get("broker", "rundir")

        tempdir = mkdtemp(prefix="publish_",
                          suffix="_%s" % dbsandbox.name,
                          dir=rundir)
        try:
            run_git([
                "clone", "--shared", "--branch", dbsandbox.name, kingdir,
                dbsandbox.name
            ],
                    path=tempdir,
                    logger=logger)
            temprepo = os.path.join(tempdir, dbsandbox.name)
            run_git(["bundle", "verify", filename],
                    path=temprepo,
                    logger=logger)
            ref = "HEAD:%s" % (dbsandbox.name)
            command = ["pull", filename, ref]
            if rebase:
                command.append("--force")
            run_git(command,
                    path=temprepo,
                    logger=logger,
                    loglevel=CLIENT_INFO)
            # FIXME: Run tests before pushing back to template-king
            if rebase:
                target_ref = "+" + dbsandbox.name
            else:
                target_ref = dbsandbox.name
            run_git(["push", "origin", target_ref],
                    path=temprepo,
                    logger=logger)
        except ProcessException, e:
            raise ArgumentError("\n%s%s" % (e.out, e.err))
示例#5
0
文件: publish.py 项目: piojo/aquilon
    def render(self, session, logger, branch, sandbox, bundle, sync, rebase,
               **arguments):
        # Most of the logic here is duplicated in deploy
        if branch:
            sandbox = branch
        dbsandbox = Sandbox.get_unique(session, sandbox, compel=True)

        (handle, filename) = mkstemp()
        contents = b64decode(bundle)
        write_file(filename, contents, logger=logger)

        if sync and not dbsandbox.is_sync_valid and dbsandbox.trackers:
            # FIXME: Maybe raise an ArgumentError and request that the
            # command run with --nosync?  Maybe provide a --validate flag?
            # For now, we just auto-flip anyway (below) making the point moot.
            pass
        if not dbsandbox.is_sync_valid:
            dbsandbox.is_sync_valid = True

        if rebase and dbsandbox.trackers:
            raise ArgumentError("{0} has trackers, rebasing is not allowed."
                                .format(dbsandbox))

        kingdir = self.config.get("broker", "kingdir")
        rundir = self.config.get("broker", "rundir")

        tempdir = mkdtemp(prefix="publish_", suffix="_%s" % dbsandbox.name,
                          dir=rundir)
        try:
            run_git(["clone", "--shared", "--branch", dbsandbox.name,
                     kingdir, dbsandbox.name],
                    path=tempdir, logger=logger)
            temprepo = os.path.join(tempdir, dbsandbox.name)
            run_git(["bundle", "verify", filename],
                    path=temprepo, logger=logger)
            ref = "HEAD:%s" % (dbsandbox.name)
            command = ["pull", filename, ref]
            if rebase:
                command.append("--force")
            run_git(command, path=temprepo, logger=logger, loglevel=CLIENT_INFO)
            # FIXME: Run tests before pushing back to template-king
            if rebase:
                target_ref = "+" + dbsandbox.name
            else:
                target_ref = dbsandbox.name
            run_git(["push", "origin", target_ref],
                    path=temprepo, logger=logger)
        except ProcessException, e:
            raise ArgumentError("\n%s%s" % (e.out, e.err))
示例#6
0
    def render(self, session, dbuser, sandbox, comments, compiler_version,
               autosync, **arguments):
        dbsandbox = Sandbox.get_unique(session, sandbox, compel=True)

        # FIXME: proper authorization
        if dbsandbox.owner != dbuser and dbuser.role.name != 'aqd_admin':
            raise AuthorizationException("Only the owner or an AQD admin can "
                                         "update a sandbox.")

        if comments:
            dbsandbox.comments = comments
        if compiler_version:
            dbsandbox.compiler = expand_compiler(self.config, compiler_version)
        if autosync is not None:
            dbsandbox.autosync = autosync

        session.flush()
        return
示例#7
0
    def render(self, session, dbuser, sandbox, comments, compiler_version,
               autosync, **arguments):
        dbsandbox = Sandbox.get_unique(session, sandbox, compel=True)

        # FIXME: proper authorization
        if dbsandbox.owner != dbuser and dbuser.role.name != 'aqd_admin':
            raise AuthorizationException("Only the owner or an AQD admin can "
                                         "update a sandbox.")

        if comments:
            dbsandbox.comments = comments
        if compiler_version:
            dbsandbox.compiler = expand_compiler(self.config, compiler_version)
        if autosync is not None:
            dbsandbox.autosync = autosync

        session.flush()
        return
示例#8
0
文件: branch.py 项目: piojo/aquilon
def get_branch_and_author(session, logger,
                          domain=None, sandbox=None, branch=None,
                          compel=False):
    dbbranch = None
    dbauthor = None
    if domain:
        dbbranch = Domain.get_unique(session, domain, compel=True)
    elif branch:
        dbbranch = Branch.get_unique(session, branch, compel=True)
    elif sandbox:
        (author, slash, name) = sandbox.partition('/')
        if not slash:
            raise ArgumentError("Expected sandbox as 'author/branch', author "
                                "name and branch name separated by a slash.")
        dbbranch = Sandbox.get_unique(session, name, compel=True)
        dbauthor = get_user_principal(session, author)
    elif compel:
        raise ArgumentError("Please specify either sandbox or domain.")
    return (dbbranch, dbauthor)
示例#9
0
文件: branch.py 项目: ned21/aquilon
def get_branch_and_author(session,
                          logger,
                          domain=None,
                          sandbox=None,
                          branch=None,
                          compel=False):
    dbbranch = None
    dbauthor = None
    if domain:
        dbbranch = Domain.get_unique(session, domain, compel=True)
    elif branch:
        dbbranch = Branch.get_unique(session, branch, compel=True)
    elif sandbox:
        (author, slash, name) = sandbox.partition('/')
        if not slash:
            raise ArgumentError("Expected sandbox as 'author/branch', author "
                                "name and branch name separated by a slash.")
        dbbranch = Sandbox.get_unique(session, name, compel=True)
        dbauthor = get_user_principal(session, author)
    elif compel:
        raise ArgumentError("Please specify either sandbox or domain.")
    return (dbbranch, dbauthor)