d843870183c96dfd0406f8d0648e064a05a9fc1a
[doctor.git] / doctor_tests / installer / common / set_congress.py
1 ##############################################################################
2 # Copyright (c) 2018 ZTE Corporation and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 import configparser
10 import shutil
11
12
13 def set_drivers_config():
14     co_conf = "/etc/congress/congress.conf"
15     co_conf_bak = "/etc/congress/congress.conf.bak"
16     doctor_driver = "congress.datasources.doctor_driver.DoctorDriver"
17     config_modified = False
18
19     config = configparser.ConfigParser()
20     config.read(co_conf)
21     drivers = config['DEFAULT']['drivers']
22
23     if doctor_driver not in drivers:
24         config_modified = True
25         drivers += ',' + doctor_driver
26
27     config['DEFAULT']['drivers'] = drivers
28
29     if config_modified:
30         shutil.copyfile(co_conf, co_conf_bak)
31         with open(co_conf, 'w') as configfile:
32             config.write(configfile)
33
34
35 set_drivers_config()