当前位置: 首页>>代码示例>>Python>>正文


Python git._fail函数代码示例

本文整理汇总了Python中salt.states.git._fail函数的典型用法代码示例。如果您正苦于以下问题:Python _fail函数的具体用法?Python _fail怎么用?Python _fail使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了_fail函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _update_repo

def _update_repo(ret, target, clean, user, rev, opts):
    """
    Update the repo to a given revision. Using clean passes -C to the hg up
    """
    log.debug("target {0} is found, " '"hg pull && hg up is probably required"'.format(target))

    current_rev = __salt__["hg.revision"](target, user=user)
    if not current_rev:
        return _fail(ret, "Seems that {0} is not a valid hg repo".format(target))

    if __opts__["test"]:
        test_result = ("Repository {0} update is probably required (current " "revision is {1})").format(
            target, current_rev
        )
        return _neutral_test(ret, test_result)

    pull_out = __salt__["hg.pull"](target, user=user, opts=opts)

    if rev:
        __salt__["hg.update"](target, rev, force=clean, user=user)
    else:
        __salt__["hg.update"](target, "tip", force=clean, user=user)

    new_rev = __salt__["hg.revision"](cwd=target, user=user)

    if current_rev != new_rev:
        revision_text = "{0} => {1}".format(current_rev, new_rev)
        log.info("Repository {0} updated: {1}".format(target, revision_text))
        ret["comment"] = "Repository {0} updated.".format(target)
        ret["changes"]["revision"] = revision_text
    elif "error:" in pull_out:
        return _fail(ret, "An error was thrown by hg:\n{0}".format(pull_out))
    return ret
开发者ID:wikimedia,项目名称:operations-debs-salt,代码行数:33,代码来源:hg.py

示例2: latest

def latest(name,
           rev=None,
           target=None,
           clean=False,
           user=None,
           force=False,
           opts=False):
    '''
    Make sure the repository is cloned to the given directory and is up to date

    name
        Address of the remote repository as passed to "hg clone"

    rev
        The remote branch, tag, or revision hash to clone/pull

    target
        Name of the target directory where repository is about to be cloned

    clean
        Force a clean update with -C (Default: False)

    user
        Name of the user performing repository management operations

        .. versionadded: 0.17.0

    force
        Force hg to clone into pre-existing directories (deletes contents)

    opts
        Include additional arguments and options to the hg command line
    '''
    ret = {'name': name, 'result': True, 'comment': '', 'changes': {}}

    if not target:
        return _fail(ret, '"target option is required')

    is_repository = (
            os.path.isdir(target) and
            os.path.isdir('{0}/.hg'.format(target)))

    if is_repository:
        ret = _update_repo(ret, name, target, clean, user, rev, opts)
    else:
        if os.path.isdir(target):
            fail = _handle_existing(ret, target, force)
            if fail is not None:
                return fail
        else:
            log.debug(
                    'target {0} is not found, "hg clone" is required'.format(
                        target))
        if __opts__['test']:
            return _neutral_test(
                    ret,
                    'Repository {0} is about to be cloned to {1}'.format(
                        name, target))
        _clone_repo(ret, target, name, user, rev, opts)
    return ret
开发者ID:DavideyLee,项目名称:salt,代码行数:60,代码来源:hg.py

示例3: _clone_repo

def _clone_repo(ret, target, name, user, identity, rev, opts):
    try:
        result = __salt__['hg.clone'](target, name, user=user, identity=identity, opts=opts)
    except CommandExecutionError as err:
        ret['result'] = False
        ret['comment'] = err
        return ret

    if not os.path.isdir(target):
        return _fail(ret, result)

    if rev:
        try:
            __salt__['hg.update'](target, rev, user=user)
        except CommandExecutionError as err:
            ret['result'] = False
            ret['comment'] = err
            return ret

    new_rev = __salt__['hg.revision'](cwd=target, user=user)
    message = 'Repository {0} cloned to {1}'.format(name, target)
    log.info(message)
    ret['comment'] = message

    ret['changes']['new'] = name
    ret['changes']['revision'] = new_rev

    return ret
开发者ID:bryson,项目名称:salt,代码行数:28,代码来源:hg.py

示例4: _update_repo

