Esempio n. 1
0
    def deploy(self, builder, label, target_base):
        for asm in self.assemblies:
            src = os.path.join(asm.get_source_dir(builder), asm.from_rel)
            dst = os.path.join(target_base, asm.to_name)

            if not os.path.exists(src):
                if asm.fail_on_absent_source:
                    raise GiveUp("Deployment %s: source object %s does not"
                                 " exist."%(label.name, src))
                # Else no one cares :-)
            else:
                # If this is a file, just copy it.
                if (not os.path.isdir(src)):
                    if (asm.using_rsync):
                        utils.run_cmd("rsync -avz \"%s\" \"%s\""%(src,dst))
                    else:
                        utils.copy_file(src,dst,object_exactly=asm.copy_exactly)
                elif asm.using_rsync: # Rsync for great speed!
                    try:
                        os.makedirs(dst)
                    except OSError:
                        pass

                    xdst = dst
                    if xdst[-1] != "/":
                        xdst = xdst + "/"

                    utils.run0("rsync -avz \"%s/.\" \"%s\""%(src,xdst))
                elif asm.recursive:
                    utils.recursively_copy(src, dst, object_exactly=asm.copy_exactly)
                else:
                    utils.copy_file(src, dst, object_exactly=asm.copy_exactly)
Esempio n. 2
0
    def deploy(self, builder, label):
        deploy_dir = builder.deploy_path(label)
        # First off, delete the target directory
        utils.recursively_remove(deploy_dir)
        utils.ensure_dir(deploy_dir)

        for role, domain in self.roles:
            if domain:
                print "> %s: Deploying role %s in domain %s .. "%(label.name, role, domain)
            else:
                print "> %s: Deploying role %s .. "%(label.name, role)
            install_dir = builder.role_install_path(role, domain = domain)
            utils.recursively_copy(install_dir, deploy_dir, object_exactly=True)

        # This is somewhat tricky as it potentially requires privilege elevation.
        # Privilege elevation is done by hooking back into ourselves via a
        # build command to a label we registered earlier.
        #
        # Note that you cannot split instruction application - once the first
        # privilege-requiring instruction is executed, all further instructions
        # may require privilege even if they didn't before (e.g. a chmod after
        # chown)

        # First off, do we need to at all?
        need_root_for = set()
        for role, domain in self.roles:
            lbl = depend.Label(utils.LabelType.Package, "*", role, "*", domain=domain)
            install_dir = builder.role_install_path(role, domain = label.domain)
            instr_list = builder.load_instructions(lbl)
            for (lbl, fn, instr_file) in instr_list:
                # Obey this instruction?
                for instr in instr_file:
                    iname = instr.outer_elem_name()
                    if iname in self.app_dict:
                        if self.app_dict[iname].needs_privilege(builder, instr, role, install_dir):
                            need_root_for.add(iname)
                    # Deliberately do not break - we want to check everything for
                    # validity before acquiring privilege.
                    else:
                        raise utils.GiveUp("File deployments don't know about " +
                                            "instruction %s"%iname +
                                            " found in label %s (filename %s)"%(lbl, fn))

        print "Rerunning muddle to apply instructions .. "

        permissions_label = depend.Label(utils.LabelType.Deployment,
                                         label.name, None, # XXX label.role,
                                         utils.LabelTag.InstructionsApplied,
                                         domain = label.domain)

        if need_root_for:
            print "I need root to do %s - sorry! - running sudo .."%(', '.join(sorted(need_root_for)))
            utils.run0("sudo %s buildlabel '%s'"%(builder.muddle_binary,
                                                  permissions_label))
        else:
            utils.run0("%s buildlabel '%s'"%(builder.muddle_binary,
                                             permissions_label))
Esempio n. 3
0
    def deploy(self, builder, label):
        deploy_dir = builder.deploy_path(label)

        utils.recursively_remove(deploy_dir)
        utils.ensure_dir(deploy_dir)

        for role in self.dependent_roles:
            print "> %s: Deploying role %s .."%(label.name, role)
            install_dir = builder.role_install_path(role,
                                                               domain = label.domain)
            # We do want an exact copy here - this is a copy from the install
            #  set to the role deployment and therefore may include symlinks
            #  hardwired to MUDDLE_TARGET_INSTALL. If it were a copy to the install
            #  directory, we'd want an inexact copy.
            # - rrw 2009-11-09
            utils.recursively_copy(install_dir, deploy_dir, object_exactly = True)
Esempio n. 4
0
    def deploy(self, builder, label):
        deploy_dir = builder.deploy_path(label)

        utils.recursively_remove(deploy_dir)
        utils.ensure_dir(deploy_dir)

        for role in self.dependent_roles:
            print "> %s: Deploying role %s .." % (label.name, role)
            install_dir = builder.role_install_path(role, domain=label.domain)
            # We do want an exact copy here - this is a copy from the install
            #  set to the role deployment and therefore may include symlinks
            #  hardwired to MUDDLE_TARGET_INSTALL. If it were a copy to the install
            #  directory, we'd want an inexact copy.
            # - rrw 2009-11-09
            utils.recursively_copy(install_dir,
                                   deploy_dir,
                                   object_exactly=True)
