一段导出gitlab工程的python脚本

安装python-gitlab

1
pip install python-gitlab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/python
# -*- coding: UTF-8 -*-

import gitlab

def auth():
gl = gitlab.Gitlab('http://192.168.1.105', private_token='dfshgjkdfgcxvhjkdshfa')
gl.auth()

return gl

def project_list():
gl = auth()
projects = gl.projects.list(all=True)
if(projects != None):
for project in projects:
download_project(gl, project)

def download_project(gl, p):
export = p.exports.create({})

# Wait for the 'finished' status
export.refresh()
while export.export_status != 'finished':
time.sleep(1)
export.refresh()

# Download the result
with open('C://', 'wb') as f:
export.download(streamed=True, action=f.write)

project_list()

注意:GitLab版本至少10.6