generate_ini.py 1.48 KB
Newer Older
Lorenz Steinert's avatar
Lorenz Steinert committed
1 2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
3
"""generate ini file for proto.py"""
Lorenz Steinert's avatar
Lorenz Steinert committed
4

5 6 7 8
import os
import sys
import argparse
from module.esme import get_config
Lorenz Steinert's avatar
Lorenz Steinert committed
9

10
if __name__ == "__main__":
11 12 13 14 15 16 17 18 19 20 21
    RUNDIR = os.path.dirname(os.path.realpath(__file__))

    PARSER = argparse.ArgumentParser(description="generate ini file \
                                                  for the protokollskript")
    PARSER.add_argument('-c', '--config',
                        default=os.path.join(RUNDIR, '../etc/proto.ini'),
                        help="location of generated config file")
    OPT = PARSER.parse_args()

    CONFIG = get_config(RUNDIR, default=True)

22 23
    print('Die Werte in [] können ohne eingabe übernommen werden.')

24
    for i in CONFIG:
25
        print('['+i+']')
26
        for j in CONFIG[i]:
27 28
            tmp = input('Bitte gib [' + j
                        + '] ein [' + CONFIG[i][j] + ']: ')
Lorenz Steinert's avatar
Lorenz Steinert committed
29
            if tmp:
30
                CONFIG[i][j] = tmp
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

    if OPT.config:
        if os.path.isdir(os.path.dirname(OPT.config)):
            OUTFILE = OPT.config
        else:
            print(os.path.dirname(OPT.config) + ': Not a Directory')
            sys.exit(2)
    else:
        if os.path.isdir(os.path.join(RUNDIR, '../etc/proto.ini')):
            OUTFILE = os.path.join(RUNDIR, '../etc/proto.ini')
        else:
            print(os.path.dirname(os.path.join(RUNDIR, '..'))
                  + ': Not a Directory')
            sys.exit(1)

    with open(OUTFILE, 'w') as fobj:
47
        CONFIG.write(fobj)