예제 #1
0
def deploy(params, topdir=None, cache_only=None):
    if cache_only:
        return (0, "no-ops for caching", {})

    action_type = 'configfiles.deploy'
    if not _local_permission_check(action_type):
        log_to_file(0, "permissions error: " + str(action_type))
        return _perm_error(action_type)

    _init()
    files = params.get('files') or []
    dep_trans = DeployTransaction(transaction_root=topdir, auto_rollback=0)

    for file in files:
        dep_trans.add(file)

    try:
        dep_trans.deploy()
    #5/3/05 wregglej - 135415 Adding stuff for missing user info
    except cfg_exceptions.UserNotFound, e:
            try:
                dep_trans.rollback()
            except FailedRollback:
                log_to_file(0, "Failed deployment and rollback, information on user '%s' could not be found" % (e[0], ))
                return (44, "Failed deployment and rollback, information on user '%s' could not be found" % (e[0], ), {})
            #5/3/05 wregglej - 136415 Adding some more exceptions to handle
            except cfg_exceptions.UserNotFound, f:
                log_to_file(0, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0], ))
                return (50, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0], ), {})
예제 #2
0
def deploy(params, topdir=None, cache_only=None):
    if cache_only:
        return (0, "no-ops for caching", {})

    action_type = 'configfiles.deploy'
    if not _local_permission_check(action_type):
        log_to_file(0, "permissions error: " + str(action_type))
        return _perm_error(action_type)

    _init()
    files = params.get('files') or []
    dep_trans = DeployTransaction(transaction_root=topdir, auto_rollback=0)

    for file in files:
        dep_trans.add(file)

    try:
        dep_trans.deploy()
    #5/3/05 wregglej - 135415 Adding stuff for missing user info
    except cfg_exceptions.UserNotFound, e:
            try:
                dep_trans.rollback()
            except FailedRollback:
                log_to_file(0, "Failed deployment and rollback, information on user '%s' could not be found" % (e[0], ))
                return (44, "Failed deployment and rollback, information on user '%s' could not be found" % (e[0], ), {})
            #5/3/05 wregglej - 136415 Adding some more exceptions to handle
            except cfg_exceptions.UserNotFound, f:
                log_to_file(0, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0], ))
                return (50, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0], ), {})
예제 #3
0
def deploy_files(topdir, repository, files, excludes = None, config_channel = None):
    topdir = topdir or os.sep
    if not excludes:
        excludes = []
    dep_trans = DeployTransaction(transaction_root=topdir)
    dep_trans.deploy_callback(deploy_msg_callback)

    for path in files:
        if path in excludes:
            print("Excluding %s" % path)
        else:
            try:
                if config_channel:
                    args = (config_channel, path)
                else:
                    args = (path, )
                kwargs = {'auto_delete': 0, 'dest_directory': topdir}
                finfo = repository.get_file_info(*args, **kwargs)
            except cfg_exceptions.DirectoryEntryIsFile:
                e = sys.exc_info()[1]
                print("Error: unable to deploy directory %s, as it is already a file on disk" % e[0])
                continue

            if finfo is None:
                # File disappeared since we called the function
                continue

            (processed_path, file_info, dirs_created) = finfo
            try:
                dep_trans.add_preprocessed(path, processed_path, file_info, dirs_created)
            except cfg_exceptions.UserNotFound:
                e = sys.exc_info()[1]
                print("Error: unable to deploy file %s, information on user '%s' could not be found." % (path,e[0]))
                continue
            except cfg_exceptions.GroupNotFound:
                e = sys.exc_info()[1]
                print("Error: unable to deploy file %s, information on group '%s' could not be found." % (path, e[0]))
                continue

    try:
        dep_trans.deploy()
    #5/3/05 wregglej - 136415 added missing user exception stuff.
    except cfg_exceptions.UserNotFound:
        e = sys.exc_info()[1]
        try_rollback(dep_trans, "Error unable to deploy file, information on user '%s' could not be found" % e[0])
    except cfg_exceptions.GroupNotFound:
        e = sys.exc_info()[1]
        try_rollback(dep_trans, "Error: unable to deploy file, information on group '%s' could not be found" % e[0])
    except cfg_exceptions.FileEntryIsDirectory:
        e = sys.exc_info()[1]
        try_rollback(dep_trans, "Error: unable to deploy file %s, as it is already a directory on disk" % e[0])
    except cfg_exceptions.DirectoryEntryIsFile:
        e = sys.exc_info()[1]
        try_rollback(dep_trans, "Error: unable to deploy directory %s, as it is already a file on disk" % e[0])
    except Exception:
        try:
            try_rollback(dep_trans, "Deploy failed, rollback successful")
        except:
            print("Failed rollback")
            raise
