-
Notifications
You must be signed in to change notification settings - Fork 2
/
privateRepoDload.py
63 lines (47 loc) · 1.51 KB
/
privateRepoDload.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Karthik Muthuswamy
# Download private repos
import encryptData, os
from commands import getoutput as cmd
from github2.client import Github
from encryptData import encryptDESAndWriteData
appid,uname = encryptData.readDataAndDecryptDES('keys.txt', '')
# GitHub configurations
GITHUB_USER = uname
GITHUB_TOKEN = appid
# API Object
github = Github(username=GITHUB_USER, api_token=GITHUB_TOKEN)
# repo slots
repos = {}
repos['private'] = []
repos['public'] = []
# Collect GitHub repos via API
for repo in github.repos.list():
if repo.private:
repos['private'].append(repo)
else:
repos['public'].append(repo)
for org, repos in repos.iteritems():
for repo in repos:
try:
os.makedirs(org)
except OSError:
pass
os.chdir(org)
private = True if org in ('private') else False
# just `git pull` if it's already there
if os.path.exists(repo.name):
os.chdir(repo.name)
print('Updating repo: %s' % (repo.name))
os.system('git pull')
os.chdir('..')
else:
if private:
print('Cloning private repo: %s' % (repo.name))
os.system('git clone [email protected]:%s/%s.git' % (repo.owner, repo.name))
else:
print('Cloning repo: %s' % (repo.name))
os.system('git clone git://github.com/%s/%s.git' % (repo.owner, repo.name))
os.chdir('..')
print