forked from Tribler/tribler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit_category.py
59 lines (47 loc) · 1.36 KB
/
init_category.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
# Written by Yuan Yuan
# see LICENSE.txt for license information
# give the initial category information
import ConfigParser
def __split_list(string):
the_list = []
for word in string.split(","):
word = word.strip()
the_list.append(word)
return the_list
INIT_FUNC_DICT = {
"minfilenumber": int,
"maxfilenumber": int,
"minfilesize": int,
"maxfilesize": int,
"suffix": __split_list,
"matchpercentage": float,
"keywords": float,
"strength": float,
"displayname": str,
"rank": int
}
def __get_default():
category = {}
category["name"] = ""
category["keywords"] = {}
category["suffix"] = []
category["minfilesize"] = 0
category["maxfilesize"] = -1
return category
def getCategoryInfo(filename):
config = ConfigParser.ConfigParser()
config.readfp(open(filename))
cate_list = []
sections = config.sections()
for isection in sections:
category = __get_default()
category["name"] = isection
for (name, value) in config.items(isection):
if name[0] != "*":
category[name] = INIT_FUNC_DICT[name](value)
else:
name = name[1:]
name = name.strip()
category["keywords"][name] = INIT_FUNC_DICT["keywords"](value)
cate_list.append(category)
return cate_list