예제 #4
0
    def run(self):
        topdir = self.options.topdir or os.sep
        dep_trans = DeployTransaction(transaction_root=topdir)

        dep_trans.deploy_callback(deploying_mesg_callback)

        # Setup the excludes hash
        excludes = {}
        if self.options.exclude is not None:
            for exclude in enumerate(self.options.exclude):
                    excludes[exclude[1]] = None

        for path in self.get_valid_files():

            (directory, filename) = os.path.split(path)
            directory = os.path.normpath("%s%s%s" % (topdir, os.sep, directory))

            try:
                finfo = self.repository.get_file_info(path, auto_delete=0, dest_directory=directory)
            except cfg_exceptions.DirectoryEntryIsFile, e:
                print "Error: unable to deploy directory %s, as it is already a file on disk" % (e[0], )
                continue

            if finfo is None:
                # File disappeared since we called the function
                continue

            (processed_path, file_info, dirs_created) = finfo

            if excludes.has_key(path):
                print "Excluding %s" % path
            else:
                try:
                    dep_trans.add_preprocessed(path, processed_path, file_info, dirs_created)
                except cfg_exceptions.UserNotFound, e:
                    print "Error: unable to deploy file %s, information on user '%s' could not be found." % (path,e[0])
                    continue
                except cfg_exceptions.GroupNotFound, e:
                    print "Error: unable to deploy file %s, information on group '%s' could not be found." % (path, e[0])
                    continue
