File: config_gen.py

package info (click to toggle)
glueviz 0.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 17,180 kB
  • ctags: 6,728
  • sloc: python: 37,111; makefile: 134; sh: 60
file content (51 lines) | stat: -rwxr-xr-x 1,216 bytes parent folder | download
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
#!/usr/bin/env python
"""
Script used to create template config.py files for Glue
"""

from __future__ import absolute_import, division, print_function

import os
import sys
from shutil import copyfile

import glue
from glue.external.six import input


def get_clobber():
    result = None
    result = input("\nDestination file exists. Overwrite? [y/n] ")
    while result not in ['y', 'n']:
        print("\tPlease choose one of [y/n]")
        result = input("\nDestination file exists. Overwrite? [y/n] ")

    return result == 'y'


def main():

    # Import at runtime because some tests change this value. We also don't
    # just import the function directly otherwise it is cached.
    from glue import config
    dest = config.CFG_DIR

    if not os.path.exists(dest):
        print("Creating directory %s" % dest)
        os.makedirs(dest)

    infile = os.path.join(glue.__path__[0], 'default_config.py')
    outfile = os.path.join(dest, 'config.py')

    print("Creating file %s" % outfile)

    if os.path.exists(outfile):
        clobber = get_clobber()
        if not clobber:
            print("Exiting")
            sys.exit(1)

    copyfile(infile, outfile)

if __name__ == "__main__":
    main()