提交 860494a3 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

close task #7508

上级 dc113f05
......@@ -8,3 +8,4 @@
/data/.cache/.data.db-wal
/demo/out/
/test/output/
/data/_test/
title: 私有IP
desc:
author: zentao
version: 1.0
field: privateIP
instances:
- instance: all
fields:
- field: part
from: system.ip.v1.yaml
use: privateA, privateB, privateC
prefix: ""
postfix: "/24"
title: IP地址
desc: 含有多种实现的示例。
author: wwccss
version: 1.0
field: ip
instances:
- instance: privateC
note: C类IP地址
prefix: 192.168.
fields:
- field: part3
range: 0-254
postfix: .
- field: part4
range: 1-254
- instance: privateB
note: B类IP地址
prefix: 172.
fields:
- field: part2
range: 16-31
postfix: .
- field: part3
range: 0-254
postfix: .
- field: part4
range: 1-254
- instance: privateA
note: A类IP地址
prefix: 10.
fields:
- field: part2
range: 0-254
postfix: .
- field: part3
range: 0-254
postfix: .
- field: part4
range: 1-254
\ No newline at end of file
title: IP地址
desc: 含有多种实现的示例。
author: wwccss
version: 1.0
field: ip
instances:
- instance: privateC
note: C类IP地址
prefix: 192.168.
fields:
- field: part3
range: 0-254
postfix: .
- field: part4
range: 1-254
- instance: privateB
note: B类IP地址
prefix: 172.
fields:
- field: part2
range: 16-31
postfix: .
- field: part3
range: 0-254
postfix: .
- field: part4
range: 1-254
- instance: privateA
note: A类IP地址
prefix: 10.
fields:
- field: part2
range: 0-254
postfix: .
- field: part3
range: 0-254
postfix: .
- field: part4
range: 1-254
\ No newline at end of file
title: IP地址
desc: 含有多种实现的示例。
author: wwccss
version: 1.0
field: ip
instances:
- instance: privateC
note: C类IP地址
prefix: 192.168.
fields:
- field: part3
range: 0-254
postfix: .
- field: part4
range: 1-254
- instance: privateB
note: B类IP地址
prefix: 172.
fields:
- field: part2
range: 16-31
postfix: .
- field: part3
range: 0-254
postfix: .
- field: part4
range: 1-254
- instance: privateA
note: A类IP地址
prefix: 10.
fields:
- field: part2
range: 0-254
postfix: .
- field: part3
range: 0-254
postfix: .
- field: part4
range: 1-254
\ No newline at end of file
title: number
desc: 数字分组
author: wwccss
version: 1.0
field: number
note: 数值类型数据
prefix: "'"
postfix: "'"
loop: 2
loopfix: ","
ranges:
small: 1-9
medium: 11-99
large: 10001-99999
......@@ -20,8 +20,14 @@ fields:
prefix: "[" # 复写前缀
postfix: "]" # 特殊字符加引号,否则无法解析
- field: field_nested_inst # 引用的instance使用多层嵌套的use定义
from: system.ip.private.yaml # 引用data/system/ip/v1.yaml
- field: field_nested_range # 引用的range使用多层嵌套的use定义
from: system.misc.number.yaml # 引用data/system/misc/number.yaml
use: all # 使用该文件中定义的privateC和privateB两个实例。
prefix: "[" # 复写前缀
postfix: "]" # 特殊字符加引号,否则无法解析
\ No newline at end of file
postfix: "]" # 特殊字符加引号,否则无法解析
- field: field_nested_refer # 引用的instance使用多层嵌套的use定义
from: _test.ip.private.yaml
use: all
prefix: "["
postfix: "]"
\ No newline at end of file
......@@ -71,12 +71,9 @@ func getResProp(from string) (string, string) { // from resource
resPath := resFile
if !filepath.IsAbs(resPath) {
resPath = vari.ConfigDir + resFile
resPath = vari.ExeDir + constant.ResDir + resFile // used res should be in data folder
if !fileUtils.FileExist(resPath) {
resPath = vari.DefaultDir + resFile
if !fileUtils.FileExist(resPath) {
resPath = ""
}
resPath = ""
}
} else {
if !fileUtils.FileExist(resPath) {
......@@ -148,16 +145,22 @@ func getResForInstances(insts model.ResInsts) map[string][]string {
for _, inst := range insts.Instances {
for _, instField := range inst.Fields { // prepare referred parent instances if needed
if instField.Use != "" { // refer to another instance
parent := getRootInstant(instField)
if instField.Use != "" { // refer to another def
parentRanges, parentInstants := getRootRangeOrInstant(instField)
groupedValueParent := map[string][]string{}
for _, child := range parent.Instances {
field := convertInstantToField(parent, child)
// gen values
group := child.Instance
groupedValueParent[group] = GenerateForField(&field, constant.Total, false)
if len(parentInstants.Instances) > 0 {
for _, child := range parentInstants.Instances {
field := convertInstantToField(parentInstants, child)
// gen values
group := child.Instance
groupedValueParent[group] = GenerateForField(&field, constant.Total, false)
}
} else if len(parentRanges.Ranges) > 0 {
groupedValueParent = getResForRanges(parentRanges)
}
vari.Res[instField.From] = groupedValueParent
}
}
......@@ -172,7 +175,7 @@ func getResForInstances(insts model.ResInsts) map[string][]string {
return groupedValue
}
func getRootInstant(inst model.DefField) (parentInsts model.ResInsts) {
func getRootRangeOrInstant(inst model.DefField) (parentRanges model.ResRanges, parentInsts model.ResInsts) {
resFile, _ := getResProp(inst.From)
yamlContent, err := ioutil.ReadFile(resFile)
......@@ -181,9 +184,14 @@ func getRootInstant(inst model.DefField) (parentInsts model.ResInsts) {
return
}
err = yaml.Unmarshal(yamlContent, &parentInsts)
if err == nil && parentInsts.Instances != nil && len(parentInsts.Instances) > 0 { // instances
logUtils.Screen(i118Utils.I118Prt.Sprintf("fail_to_parse_file", resFile))
err1 := yaml.Unmarshal(yamlContent, &parentRanges)
if err1 != nil || parentInsts.Instances == nil || len(parentInsts.Instances) == 0 { // instances
err2 := yaml.Unmarshal(yamlContent, &parentInsts)
if err2 != nil || parentRanges.Ranges == nil || len(parentRanges.Ranges) == 0 { // ranges
logUtils.Screen(i118Utils.I118Prt.Sprintf("fail_to_parse_file", resFile))
return
}
}
return
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册