예제 #5
0
def deploy(params, topdir=None, cache_only=None):
    if cache_only:
        return (0, "no-ops for caching", {})

    action_type = 'configfiles.deploy'
    if not _local_permission_check(action_type):
        log_to_file(0, "permissions error: " + str(action_type))
        return _perm_error(action_type)

    _init()
    files = params.get('files') or []
    dep_trans = DeployTransaction(transaction_root=topdir, auto_rollback=0)

    for file in files:
        dep_trans.add(file)

    try:
        dep_trans.deploy()
    #5/3/05 wregglej - 135415 Adding stuff for missing user info
    except cfg_exceptions.UserNotFound:
            e = sys.exc_info()[1]
            try:
                dep_trans.rollback()
            except FailedRollback:
                log_to_file(0, "Failed deployment and rollback, information on user '%s' could not be found" % (e[0], ))
                return (44, "Failed deployment and rollback, information on user '%s' could not be found" % (e[0], ), {})
            #5/3/05 wregglej - 136415 Adding some more exceptions to handle
            except cfg_exceptions.UserNotFound:
                f = sys.exc_info()[1]
                log_to_file(0, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0], ))
                return (50, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0], ), {})
            #5/5/05 wregglej - 136415 Adding exception handling for unknown group,
            except cfg_exceptions.GroupNotFound:
                f = sys.exc_info()[1]
                log_to_file(0, "Failed deployment and rollback, group '%s' could not be found" % (f[0],))
                return (51, "Failed deployment and rollback, group '%s' could not be found" % (f[0],), {})
            else:
                log_to_file(0, "Failed deployment and rollback, information on user '%s' could not be found" % (e[0], ))
                return (50, "Failed deployment and rollback, information on user '%s' could not be found" % (e[0], ), {})
    except cfg_exceptions.GroupNotFound:
            e = sys.exc_info()[1]
            try:
                dep_trans.rollback()
            except FailedRollback:
                log_to_file(0, "Failed deployment and rollback, information on user '%s' could not be found" % (e[0], ))
                return (44, "Failed deployment and rollback, information on user '%s' could not be found" % (e[0], ), {})
            #5/3/05 wregglej - 136415 Adding some more exceptions to handle
            except cfg_exceptions.UserNotFound:
                f = sys.exc_info()[1]
                log_to_file(0, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0], ) )
                return (50, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0], ), {})
            #5/5/05 wregglej - 136415 Adding exception handling for unknown group,
            except cfg_exceptions.GroupNotFound:
                f = sys.exc_info()[1]
                log_to_file(0, "Failed deployment and rollback, group '%s' could not be found" % (f[0],))
                return (51, "Failed deployment and rollback, group '%s' could not be found" % (f[0],), {})
            else:
                log_to_file(0, "Failed deployment and rollback, group '%s' could not be found" % (e[0], ))
                return (51, "Failed deployment and rollback, group '%s' could not be found" % (e[0], ), {})
    except cfg_exceptions.FileEntryIsDirectory:
            e = sys.exc_info()[1]
            try:
                dep_trans.rollback()
            except FailedRollback:
                log_to_file(0, "Failed deployment and rollback, %s already exists as a directory" % (e[0], ))
                return (44, "Failed deployment and rollback, %s already exists as a directory" % (e[0], ), {})
            #5/3/05 wregglej - 136415 Adding some more exceptions to handle
            except cfg_exceptions.UserNotFound:
                f = sys.exc_info()[1]
                log_to_file(0, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0], ))
                return (50, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0], ), {})
            #5/5/05 wregglej - 136415 Adding exception handling for unknown group,
            except cfg_exceptions.GroupNotFound:
                f = sys.exc_info()[1]
                log_to_file(0, "Failed deployment and rollback, group '%s' could not be found" % (f[0],))
                return (51, "Failed deployment and rollback, group '%s' could not be found" % (f[0],), {})
            else:
                log_to_file(0, "Failed deployment, %s already exists as a directory" % (e[0], ))
                return (45, "Failed deployment, %s already exists as a directory" % (e[0], ), {})
    except cfg_exceptions.DirectoryEntryIsFile:
            e = sys.exc_info()[1]
            try:
                dep_trans.rollback()
            except FailedRollback:
                log_to_file(0, "Failed deployment and rollback, %s already exists as a file" % (e[0], ))
                return (46, "Failed deployment and rollback, %s already exists as a file" % (e[0], ), {})
            #5/3/05 wregglej - 136415 Adding exceptions for missing user
            except cfg_exceptions.UserNotFound:
                f = sys.exc_info()[1]
                log_to_file(0, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0], ))
                return (50, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0], ), {})
            #5/5/05 wregglej - 136415 Adding exception handling for unknown group,
            except cfg_exceptions.GroupNotFound:
                f = sys.exc_info()[1]
                log_to_file(0, "Failed deployment and rollback, group '%s' could not be found" % (f[0],))
                return (51, "Failed deployment and rollback, group '%s' could not be found" % (f[0],), {})
            else:
                log_to_file(0, "Failed deployment, %s already exists as a file" % (e[0], ))
                return (47, "Failed deployment, %s already exists as a file" % (e[0], ), {})

    except Exception:
        e = sys.exc_info()[1]
        print(e)
        try:
            dep_trans.rollback()
        except FailedRollback:
            e2 = sys.exc_info()[1]
            log_to_file(0, "Failed deployment, failed rollback:  %s" % e2)
            return (48, "Failed deployment, failed rollback:  %s" % e2, {})
        #5/3/05 wregglej - 135415 Add exception handling for missing user.
        except cfg_exceptions.UserNotFound:
            f = sys.exc_info()[1]
            log_to_file(0, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0]))
            return (50, "Failed deployment and rollback, information on user '%s' could not be found" % (f[0]), {})
        #5/5/05 wregglej - 136415 Adding exception handling for unknown group,
        except cfg_exceptions.GroupNotFound:
            f = sys.exc_info()[1]
            log_to_file(0, "Failed deployment and rollback, group '%s' could not be found" % (f[0],))
            return (51, "Failed deployment and rollback, group '%s' could not be found" % (f[0],), {})
        else:
            log_to_file(0, "Failed deployment, rolled back:  %s" % e)
            return (49, "Failed deployment, rolled back:  %s" % e, {})

    extras = {}
    log_to_file(0, "Files successfully deployed: %s %s" % (format_file_string(files, create_key_list()), str(extras)))
    return 0, "Files successfully deployed", extras
