This repository has been archived by the owner on Oct 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
114 lines (94 loc) · 3.15 KB
/
config.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
from os import path
import configparser
from configparser import ConfigParser
from collections import namedtuple
COLORS = {
"#556B2F": "Strongly Positive",
"#019B00": "Positive",
"#789B01": "Weakly Positive",
"#015A9B": "Slightly Positive",
"#1F019B": "Slightly Negative",
"#73019B": "Weakly Negative",
"#9B016F": "Negative",
"#9B0112": "Strongly Negative"
}
UPLOAD_DIR = "file_upload"
Review = namedtuple(
'Review', ['rating', 'body', 'title', 'date', 'version', 'region'])
class Config(object):
HOME_DIR = path.abspath(path.join(path.dirname(__file__), r'.'))
__CONFIG_FILE = path.join(HOME_DIR, 'config.ini')
Parser = ConfigParser()
Parser.read(__CONFIG_FILE)
"""Section List"""
__SEC_DATASETS = "DataSets"
__SEC_VERSIONS = "Versions"
__SEC_INFO = "Info"
__SEC_STORE = "Store"
__SEC_TOPICS = "Topics"
__SEC_PHRASES = "Phrases"
__SEC_VALIDATE = "ValidateFiles"
__SEC_VAL = "Validate"
@classmethod
def get_section_list(cls):
return cls.Parser.sections()
@classmethod
def __get_attr(cls, attr_type, section, option):
"""
:param attr_type: can be int, float, str, bool
:param section:
:param option:
:return:
"""
result = None
try:
if attr_type is int:
result = cls.Parser.getint(section=section, option=option)
elif attr_type is float:
result = cls.Parser.getfloat(section=section, option=option)
elif attr_type is bool:
result = cls.Parser.getfloat(section=section, option=option)
elif attr_type is str:
result = cls.Parser.getfloat(section=section, option=option)
except configparser.NoOptionError:
pass
return result
@classmethod
def get_datasets(cls):
"""
:return: a list of tuples (app, path)
"""
return cls.Parser.items(cls.__SEC_DATASETS)
@classmethod
def get_version_digits(cls):
return cls.__get_attr(int, cls.__SEC_VERSIONS, "VersionDigits")
@classmethod
def get_info_num(cls):
return cls.__get_attr(int, cls.__SEC_INFO, "InfoNum")
@classmethod
def get_store_num(cls):
return cls.__get_attr(int, cls.__SEC_STORE, "StoreNum")
@classmethod
def get_topic_num(cls):
return cls.__get_attr(int, cls.__SEC_TOPICS, "TopicNum")
@classmethod
def get_candidate_num(cls):
return cls.__get_attr(int, cls.__SEC_TOPICS, "CandidateNum")
@classmethod
def get_window_size(cls):
return cls.__get_attr(int, cls.__SEC_TOPICS, "WindowSize")
@classmethod
def get_bigram_min(cls):
return cls.__get_attr(int, cls.__SEC_PHRASES, "Bigram_Min")
@classmethod
def get_trigram_min(cls):
return cls.__get_attr(int, cls.__SEC_PHRASES, "Trigram_Min")
@classmethod
def get_validate_files(cls):
"""
:return: dictionary of {apk: path_to_changelog}
"""
return cls.Parser._sections[cls.__SEC_VALIDATE]
@classmethod
def get_validate_or_not(cls):
return cls.__get_attr(int, cls.__SEC_VAL, "Validate")