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
|
from argparse import ArgumentParser
import logging
import sys
from pull.cgit import CGit, Output
from pull.my_repos import MY_REPOS
DEFAULT_OUTPUT_DIR = 'output'
DEFAULT_CGIT_CLONE_USER = 'egor'
DEFAULT_CGIT_CLONE_HOST = 'tensin-ext1.home'
DEFAULT_CGIT_CLONE_PORT = 8080
def set_up_logging():
logging.basicConfig(
level=logging.DEBUG,
datefmt='%Y-%m-%d %H:%M:%S',
format='%(asctime)s | %(levelname)s | %(message)s')
def parse_args(argv=None):
if argv is None:
argv = sys.argv[1:]
parser = ArgumentParser()
parser.add_argument('--output', metavar='PATH',
default=DEFAULT_OUTPUT_DIR,
help='output directory path')
parser.add_argument('--cgit-user', metavar='USERNAME',
default=DEFAULT_CGIT_CLONE_USER,
help='cgit clone username')
parser.add_argument('--cgit-host', metavar='HOST',
default=DEFAULT_CGIT_CLONE_HOST,
help='cgit clone host')
parser.add_argument('--cgit-port', metavar='PORT', type=int,
default=DEFAULT_CGIT_CLONE_PORT,
help='cgit clone port number')
parser.add_argument('--repo', metavar='REPO_ID', nargs='*', dest='repos',
help='repos to pull')
return parser.parse_args(argv)
def main(args=None):
set_up_logging()
try:
args = parse_args(args)
cgit = CGit(args.cgit_user, args.cgit_host, args.cgit_port)
output = Output(args.output, cgit)
success = True
for repo in MY_REPOS:
if args.repos is None or repo.repo_id in args.repos:
if not output.pull(repo):
success = False
if success:
logging.info('All repositories were updated successfully')
return 0
else:
logging.warning("Some repositories couldn't be updated!")
return 1
except Exception as e:
logging.exception(e)
raise
if __name__ == '__main__':
sys.exit(main())
|