summaryrefslogtreecommitdiff
path: root/playoff.py
blob: 4e4d197217539515c797978912b755e414676ec7 (plain)
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
import traceback

from jfr_playoff.filemanager import PlayoffFileManager
from jfr_playoff.generator import PlayoffGenerator
from jfr_playoff.settings import PlayoffSettings
from jfr_playoff.logger import PlayoffLogger


def main():

    interactive = False

    try:
        import argparse
        arg_parser = argparse.ArgumentParser(
            description='Generate play-off HTML for JFR Teamy tournaments')
        output_args = arg_parser.add_mutually_exclusive_group()
        output_args.add_argument('-v', '--verbose', action='store_true',
                                 help='display info on STDERR')
        output_args.add_argument('-vv', '--debug', action='store_true',
                                 help='display debug info on STDERR')
        output_args.add_argument('-q', '--quiet', action='store_true',
                                 help='suppress warnings on STDERR')
        arg_parser.add_argument('config_file', metavar='JSON_FILE',
                                help='path to config JSON file',
                                type=str, nargs='?', default=None)
        arguments = arg_parser.parse_args()

        PlayoffLogger.setup('ERROR' if arguments.quiet else (
            'INFO' if arguments.verbose else (
                'DEBUG' if arguments.debug else 'WARNING')))

        PlayoffLogger.get().info('started with arguments: %s', arguments)

        settings = PlayoffSettings(arguments.config_file)
        interactive = settings.interactive

        generator = PlayoffGenerator(settings)
        content = generator.generate_content()

        file_manager = PlayoffFileManager(settings)
        file_manager.write_content(content)
        file_manager.copy_scripts()
        file_manager.copy_styles()
        file_manager.send_files()
    except SystemExit:
        interactive = False
        raise
    except:
        print traceback.format_exc()
    finally:
        if interactive:
            raw_input('Press any key to continue...')

if __name__ == '__main__':
    main()