forked from fossasia/open-event-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
65 lines (46 loc) · 1.73 KB
/
main.py
File metadata and controls
65 lines (46 loc) · 1.73 KB
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
import argparse
import logging
import sys
import threading
from os.path import join
import yaml
from auto_updater import AutoUpdater
POLL_SECONDS = 60
logger = logging.getLogger(__name__)
log_format = '%(asctime)s [%(levelname)s] %(name)s: %(message)s'
logging.basicConfig(level=logging.INFO, format=log_format)
parser = argparse.ArgumentParser()
parser.add_argument('--workdir', help='Directory to clone projects in')
parser.add_argument('--config', help='config.yml with project descriptions')
def get_auto_updater(cwd, name, cfg):
logger.info('project <%s> from <%s> added', name, cfg['url'])
a = AutoUpdater(name, cfg['url'], cwd=join(cwd, name), branch=cfg['branch'])
if 'init' in cfg or 'upgrade' in cfg:
a.add_scripts(
container=cfg['container'], init_cmd=cfg['init'], upgrade_cmd=cfg['upgrade']
)
return a
def start_all_projects(projects):
for p in projects:
p.start()
def update_all_projects(projects):
for p in projects:
logger.info('updating %s', p.repo)
p.update()
p.upgrade()
logger.info('sleeping %d seconds', POLL_SECONDS)
threading.Timer(POLL_SECONDS, update_all_projects).start()
if __name__ == '__main__':
args = parser.parse_args()
if not args.workdir or not args.config:
print('workdir/config not set. run `--help` to show options')
sys.exit(1)
cwd = args.workdir
config_file = args.config
with open(config_file, 'r') as ymlfile:
config = yaml.safe_load(ymlfile)
projects = [get_auto_updater(cwd, n, config[n]) for n in config]
logger.info('starting projects')
start_all_projects(projects)
logger.info('starting update threads for projects')
update_all_projects(projects)