/
gitcloner
executable file
·83 lines (67 loc) · 2.62 KB
/
gitcloner
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
72
73
74
75
76
77
78
79
80
81
82
83
#! /usr/bin/env python3
import argparse
import sys
from gitaccount import GitAccount
def main():
parser = argparse.ArgumentParser(
prog='gitcloner',
description='''Clone all the repositories from a github user/org
account to the current directory''')
accType = parser.add_mutually_exclusive_group()
accType.add_argument('-u', '--user', help='For user accounts [DEFAULT]',
action='store_true')
accType.add_argument('-o', '--org', help='For organization accounts',
action='store_true')
type_of_repo = parser.add_mutually_exclusive_group()
type_of_repo.add_argument('-r', '--repo',
help='For cloning repos only[DEFAULT]',
action='store_true')
type_of_repo.add_argument('-g', '--gist', help='For cloning gists only',
action='store_true')
type_of_repo.add_argument('-a', '--all',
help='For cloning repos and gists together',
action='store_true')
command = parser.add_mutually_exclusive_group()
command.add_argument('-c', '--clone',
help='''For cloning all repos/gists from an account.
[DEFAULT]''',
action='store_true')
command.add_argument('-p', '--pull',
help='Update the existing repos/gists of a user/org.',
action='store_true')
parser.add_argument('name', help='name of the user / organization')
args = parser.parse_args()
if not args.org:
args.user = True
print('Default account type is user account')
if args.user:
print('Username: {}'.format(args.name))
accType = 'user'
else:
print('Organization: {}'.format(args.name))
accType = 'org'
account = GitAccount(accType, args.name)
if not(args.clone or args.pull):
args.clone = True
if not(args.gist or args.all):
args.repo = True
if (args.gist or args.all) and args.org:
print('Cloning gists of an organization is not supported!')
sys.exit(1)
if args.repo or args.all:
if args.clone:
account.clone_repos()
else:
account.pull_repos()
if args.gist or args.all:
if args.clone:
account.clone_gists()
else:
account.pull_gists()
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
print('\nOperation cancelled!')
print('Interrupted by user.')
sys.exit(1)