예제 #6
0
    def run(self):
        log_debug(2)
        r = self.repository

        channel = self.options.channel
        if not channel:
            die(6, "Config channel not specified")

        topdir = self.options.topdir
        if topdir:
            if not os.path.isdir(self.options.topdir):
                die(
                    8, "--topdir specified, but `%s' not a directory" %
                    self.options.topdir)

        if not self.args:
            die(7, "No files specified")

        revision = self.options.revision
        if revision:
            if len(self.args) > 1:
                die(9, "--revision specified with multiple files")

        dep_trans = None

        if topdir:
            dep_trans = DeployTransaction(transaction_root=topdir)
            dep_trans.deploy_callback(deploying_mesg_callback)

        for f in self.args:
            try:
                directory = topdir or tempfile.gettempdir()

                #5/11/05 wregglej - 157066 dirs_created is returned from get_file_info.
                (temp_file, info,
                 dirs_created) = r.get_file_info(channel,
                                                 f,
                                                 revision=revision,
                                                 auto_delete=0,
                                                 dest_directory=directory)

            except cfg_exceptions.RepositoryFileMissingError:
                if revision is not None:
                    die(
                        2, "Error: file %s (revision %s) not in config "
                        "channel %s" % (f, revision, channel))
                else:
                    die(
                        2, "Error: file %s not in config channel %s" %
                        (f, channel))

            if topdir:
                #5/11/05 wregglej - 157066 dirs_created now gets passed into add_preprocessed.
                dep_trans.add_preprocessed(f,
                                           temp_file,
                                           info,
                                           dirs_created,
                                           strict_ownership=0)
                continue
            elif info.get('filetype') == 'symlink':
                print("%s -> %s" % (info['path'], info['symlink']))
                continue
            elif info.get('filetype') == 'directory':
                print("%s is a directory entry, nothing to get" % info['path'])
                continue
            else:
                print(open(temp_file).read())
                os.unlink(temp_file)

        if topdir:
            try:
                dep_trans.deploy()
            except Exception:
                try:
                    dep_trans.rollback()
                except FailedRollback:
                    raise_with_tb(FailedRollback("FAILED ROLLBACK:  "),
                                  sys.exc_info()[2])
                #5/3/05 wregglej - 136415 Added exception stuff for missing user info.
                except cfg_exceptions.UserNotFound:
                    raise
                #5/5/05 wregglej - 136415 Added exception handling for unknown group.
                except cfg_exceptions.GroupNotFound:
                    raise
                else:
                    raise_with_tb(
                        Exception("Deploy failed, rollback successful:  "),
                        sys.exc_info()[2])
