-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgit-mirror.py
58 lines (48 loc) · 1.83 KB
/
git-mirror.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (C) 2018 Sandro Lutz <[email protected]>
#
# This software is licensed under GPLv3, see LICENSE for details.
import argparse
import ipaddress
import json
from hoster import getHosterInstance
from task import getTaskInstance
parser = argparse.ArgumentParser(prog='git-mirror.py',
description='Mirrors repositories between GitLab, GitHub and Bitbucket w/o direct access to the GitLab Server.')
parser.add_argument('-v', '--verbose', action="store_true",
help='prints more output to the console')
parser.add_argument('-c', '--config', metavar='config.json', nargs=1, type=argparse.FileType('r'),
default='config.json', help='path to the configuration file')
parser.add_argument('--version', action='version', version='%(prog)s 1.1.0')
args = parser.parse_args()
try:
# Read configuration file
if (type(args.config) is list):
data = json.load(args.config[-1])
else:
data = json.load(args.config)
if 'hoster' not in data:
raise ValueError('Configuration file does not contain any hoster')
hoster = dict()
for config in data['hoster']:
if 'name' not in config:
raise ValueError('Not all hoster in the configuration file have a name assigned')
hoster[config['name']] = getHosterInstance(config)
if args.verbose:
print('Hoster ' + config['name'] + ' loaded')
tasks = list()
for config in data['tasks']:
tasks.append(getTaskInstance(config, hoster))
if args.verbose:
print('Task ' + config['name'] + ' prepared')
for task in tasks:
# TODO: Run tasks asynchonously
if args.verbose:
print('Run task ' + task.name + '...')
task.run(args.verbose)
if args.verbose:
print('-----------')
except KeyboardInterrupt:
print('KeyboardInterrupt received! Mirroring stopped.')