def _update_repo(ret, target, clean, user, rev, opts):
    '''
    Update the repo to a given revision. Using clean passes -C to the hg up
    '''
    log.debug(
            'target {0} is found, '
            '"hg pull && hg up is probably required"'.format(target)
    )

    current_rev = __salt__['hg.revision'](target, user=user, state_ret=ret)
    if not current_rev:
        return _fail(
                ret,
                'Seems that {0} is not a valid hg repo'.format(target))

    if __opts__['test']:
        test_result = (
                'Repository {0} update is probably required (current '
                'revision is {1})').format(target, current_rev)
        return _neutral_test(
                ret,
                test_result)

    pull_out = __salt__['hg.pull'](target, user=user, opts=opts, state_ret=ret)

    if rev:
        __salt__['hg.update'](target, rev, force=clean, user=user, state_ret=ret)
    else:
        __salt__['hg.update'](target, 'tip', force=clean, user=user, state_ret=ret)

    new_rev = __salt__['hg.revision'](cwd=target, user=user, state_ret=ret)

    if current_rev != new_rev:
        revision_text = '{0} => {1}'.format(current_rev, new_rev)
        log.info(
                'Repository {0} updated: {1}'.format(
                    target, revision_text)
        )
        ret['comment'] = 'Repository {0} updated.'.format(target)
        ret['changes']['revision'] = revision_text
    elif 'error:' in pull_out:
        return _fail(
            ret,
            'An error was thrown by hg:\n{0}'.format(pull_out)
        )
    return ret
开发者ID:MadeiraCloud,项目名称:salt,代码行数:46,代码来源:hg.py

示例5: dirty

def dirty(name,
          target,
          user=None,
          ignore_unversioned=False):
    '''
    Determine if the working directory has been changed.
    '''
    ret = {'name': name, 'result': True, 'comment': '', 'changes': {}}
    return _fail(ret, 'This function is not implemented yet.')
开发者ID:gspradeep,项目名称:salt,代码行数:9,代码来源:svn.py

示例6: _handle_existing

def _handle_existing(ret, target, force):
    not_empty = os.listdir(target)
    if not not_empty:
        log.debug("target {0} found, but directory is empty, automatically " "deleting".format(target))
        shutil.rmtree(target)
    elif force:
        log.debug("target {0} found and is not empty. Since force option is" " in use, deleting anyway.".format(target))
        shutil.rmtree(target)
    else:
        return _fail(ret, "Directory exists, and is not empty")
开发者ID:wikimedia,项目名称:operations-debs-salt,代码行数:10,代码来源:hg.py

示例7: _handle_existing

def _handle_existing(ret, target, force):
    is_empty = os.listdir(target)
    if is_empty:
        log.debug(
            'target {0} found, but directory is empty, automatically '
            'deleting'.format(target))
        shutil.rmtree(target)
    elif force:
        log.debug(
            'target {0} found and is not empty. Since force option is'
            ' in use, deleting anyway.'.format(target))
        shutil.rmtree(target)
    else:
        return _fail(ret, 'Directory exists, and is not empty')
开发者ID:BackSeat,项目名称:salt,代码行数:14,代码来源:hg.py

示例8: latest

def latest(name,
           rev=None,
           target=None,
           runas=None,
           force=False,
        ):
    '''
    Make sure the repository is cloned to to given directory and is up to date

    name
        Address of the remote repository as passed to "hg clone"
    rev
        The remote branch, tag, or revision hash to clone/pull
    target
        Name of the target directory where repository is about to be cloned
    runas
        Name of the user performing repository management operations
    force
        Force hg to clone into pre-existing directories (deletes contents)
    '''
    ret = {'name': name, 'result': True, 'comment': '', 'changes': {}}
    if not target:
        return _fail(ret, '"target option is required')

    is_repository = (
            os.path.isdir(target) and
            os.path.isdir('{0}/.hg'.format(target)))

    if is_repository:
        ret = _update_repo(ret, target, runas, rev)
    else:
        if os.path.isdir(target):
            fail = _handle_existing(ret, target, force)
            if fail is not None:
                return fail
        else:
            log.debug(
                    'target {0} is not found, "hg clone" is required'.format(
                        target))
        if __opts__['test']:
            return _neutral_test(
                    ret,
                    'Repository {0} is about to be cloned to {1}'.format(
                        name, target))
        _clone_repo(ret, target, name, runas, rev)
    return ret
