• pythongitlab


    python-gitlab:下载文件或者指定文件夹
    1.下载文件

    //需要先创建本地目录,先删除再创建
    def emptyFolder(pathName):
    if 1 == os.path.exists(pathName):
    shutil.rmtree(pathName)
    allPath = 'D:/WebContent/'
    emptyFolder(allPath)
    os.makedirs(allPath)

    //下载gitlab文件到本地,先打开本地文件,file_path是远程Git路径,ref是分支
    with open('D:/WebContent/AppConfig.h', 'wb') as f:
    project.files.raw(file_path='/src/main/AppConfig.h', ref='ReplaceWeb', streamed=True, action=f.write)
    print u"下载AppConfig.h成功"

    2.下载文件夹

    //需要先创建本地目录,先删除再创建
    def emptyFolder(pathName):
    if 1 == os.path.exists(pathName):
    shutil.rmtree(pathName)
    allPath = 'D:/WebContent/'
    emptyFolder(allPath)
    os.makedirs(allPath)

    //获取远程文件树(path是远程Git文件夹目录,ref是分支名,递归获取)
    fileList = project.repository_tree(path='bin/tools/', ref='master', recursive=True, all=True)

    //本地创建文件树中的目录
    for i in fileList:
    if (i['type'] == "tree"):
    dirs = 'D:/WebContent/%s' % i['path']
    if not os.path.exists(dirs):
    os.makedirs(dirs)

    print u"...下载文件中..."
    //下载tools文件夹
    for i in fileList:
    if (i['type'] == "blob"):
    with open('D:/WebContent/%s' % i['path'], 'wb') as f:
    project.files.raw(file_path=i['path'], ref='master', streamed=True, action=f.write)
    print u"%s" %i['path']
    print u"...文件下载完毕..."

  • 相关阅读:
    FCKEditor配置
    在线文档编辑器原理
    DVD格式(vob)文件转换avi,转换后可嵌入HTML中播放
    Javascript小技巧
    sql server 查询当前记录的前一条和后一条记录
    [翻译]开发一个自己的HTML在线编辑器(二)
    在线编辑器(4)TAB键缩进功能
    IIS不能浏览ASP页面
    C#枚举类型的使用《转》
    C#中泛型使用《转》
  • 原文地址:https://www.cnblogs.com/hushaojun/p/15994306.html
Copyright © 2020-2023  润新知