예제 #7
0
def deploy(params, topdir=None, cache_only=None):
    if cache_only:
        return (0, "no-ops for caching", {})

    action_type = 'configfiles.deploy'
    if not _local_permission_check(action_type):
        log_to_file(0, "permissions error: " + str(action_type))
        return _perm_error(action_type)

    _init()
    files = params.get('files') or []
    dep_trans = DeployTransaction(transaction_root=topdir, auto_rollback=0)

    for file in files:
        dep_trans.add(file)

    try:
        dep_trans.deploy()
    #5/3/05 wregglej - 135415 Adding stuff for missing user info
    except cfg_exceptions.UserNotFound:
        e = sys.exc_info()[1]
        try:
            dep_trans.rollback()
        except FailedRollback:
            log_to_file(
                0,
                "Failed deployment and rollback, information on user '%s' could not be found"
                % (e[0], ))
            return (
                44,
                "Failed deployment and rollback, information on user '%s' could not be found"
                % (e[0], ), {})
        #5/3/05 wregglej - 136415 Adding some more exceptions to handle
        except cfg_exceptions.UserNotFound:
            f = sys.exc_info()[1]
            log_to_file(
                0,
                "Failed deployment and rollback, information on user '%s' could not be found"
                % (f[0], ))
            return (
                50,
                "Failed deployment and rollback, information on user '%s' could not be found"
                % (f[0], ), {})
        #5/5/05 wregglej - 136415 Adding exception handling for unknown group,
        except cfg_exceptions.GroupNotFound:
            f = sys.exc_info()[1]
            log_to_file(
                0,
                "Failed deployment and rollback, group '%s' could not be found"
                % (f[0], ))
            return (
                51,
                "Failed deployment and rollback, group '%s' could not be found"
                % (f[0], ), {})
        else:
            log_to_file(
                0,
                "Failed deployment and rollback, information on user '%s' could not be found"
                % (e[0], ))
            return (
                50,
                "Failed deployment and rollback, information on user '%s' could not be found"
                % (e[0], ), {})
    except cfg_exceptions.GroupNotFound:
        e = sys.exc_info()[1]
        try:
            dep_trans.rollback()
        except FailedRollback:
            log_to_file(
                0,
                "Failed deployment and rollback, information on user '%s' could not be found"
                % (e[0], ))
            return (
                44,
                "Failed deployment and rollback, information on user '%s' could not be found"
                % (e[0], ), {})
        #5/3/05 wregglej - 136415 Adding some more exceptions to handle
        except cfg_exceptions.UserNotFound:
            f = sys.exc_info()[1]
            log_to_file(
                0,
                "Failed deployment and rollback, information on user '%s' could not be found"
                % (f[0], ))
            return (
                50,
                "Failed deployment and rollback, information on user '%s' could not be found"
                % (f[0], ), {})
        #5/5/05 wregglej - 136415 Adding exception handling for unknown group,
        except cfg_exceptions.GroupNotFound:
            f = sys.exc_info()[1]
            log_to_file(
                0,
                "Failed deployment and rollback, group '%s' could not be found"
                % (f[0], ))
            return (
                51,
                "Failed deployment and rollback, group '%s' could not be found"
                % (f[0], ), {})
        else:
            log_to_file(
                0,
                "Failed deployment and rollback, group '%s' could not be found"
                % (e[0], ))
            return (
                51,
                "Failed deployment and rollback, group '%s' could not be found"
                % (e[0], ), {})
    except cfg_exceptions.FileEntryIsDirectory:
        e = sys.exc_info()[1]
        try:
            dep_trans.rollback()
        except FailedRollback:
            log_to_file(
                0,
                "Failed deployment and rollback, %s already exists as a directory"
                % (e[0], ))
            return (
                44,
                "Failed deployment and rollback, %s already exists as a directory"
                % (e[0], ), {})
        #5/3/05 wregglej - 136415 Adding some more exceptions to handle
        except cfg_exceptions.UserNotFound:
            f = sys.exc_info()[1]
            log_to_file(
                0,
                "Failed deployment and rollback, information on user '%s' could not be found"
                % (f[0], ))
            return (
                50,
                "Failed deployment and rollback, information on user '%s' could not be found"
                % (f[0], ), {})
        #5/5/05 wregglej - 136415 Adding exception handling for unknown group,
        except cfg_exceptions.GroupNotFound:
            f = sys.exc_info()[1]
            log_to_file(
                0,
                "Failed deployment and rollback, group '%s' could not be found"
                % (f[0], ))
            return (
                51,
                "Failed deployment and rollback, group '%s' could not be found"
                % (f[0], ), {})
        else:
            log_to_file(
                0, "Failed deployment, %s already exists as a directory" %
                (e[0], ))
            return (45, "Failed deployment, %s already exists as a directory" %
                    (e[0], ), {})
    except cfg_exceptions.DirectoryEntryIsFile:
        e = sys.exc_info()[1]
        try:
            dep_trans.rollback()
        except FailedRollback:
            log_to_file(
                0,
                "Failed deployment and rollback, %s already exists as a file" %
                (e[0], ))
            return (
                46,
                "Failed deployment and rollback, %s already exists as a file" %
                (e[0], ), {})
        #5/3/05 wregglej - 136415 Adding exceptions for missing user
        except cfg_exceptions.UserNotFound:
            f = sys.exc_info()[1]
            log_to_file(
                0,
                "Failed deployment and rollback, information on user '%s' could not be found"
                % (f[0], ))
            return (
                50,
                "Failed deployment and rollback, information on user '%s' could not be found"
                % (f[0], ), {})
        #5/5/05 wregglej - 136415 Adding exception handling for unknown group,
        except cfg_exceptions.GroupNotFound:
            f = sys.exc_info()[1]
            log_to_file(
                0,
                "Failed deployment and rollback, group '%s' could not be found"
                % (f[0], ))
            return (
                51,
                "Failed deployment and rollback, group '%s' could not be found"
                % (f[0], ), {})
        else:
            log_to_file(
                0, "Failed deployment, %s already exists as a file" % (e[0], ))
            return (47, "Failed deployment, %s already exists as a file" %
                    (e[0], ), {})

    except Exception:
        e = sys.exc_info()[1]
        print(e)
        try:
            dep_trans.rollback()
        except FailedRollback:
            e2 = sys.exc_info()[1]
            log_to_file(0, "Failed deployment, failed rollback:  %s" % e2)
            return (48, "Failed deployment, failed rollback:  %s" % e2, {})
        #5/3/05 wregglej - 135415 Add exception handling for missing user.
        except cfg_exceptions.UserNotFound:
            f = sys.exc_info()[1]
            log_to_file(
                0,
                "Failed deployment and rollback, information on user '%s' could not be found"
                % (f[0]))
            return (
                50,
                "Failed deployment and rollback, information on user '%s' could not be found"
                % (f[0]), {})
        #5/5/05 wregglej - 136415 Adding exception handling for unknown group,
        except cfg_exceptions.GroupNotFound:
            f = sys.exc_info()[1]
            log_to_file(
                0,
                "Failed deployment and rollback, group '%s' could not be found"
                % (f[0], ))
            return (
                51,
                "Failed deployment and rollback, group '%s' could not be found"
                % (f[0], ), {})
        else:
            log_to_file(0, "Failed deployment, rolled back:  %s" % e)
            return (49, "Failed deployment, rolled back:  %s" % e, {})

    extras = {}
    log_to_file(
        0, "Files successfully deployed: %s %s" %
        (format_file_string(files, create_key_list()), str(extras)))
    return 0, "Files successfully deployed", extras