开发者ID:BackSeat,项目名称:salt,代码行数:46,代码来源:hg.py

示例9: _clone_repo

def _clone_repo(ret, target, name, runas, rev):
    result = __salt__['hg.clone'](target, name, user=runas)

    if not os.path.isdir(target):
        return _fail(ret, result)
    
    if rev:
        __salt__['hg.update'](target, rev, user=runas)

    new_rev = __salt__['hg.revision'](cwd=target, user=runas)
    message = 'Repository {0} cloned to {1}'.format(name, target)
    log.info(message)
    ret['comment'] = message

    ret['changes']['new'] = name
    ret['changes']['revision'] = new_rev

    return ret
开发者ID:BackSeat,项目名称:salt,代码行数:18,代码来源:hg.py

示例10: _clone_repo

def _clone_repo(ret, target, name, user, rev, opts):
    result = __salt__["hg.clone"](target, name, user=user, opts=opts)

    if not os.path.isdir(target):
        return _fail(ret, result)

    if rev:
        __salt__["hg.update"](target, rev, user=user)

    new_rev = __salt__["hg.revision"](cwd=target, user=user)
    message = "Repository {0} cloned to {1}".format(name, target)
    log.info(message)
    ret["comment"] = message

    ret["changes"]["new"] = name
    ret["changes"]["revision"] = new_rev

    return ret
开发者ID:wikimedia,项目名称:operations-debs-salt,代码行数:18,代码来源:hg.py

示例11: latest

def latest(name,
           target=None,
           rev=None,
           user=None,
           username=None,
           force=False,
           externals=True):
    '''
    Checkout or update the working directory to the latest revision from the
    remote repository.

    name
        Address of the name repository as passed to "svn checkout"

    target
        Name of the target directory where the checkout will put the working
        directory

    rev : None
        The name revision number to checkout. Enable "force" if the directory
        already exists.

    user : None
        Name of the user performing repository management operations

    username : None
        The user to access the name repository with. The svn default is the
        current user

    force : False
        Continue if conflicts are encountered

    externals : True
        Change to False to not checkout or update externals
    '''
    ret = {'name': name, 'result': True, 'comment': '', 'changes': {}}
    if not target:
        return _fail(ret, 'Target option is required')

    svn_cmd = 'svn.checkout'
    cwd, basename = os.path.split(target)
    opts = tuple()

    if os.path.exists(target) and not os.path.isdir(target):
        return _fail(ret,
                     'The path "{0}" exists and is not '
                     'a directory.'.format(target)
                     )

    try:
        __salt__['svn.info']('.', target, user=user)
        svn_cmd = 'svn.update'
    except exceptions.CommandExecutionError:
        pass

    if rev:
        opts += ('-r', str(rev))

    if force:
        opts += ('--force',)

    if externals is False:
        opts += ('--ignore-externals',)

    if svn_cmd == 'svn.update':
        out = __salt__[svn_cmd](cwd, basename, user, *opts)
    else:
        out = __salt__[svn_cmd](cwd, name, basename, user, username, *opts)
    ret['comment'] = out
    return ret
开发者ID:gspradeep,项目名称:salt,代码行数:70,代码来源:svn.py

示例12: latest

