28 lines
1.1 KiB
Python
28 lines
1.1 KiB
Python
import os
|
|
import json
|
|
import urllib.request
|
|
|
|
def httpGet(url, params={}):
|
|
real_url = url + urllib.parse.urlencode(params)
|
|
req = urllib.request.Request(real_url)
|
|
req.add_header('Private-Token', 'cRjSP2EUx1SaQYcis9W7')
|
|
data = urllib.request.urlopen(req).readall()
|
|
return json.loads(data.decode('utf-8'))
|
|
|
|
projects = httpGet('http://git.kingsome.cn/api/v4/projects?',
|
|
{
|
|
'page': 1,
|
|
'per_page': 1000
|
|
})
|
|
for proj in projects:
|
|
http_url_to_repo = proj['http_url_to_repo']
|
|
name = proj['name']
|
|
path = proj['namespace']['path']
|
|
if not os.path.exists('repository/%s' % path):
|
|
os.mkdir('repository/%s' % (path))
|
|
if not os.path.exists('repository/%s/%s' % (path, name)):
|
|
os.system('cd repository/%s/%s && git clone %s' % (path, name, http_url_to_repo))
|
|
os.system('cd repository/%s/%s && git pull' % (path, name))
|
|
os.system('cd repository/%s/%s && git submodule init' % (path, name))
|
|
os.system('cd repository/%s/%s && git submodule update' % (path, name))
|