예제 #8
0
    def run(self):
        log_debug(2)
        r = self.repository

        channel = self.options.channel
        if not channel:
            die(6, "Config channel not specified")

        topdir = self.options.topdir
        if topdir:
            if not os.path.isdir(self.options.topdir):
                die(8, "--topdir specified, but `%s' not a directory" % self.options.topdir)

        if not self.args:
            die(7, "No files specified")

        revision = self.options.revision
        if revision:
            if len(self.args) > 1:
                die(9, "--revision specified with multiple files")

        dep_trans = None

        if topdir:
            dep_trans = DeployTransaction(transaction_root=topdir)
            dep_trans.deploy_callback(deploying_mesg_callback)

        for f in self.args:
            try:
                directory = topdir or tempfile.gettempdir()

                # 5/11/05 wregglej - 157066 dirs_created is returned from get_file_info.
                (temp_file, info, dirs_created) = r.get_file_info(
                    channel, f, revision=revision, auto_delete=0, dest_directory=directory
                )

            except cfg_exceptions.RepositoryFileMissingError:
                if revision is not None:
                    die(2, "Error: file %s (revision %s) not in config " "channel %s" % (f, revision, channel))
                else:
                    die(2, "Error: file %s not in config channel %s" % (f, channel))

            if topdir:
                # 5/11/05 wregglej - 157066 dirs_created now gets passed into add_preprocessed.
                dep_trans.add_preprocessed(f, temp_file, info, dirs_created, strict_ownership=0)
                continue
            elif info.get("filetype") == "symlink":
                print "%s -> %s" % (info["path"], info["symlink"])
                continue
            elif info.get("filetype") == "directory":
                print "%s is a directory entry, nothing to get" % info["path"]
                continue
            else:
                print open(temp_file).read()
                os.unlink(temp_file)

        if topdir:
            try:
                dep_trans.deploy()
            except Exception, e:
                try:
                    dep_trans.rollback()
                except FailedRollback, e2:
                    raise e2, "FAILED ROLLBACK:  ", sys.exc_info()[2]
                # 5/3/05 wregglej - 136415 Added exception stuff for missing user info.
                except cfg_exceptions.UserNotFound, f:
                    raise
