-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.py
65 lines (52 loc) · 2.21 KB
/
setup.py
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
"""This script creates a config file for the main script.
This should be run once at the very beginning before
the main script run (zola_deputy.py).
Then it should be run every time you want to reconfigure the script."""
import sys
import argparse
import configparser
from os import path
def create_parser():
"""Creates parameters passed from console"""
parser = argparse.ArgumentParser()
parser.add_argument('-xak', '--x_api_key')
parser.add_argument('-ui', '--user_id')
parser.add_argument('-dat', '--deputy_access_token')
parser.add_argument('-did', '--deputy_id')
parser.add_argument('-url', '--url')
parser.add_argument('-spid', '--spreadsheet_id')
parser.add_argument('-logmode', '--logmode', default='file')
parser.add_argument('-logpath', '--logpath', default='./logs')
return parser
def initialize_variables():
"""Using parser to output parameters from console"""
config = configparser.ConfigParser()
parser = create_parser()
namespace = parser.parse_args(sys.argv[1:])
if len(sys.argv) == 1:
sys.exit(
"Please check if you run script with parameters . Script is terminated")
config.add_section('XOLA')
config["XOLA"]["x_api_key"], config["XOLA"]["user_id"] = namespace.x_api_key, namespace.user_id
config.add_section('DEPUTY')
deputy_access_token = namespace.deputy_access_token
deputy_id = namespace.deputy_id
config["DEPUTY"]["deputy_access_token"], config["DEPUTY"]["deputy_id"] = \
deputy_access_token, deputy_id
config.add_section('LOG')
config["LOG"]["log_path"], config["LOG"]["log_mode"] = namespace.logpath, namespace.logmode
config.add_section('URL')
config['URL']['public_url'] = namespace.url
config.add_section('GOOGLE')
config['GOOGLE']['spreadsheet_id'] = namespace.spreadsheet_id
with open('xola_deputy/Settings.ini', 'w') as configfile: # save
config.write(configfile)
if __name__ == '__main__':
if path.isfile('xola_deputy/Settings.ini'):
key = input("Do you really wanna change your settings?(y/n) ")
if key == "y":
initialize_variables()
else:
sys.exit("Script is terminated")
else:
initialize_variables()