repo.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:ipbb 作者: ipbus 项目源码 文件源码
def srcstat(env):

    if not env.workPath:
        secho  ( 'ERROR: No ipbb work area detected', fg='red' )
        return

    secho ( "Packages", fg='blue' )
    lSrcs = env.getSources()
    if not lSrcs:
        return

    lSrcTable = Texttable(max_width=0)
    lSrcTable.set_deco(Texttable.HEADER | Texttable.BORDER)
    lSrcTable.set_chars(['-', '|', '+', '-'])
    lSrcTable.header(['name', 'kind', 'version'])
    for lSrc in lSrcs:
        lSrcDir = join(env.src, lSrc)

        lKind, lBranch = "unknown", None

        # Check if a git repository
        if exists(join( lSrcDir, '.git')):
            with DirSentry(lSrcDir) as _:
                lKind = 'git'

                try:
                    # lBranch = sh.git('symbolic-ref','--short', 'HEAD').strip()
                    lBranch = sh.git('symbolic-ref', 'HEAD').split('/')[-1].strip()
                except sh.ErrorReturnCode_128:
                    lBranch = sh.git('rev-parse', '--short', 'HEAD').strip()+'...'

                try:
                    sh.git('diff', '--no-ext-diff', '--quiet').strip()
                except sh.ErrorReturnCode_1:
                    lBranch += '*'

                try:
                    sh.git('diff', '--no-ext-diff', '--cached', '--quiet').strip()
                except sh.ErrorReturnCode_1:
                    lBranch += '+'
        elif exists(join( lSrcDir, '.svn')):
            with DirSentry(lSrcDir) as _:
                lKind = 'svn'

                lSVNInfoRaw = sh.svn('info')

                lSVNInfo = { lEntry[0]:lEntry[1].strip() for lEntry in ( lLine.split(':',1) for lLine in lSVNInfoRaw.split('\n') if lLine )}

                lBranch = lSVNInfo['URL'].replace( lSVNInfo['Repository Root']+'/', '' )

                lSVNStatus = sh.svn('status','-q')
                if len(lSVNStatus):
                    lBranch += '*'

        lSrcTable.add_row([lSrc, lKind, lBranch])
    echo  ( lSrcTable.draw() )

# ------------------------------------------------------------------------------
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号