def latest(name,
           rev=None,
           target=None,
           clean=False,
           runas=None,
           user=None,
           force=False,
           opts=False):
    '''
    Make sure the repository is cloned to the given directory and is up to date

    name
        Address of the remote repository as passed to "hg clone"

    rev
        The remote branch, tag, or revision hash to clone/pull

    target
        Name of the target directory where repository is about to be cloned

    clean
        Force a clean update with -C (Default: False)

    runas
        Name of the user performing repository management operations

        .. deprecated:: 0.17.0

    user
        Name of the user performing repository management operations

        .. versionadded: 0.17.0

    force
        Force hg to clone into pre-existing directories (deletes contents)

    opts
        Include additional arguments and options to the hg command line
    '''
    ret = {'name': name, 'result': True, 'comment': '', 'changes': {}, 'state_stdout': ''}

    salt.utils.warn_until(
        'Hydrogen',
        'Please remove \'runas\' support at this stage. \'user\' support was '
        'added in 0.17.0',
        _dont_call_warnings=True
    )
    if runas:
        # Warn users about the deprecation
        ret.setdefault('warnings', []).append(
            'The \'runas\' argument is being deprecated in favor of \'user\', '
            'please update your state files.'
        )
    if user is not None and runas is not None:
        # user wins over runas but let warn about the deprecation.
        ret.setdefault('warnings', []).append(
            'Passed both the \'runas\' and \'user\' arguments. Please don\'t. '
            '\'runas\' is being ignored in favor of \'user\'.'
        )
        runas = None
    elif runas is not None:
        # Support old runas usage
        user = runas
        runas = None

    if not target:
        return _fail(ret, '"target option is required')

    is_repository = (
            os.path.isdir(target) and
            os.path.isdir('{0}/.hg'.format(target)))

    if is_repository:
        ret = _update_repo(ret, target, clean, user, rev, opts)
    else:
        if os.path.isdir(target):
            fail = _handle_existing(ret, target, force)
            if fail is not None:
                return fail
        else:
            log.debug(
                    'target {0} is not found, "hg clone" is required'.format(
                        target))
        if __opts__['test']:
            return _neutral_test(
                    ret,
                    'Repository {0} is about to be cloned to {1}'.format(
                        name, target))
        _clone_repo(ret, target, name, user, rev, opts)
    return ret
开发者ID:MadeiraCloud,项目名称:salt,代码行数:90,代码来源:hg.py

示例13: latest

def latest(name,
           target=None,
           rev=None,
           user=None,
           username=None,
           password=None,
           force=False,
           externals=True,
           trust=False):
    '''
    Checkout or update the working directory to the latest revision from the
    remote repository.

    name
        Address of the name repository as passed to "svn checkout"

    target
        Name of the target directory where the checkout will put the working
        directory

    rev : None
        The name revision number to checkout. Enable "force" if the directory
        already exists.

    user : None
        Name of the user performing repository management operations

    username : None
        The user to access the name repository with. The svn default is the
        current user

    password
        Connect to the Subversion server with this password

        .. versionadded:: 0.17.0

    force : False
        Continue if conflicts are encountered

    externals : True
        Change to False to not checkout or update externals

    trust : False
        Automatically trust the remote server. SVN's --trust-server-cert
    '''
    ret = {'name': name, 'result': True, 'comment': '', 'changes': {}}
    if not target:
        return _fail(ret, 'Target option is required')

    svn_cmd = 'svn.checkout'
    cwd, basename = os.path.split(target)
    opts = tuple()

    if os.path.exists(target) and not os.path.isdir(target):
        return _fail(ret,
                     'The path "{0}" exists and is not '
                     'a directory.'.format(target)
                     )
    if __opts__['test']:
        if not os.path.exists(target):
            return _neutral_test(
                    ret,
                    ('{0} doesn\'t exist and is set to be checked out.').format(target))
        svn_cmd = 'svn.diff'
        opts += ('-r', 'HEAD')
        out = __salt__[svn_cmd](cwd, target, user, username, password, *opts)
        return _neutral_test(
                ret,
                ('{0}').format(out))
    try:
        current_info = __salt__['svn.info'](cwd, target, user=user, username=username, password=password, fmt='dict')
        svn_cmd = 'svn.update'
    except exceptions.CommandExecutionError:
        pass

    if rev:
        opts += ('-r', str(rev))

    if force:
        opts += ('--force',)

    if externals is False:
        opts += ('--ignore-externals',)

    if trust:
        opts += ('--trust-server-cert',)

    if svn_cmd == 'svn.update':
        out = __salt__[svn_cmd](cwd, basename, user, username, password, *opts)

        current_rev = current_info[0]['Revision']
        new_rev = __salt__['svn.info'](cwd=target,
                                       targets=None,
                                       user=user,
                                       username=username,
                                       password=password,
                                       fmt='dict')[0]['Revision']
        if current_rev != new_rev:
            ret['changes']['revision'] = "{0} => {1}".format(current_rev, new_rev)

#.........这里部分代码省略.........
开发者ID:DaveQB,项目名称:salt,代码行数:101,代码来源:svn.py

示例14: export