Esempio n. 5
0
    def checkout(self, repo, co_leaf, options, verbose=True):
        """
        Clone a given checkout.

        Will be called in the parent directory of the checkout.

        Expected to create a directory called <co_leaf> therein.
        """
        if repo.revision and repo.revision != 'HEAD':
            raise utils.GiveUp("File does not support the 'revision' argument to"
                               " 'checkout' (revision='%s'"%repo.revision)
        if repo.branch:
            raise utils.GiveUp("File does not support the 'branch' argument to"
                               " 'checkout' (branch='%s'"%repo.branch)
        parsed = urlparse.urlparse(repo.url)
        source_path = parsed.path

        utils.recursively_copy(source_path, co_leaf, preserve=True)
Esempio n. 6
0
    def checkout(self, repo, co_leaf, options, verbose=True):
        """
        Clone a given checkout.

        Will be called in the parent directory of the checkout.

        Expected to create a directory called <co_leaf> therein.
        """
        if repo.revision and repo.revision != 'HEAD':
            raise utils.GiveUp(
                "File does not support the 'revision' argument to"
                " 'checkout' (revision='%s'" % repo.revision)
        if repo.branch:
            raise utils.GiveUp("File does not support the 'branch' argument to"
                               " 'checkout' (branch='%s'" % repo.branch)
        parsed = urlparse.urlparse(repo.url)
        source_path = parsed.path

        utils.recursively_copy(source_path, co_leaf, preserve=True)
Esempio n. 7
0
    def deploy(self, builder, label, target_base):
        for asm in self.assemblies:
            src = os.path.join(asm.get_source_dir(builder), asm.from_rel)
            dst = os.path.join(target_base, asm.to_name)

            if not os.path.exists(src):
                if asm.fail_on_absent_source:
                    raise GiveUp("Deployment %s: source object %s does not"
                                 " exist." % (label.name, src))
                # Else no one cares :-)
            else:
                # If this is a file, just copy it.
                if (not os.path.isdir(src)):
                    if (asm.using_rsync):
                        utils.shell("rsync -avz \"%s\" \"%s\"" % (src, dst))
                    else:
                        utils.copy_file(src,
                                        dst,
                                        object_exactly=asm.copy_exactly)
                elif asm.using_rsync:  # Rsync for great speed!
                    try:
                        os.makedirs(dst)
                    except OSError:
                        pass

                    xdst = dst
                    if xdst[-1] != "/":
                        xdst = xdst + "/"

                    utils.run0("rsync -avz \"%s/.\" \"%s\"" % (src, xdst))
                elif asm.recursive:
                    utils.recursively_copy(src,
                                           dst,
                                           object_exactly=asm.copy_exactly)
                else:
                    utils.copy_file(src, dst, object_exactly=asm.copy_exactly)
Esempio n. 8
0
    def deploy(self, builder, label):
        deploy_dir = builder.deploy_path(label)
        # First off, delete the target directory
        utils.recursively_remove(deploy_dir)
        utils.ensure_dir(deploy_dir)

        for role, domain in self.roles:
            if domain:
                print "> %s: Deploying role %s in domain %s .. " % (
                    label.name, role, domain)
            else:
                print "> %s: Deploying role %s .. " % (label.name, role)
            install_dir = builder.role_install_path(role, domain=domain)
            utils.recursively_copy(install_dir,
                                   deploy_dir,
                                   object_exactly=True)

        # This is somewhat tricky as it potentially requires privilege elevation.
        # Privilege elevation is done by hooking back into ourselves via a
        # build command to a label we registered earlier.
        #
        # Note that you cannot split instruction application - once the first
        # privilege-requiring instruction is executed, all further instructions
        # may require privilege even if they didn't before (e.g. a chmod after
        # chown)

        # First off, do we need to at all?
        need_root_for = set()
        for role, domain in self.roles:
            lbl = depend.Label(utils.LabelType.Package,
                               "*",
                               role,
                               "*",
                               domain=domain)
            install_dir = builder.role_install_path(role, domain=label.domain)
            instr_list = builder.load_instructions(lbl)
            for (lbl, fn, instr_file) in instr_list:
                # Obey this instruction?
                for instr in instr_file:
                    iname = instr.outer_elem_name()
                    if iname in self.app_dict:
                        if self.app_dict[iname].needs_privilege(
                                builder, instr, role, install_dir):
                            need_root_for.add(iname)
                    # Deliberately do not break - we want to check everything for
                    # validity before acquiring privilege.
                    else:
                        raise utils.GiveUp(
                            "File deployments don't know about " +
                            "instruction %s" % iname +
                            " found in label %s (filename %s)" % (lbl, fn))

        print "Rerunning muddle to apply instructions .. "

        permissions_label = depend.Label(
            utils.LabelType.Deployment,
            label.name,
            None,  # XXX label.role,
            utils.LabelTag.InstructionsApplied,
            domain=label.domain)

        if need_root_for:
            print "I need root to do %s - sorry! - running sudo .." % (
                ', '.join(sorted(need_root_for)))
            utils.run0("sudo %s buildlabel '%s'" %
                       (builder.muddle_binary, permissions_label))
        else:
            utils.run0("%s buildlabel '%s'" %
                       (builder.muddle_binary, permissions_label))