-
Notifications
You must be signed in to change notification settings - Fork 0
/
github.py
executable file
·71 lines (61 loc) · 1.96 KB
/
github.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
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python2
from __future__ import print_function, unicode_literals, division
import requests
import argparse
import subprocess
class Account(object):
def __init__(self, name, passwd, typ):
self.name = name
self.passwd = passwd
self.type = typ
pass
def list_repo(account):
print(account.type, account.name, account.passwd)
def create_repo(account, repoName):
print(account, repoName)
def filter_None(x):
if x is None:
return False
return True
def shell_out(cmd):
try:
r = subprocess.check_output(cmd.split(' '))
s = r.strip()
if len(s) > 2:
return s
else:
return None
except subprocess.CalledProcessError:
pass
return None
def get_account_info(acc):
user = shell_out('git config %s.name' % acc)
passwd = shell_out('git config %s.passwd' % acc)
_type = shell_out('git config %s.type' % acc)
if _type is None:
_type = acc
if user is None or passwd is None:
return None
else:
return Account(user, passwd, _type)
def main(args):
taccs = args.target
if taccs is None:
taccs = ['github', 'bitbucket']
accs = map(get_account_info, taccs)
accs = filter(filter_None, accs)
if args.list:
for acc in accs:
list_repo(acc)
else if args.create:
for acc in accs:
for repo in arg.create:
create_repo(acc, repo)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--private', action='store_true', default=False, help="mark repo private [creation only]")
parser.add_argument('-t', '--target', nargs='+', help="targets account, should be list in ~/.gitconfig")
parser.add_argument('-c', '--create', nargs='+', help="repo names to be created")
parser.add_argument('-l', '--list', action='store_true', default=False, help="list repos")
args = parser.parse_args()
main(args)