def export(name,
           target=None,
           rev=None,
           user=None,
           username=None,
           password=None,
           force=False,
           overwrite=False,
           externals=True,
           trust=False):
    '''
    Export a file or directory from an SVN repository

    name
        Address and path to the file or directory to be exported.

    target
        Name of the target directory where the checkout will put the working
        directory

    rev : None
        The name revision number to checkout. Enable "force" if the directory
        already exists.

    user : None
        Name of the user performing repository management operations

    username : None
        The user to access the name repository with. The svn default is the
        current user

    password
        Connect to the Subversion server with this password

        .. versionadded:: 0.17.0

    force : False
        Continue if conflicts are encountered

    overwrite : False
        Overwrite existing target

    externals : True
        Change to False to not checkout or update externals

    trust : False
        Automatically trust the remote server. SVN's --trust-server-cert
    '''
    ret = {'name': name, 'result': True, 'comment': '', 'changes': {}}
    if not target:
        return _fail(ret, 'Target option is required')

    svn_cmd = 'svn.export'
    cwd, basename = os.path.split(target)
    opts = tuple()

    if not overwrite and os.path.exists(target) and not os.path.isdir(target):
        return _fail(ret,
                     'The path "{0}" exists and is not '
                     'a directory.'.format(target)
                     )
    if __opts__['test']:
        if not os.path.exists(target):
            return _neutral_test(
                    ret,
                    ('{0} doesn\'t exist and is set to be checked out.').format(target))
        svn_cmd = 'svn.list'
        rev = 'HEAD'
        out = __salt__[svn_cmd](cwd, target, user, username, password, *opts)
        return _neutral_test(
                ret,
                ('{0}').format(out))

    if not rev:
        rev = 'HEAD'

    if force:
        opts += ('--force',)

    if externals is False:
        opts += ('--ignore-externals',)

    if trust:
        opts += ('--trust-server-cert',)

    out = __salt__[svn_cmd](cwd, name, basename, user, username, password, rev, *opts)
    ret['changes'] = name + ' was Exported to ' + target

    return ret
开发者ID:DaveQB,项目名称:salt,代码行数:89,代码来源:svn.py

示例15: latest

def latest(name, rev=None, target=None, clean=False, runas=None, user=None, force=False, opts=False):
    """
    Make sure the repository is cloned to the given directory and is up to date

    name
        Address of the remote repository as passed to "hg clone"

    rev
        The remote branch, tag, or revision hash to clone/pull

    target
        Name of the target directory where repository is about to be cloned

    clean
        Force a clean update with -C (Default: False)

    runas
        Name of the user performing repository management operations

        .. deprecated:: 0.17.0

    user
        Name of the user performing repository management operations

        .. versionadded: 0.17.0

    force
        Force hg to clone into pre-existing directories (deletes contents)

    opts
        Include additional arguments and options to the hg command line
    """
    ret = {"name": name, "result": True, "comment": "", "changes": {}}

    salt.utils.warn_until(
        "Lithium",
        "Please remove 'runas' support at this stage. 'user' support was " "added in 0.17.0",
        _dont_call_warnings=True,
    )
    if runas:
        # Warn users about the deprecation
        ret.setdefault("warnings", []).append(
            "The 'runas' argument is being deprecated in favor of 'user', " "please update your state files."
        )
    if user is not None and runas is not None:
        # user wins over runas but let warn about the deprecation.
        ret.setdefault("warnings", []).append(
            "Passed both the 'runas' and 'user' arguments. Please don't. "
            "'runas' is being ignored in favor of 'user'."
        )
        runas = None
    elif runas is not None:
        # Support old runas usage
        user = runas
        runas = None

    if not target:
        return _fail(ret, '"target option is required')

    is_repository = os.path.isdir(target) and os.path.isdir("{0}/.hg".format(target))

    if is_repository:
        ret = _update_repo(ret, target, clean, user, rev, opts)
    else:
        if os.path.isdir(target):
            fail = _handle_existing(ret, target, force)
            if fail is not None:
                return fail
        else:
            log.debug('target {0} is not found, "hg clone" is required'.format(target))
        if __opts__["test"]:
            return _neutral_test(ret, "Repository {0} is about to be cloned to {1}".format(name, target))
        _clone_repo(ret, target, name, user, rev, opts)
    return ret
开发者ID:wikimedia,项目名称:operations-debs-salt,代码行数:74,代码来源:hg.py


注:本文中的salt.states.git._fail函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。