Merge "Change PTL informatin in INFO"
[bottlenecks.git] / testsuites / vstf / vstf_scripts / vstf / common / candy_text.py
1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd 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
10
11 import sys
12
13 THIS = sys.modules[__name__]
14 __id_max = 100
15 __style_max = 10
16 dom = {"chapter", "section", "unit"}
17 element = {"title", "table", "figure", "paragraph", "plot", "chart", "space"}
18
19 nodes = dom | element
20 for _node in nodes:
21     setattr(THIS, _node, _node)
22
23
24 def tuple2text(sn, node, style):
25     assert sn in range(__id_max)
26     assert style in range(__style_max)
27     assert node in nodes
28     return "%02d##%s#%d" % (sn, node, style)
29
30
31 def dict2text(info):
32     assert "sn" in info and info["sn"] in range(__id_max)
33     assert "style" in info and info["style"] in range(__style_max)
34     assert "node" in info and info["node"] in nodes
35     return "%02d##%s#%d" % (info["sn"], info["node"], info["style"])
36
37
38 def text2dict(candy):
39     tmp = candy.replace("##", "#").split("#")
40     result = {
41         "sn": int(tmp[0]),
42         "node": tmp[1],
43         "style": int(tmp[2])
44     }
45     assert result["sn"] in range(__id_max)
46     assert result["style"] in range(__style_max)
47     assert result["node"] in nodes
48     return result
49
50
51 def text2tuple(candy):
52     tmp = candy.replace("##", "#").split("#")
53
54     sn = int(tmp[0])
55     node = tmp[1]
56     style = int(tmp[2])
57
58     assert sn in range(__id_max)
59     assert style in range(__style_max)
60     assert node in nodes
61     return sn, node, style