forked from OpenXT-Extras/scripts
- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreplicate_github.py
More file actions
Latest commit
executable file
·44 lines (42 loc) · 1.65 KB
/
Copy pathreplicate_github.py
File metadata and controls
executable file
·44 lines (42 loc) · 1.65 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
#! /usr/bin/env python
fromurllib2importurlopen, URLError
fromjsonimportload
fromosimportrename
fromos.pathimportisdir, join
fromsubprocessimportcheck_call
fromoptparseimportOptionParser
parser=OptionParser()
parser.add_option('--user', help='Override git repos with any of matching name from USER',
metavar='USER')
parser.add_option('--git-binary', metavar='PATH', default='git',
help='Assume git binary is at PATH')
options, args=parser.parse_args()
iflen(args)!=2:
print'USAGE: replicate_github organization destination_directory'
print
print'replicate all repos in github organization; when first seen'
print'clone them, on later runs fetch'
print
print'if USER_OVERRIDE is specified, overlay any matching repos from that user'
exit(1)
repos=load(urlopen('https://api.github.com/orgs/'+args[0]+'/repos?type=all&per_page=1000'))
forrepoinrepos:
destd=join(args[1], repo['name']+'.git')
ifnotisdir(destd):
print'cloning to', destd
check_call([options.git_binary, 'clone', '--bare', repo['clone_url'], destd])
else:
print'fetching to', destd
check_call([options.git_binary, 'fetch', '--all'], cwd=destd)
ifoptions.user:
forrepoinrepos:
url='https://github.com/'+options.user+'/'+repo['name']+'.git'
try:
urlopen(url)
exceptURLError:
continue
destd=join(args[1], repo['name']+'.git')
upstreamd=destd+'.upstream'
ifnotisdir(upstreamd):
rename(destd, upstreamd)
check_call([options.git_binary, 'clone', '--bare', url, destd])