File: init_cfg.py

package info (click to toggle)
doris 5.0.3~beta%2Bdfsg-7
  • links: PTS, VCS
  • area: contrib
  • in suites: buster
  • size: 5,704 kB
  • sloc: cpp: 43,593; python: 8,189; csh: 3,636; sh: 2,527; ansic: 649; makefile: 341; xml: 198
file content (75 lines) | stat: -rw-r--r-- 2,933 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/env python

import xml.etree.ElementTree as ET
import os

def init_cfg():
    template_xml_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'doris_config_template.xml')
    xml_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'doris_config.xml')
    tree = ET.parse(template_xml_file)
    settings = tree.getroot()

    settings.find('.source_path').text = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

    input = False
    while input == False:
        user_input = raw_input("Enter the path to doris: ")
        if os.path.exists(user_input) and user_input.endswith('doris'):
            settings.find('.doris_path').text = user_input
            input = True
        else:
            print('The path is incorrect, use another path')

    input = False
    while input == False:
        user_input = raw_input("Enter the path to cpxfiddle: ")
        if os.path.exists(user_input) and user_input.endswith('cpxfiddle'):
            settings.find('.cpxfiddle_path').text = user_input
            input = True
        else:
            print('The path is incorrect, use another path')

    input = False
    while input == False:
        user_input = raw_input("Enter the path to snaphu: ")
        if os.path.exists(user_input) and user_input.endswith('snaphu'):
            settings.find('.snaphu_path').text = user_input
            input = True
        else:
            print('The path is incorrect, use another path')

    # Now create the password file.
    user_input = raw_input("Enter your username for scihub (https://scihub.copernicus.eu/dhus/#/self-registration)")
    if len(user_input) > 0:
        settings.find('.scihub_username').text = user_input
    else:
        print('Username field is empty, you can change it later in the doris_config.xml file')

    user_input = raw_input("Enter your password for scihub ")
    if len(user_input) > 0:
        settings.find('.scihub_password').text = user_input
    else:
        print('Password field is empty, you can change it later in the doris_config.xml file')

    user_input = raw_input("Enter your username for srtm download (https://urs.earthdata.nasa.gov/users/new/)")
    if len(user_input) > 0:
        settings.find('.usgs_username').text = user_input
    else:
        print('Username field is empty, you can change it later in the doris_config.xml file')

    user_input = raw_input("Enter your password for srtm download ")
    if len(user_input) > 0:
        settings.find('.usgs_password').text = user_input
    else:
        print('Password field is empty, you can change it later in the doris_config.xml file')

    print('Doris is initialized. If you want to make changes later, you can change the doris_config.xml file' +
          ' or run this script again')

    tree.write(open(xml_file, 'w'))

# Actually execute the code...
if __name__ == "__main__":

    # Initialize...
    init_cfg()