예제 #9
0
def deploy_files(topdir,
                 repository,
                 files,
                 excludes=None,
                 config_channel=None):
    topdir = topdir or os.sep
    if not excludes:
        excludes = []
    dep_trans = DeployTransaction(transaction_root=topdir)
    dep_trans.deploy_callback(deploy_msg_callback)

    for path in files:
        if path in excludes:
            print("Excluding %s" % path)
        else:
            try:
                if config_channel:
                    args = (config_channel, path)
                else:
                    args = (path, )
                kwargs = {'auto_delete': 0, 'dest_directory': topdir}
                finfo = repository.get_file_info(*args, **kwargs)
            except cfg_exceptions.DirectoryEntryIsFile:
                e = sys.exc_info()[1]
                print(
                    "Error: unable to deploy directory %s, as it is already a file on disk"
                    % e[0])
                continue

            if finfo is None:
                # File disappeared since we called the function
                continue

            (processed_path, file_info, dirs_created) = finfo
            try:
                dep_trans.add_preprocessed(path, processed_path, file_info,
                                           dirs_created)
            except cfg_exceptions.UserNotFound:
                e = sys.exc_info()[1]
                print(
                    "Error: unable to deploy file %s, information on user '%s' could not be found."
                    % (path, e[0]))
                continue
            except cfg_exceptions.GroupNotFound:
                e = sys.exc_info()[1]
                print(
                    "Error: unable to deploy file %s, information on group '%s' could not be found."
                    % (path, e[0]))
                continue

    try:
        dep_trans.deploy()
    #5/3/05 wregglej - 136415 added missing user exception stuff.
    except cfg_exceptions.UserNotFound:
        e = sys.exc_info()[1]
        try_rollback(
            dep_trans,
            "Error unable to deploy file, information on user '%s' could not be found"
            % e[0])
    except cfg_exceptions.GroupNotFound:
        e = sys.exc_info()[1]
        try_rollback(
            dep_trans,
            "Error: unable to deploy file, information on group '%s' could not be found"
            % e[0])
    except cfg_exceptions.FileEntryIsDirectory:
        e = sys.exc_info()[1]
        try_rollback(
            dep_trans,
            "Error: unable to deploy file %s, as it is already a directory on disk"
            % e[0])
    except cfg_exceptions.DirectoryEntryIsFile:
        e = sys.exc_info()[1]
        try_rollback(
            dep_trans,
            "Error: unable to deploy directory %s, as it is already a file on disk"
            % e[0])
    except Exception:
        try:
            try_rollback(dep_trans, "Deploy failed, rollback successful")
        except:
            print("Failed rollback")
            raise