-
Notifications
You must be signed in to change notification settings - Fork 1
/
buildbot.py
executable file
·77 lines (61 loc) · 2.51 KB
/
buildbot.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
72
73
74
75
76
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import argparse
import os
import sys
from ConfigParser import ConfigParser
import logger
from dbutils import fetch_airports
from txutils import txupdate
from vatsimutils import clone_status
def read_config(file_name='config.ini'):
"""
Read config file.
@param file_name: The config file location.
@return: Config.
"""
if not os.path.isfile(file_name):
print('Config file missing')
sys.exit(1)
config = ConfigParser()
config.read(file_name)
return config
def main():
"""
Parse command line options, read config and run desired action.
"""
description = 'Vatsinator Buildbot automates server-side procedures for Vatsinator.'
parser = argparse.ArgumentParser(description=description)
parser.add_argument('command', choices=['txupdate', 'clone_status', 'fetch_airports'],
help='command to be run', metavar='command')
parser.add_argument('--config', '-c', dest='config_file', default='config.ini',
help='config file location (default: config.ini)',
metavar='config_file')
parser.add_argument('--logfile', '-l', dest='log_file', default='stdout',
help='file to log actions (default: stdout)', metavar='log_file')
args = parser.parse_args()
config = read_config(args.config_file)
log_file = args.log_file
if log_file != 'stdout':
f = open(log_file, 'a')
logger.output = f
if args.command == 'txupdate':
if not config.has_section('Repository'):
print('Missing \'Repository\' section in the config file. See config.ini.sample for reference.')
sys.exit(1)
txupdate(repodir=config.get('Repository', 'vatsinator'),
author=(config.get('Repository', 'author_name'), config.get('Repository', 'author_email')),
txbranch=config.get('Translations', 'txbranch')
)
elif args.command == 'clone_status':
if not config.has_section('Vatsim'):
print('Missing \'Vatsim\' section in the config file. See config.ini.sample for reference.')
sys.exit(1)
clone_status(config.get('Vatsim', 'status_file'))
elif args.command == 'fetch_airports':
if not config.has_section('Database'):
print('Missing \'Database\' section in the config file. See config.ini.sample for reference.')
sys.exit(1)
fetch_airports(config)
if __name__ == "__main__":
main()