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

update ztf scripts

上级 ad80ff97
步长负数
loop区间
instance嵌套
title: ZenData数据配置高级特性
desc:
author: zentao
version: 1.0
fields:
- field: field_step_negative # 区间可以指定步长。
range: z-a:-2 # 9,7,5,4...
prefix: "["
postfix: "]\t"
- field: field_loop_range # 自循环支持区间。
range: 1-3{3}
loop: 2-5
loopfix: "|"
prefix: "["
postfix: "]\t"
- field: field_nested_range
from: custom.test.number.v1.yaml # 自定义通用ranges,保存于data目录下。
use: medium
prefix: "["
postfix: "]\t"
- field: field_nested_instant
from: custom.ip.private.yaml # 內置instances引用其他ranges或instances。
use: all
prefix: "["
postfix: "]\t"
\ No newline at end of file
......@@ -108,7 +108,7 @@ fields:
- field: field_use_instance # 引用其他的定义文件,该文件定义了多个实例。
from: system.ip.v1.yaml # 引用data/system/ip/v1.yaml
use: privateC,privateC # 使用该文件中定义的privateC和privateB两个实例。
use: privateC,privateB # 使用该文件中定义的privateC和privateB两个实例。
postfix: "\t"
- field: field_nested_instant # 引用其他的定义文件,且该文件引用了其他实例。
......@@ -120,7 +120,7 @@ fields:
- field: field_use_excel # 从excel数据源里面取数据。
from: system.address.v1.china # 从data/system/address/v1.xlsx文件中读取名为china的工作簿。
select: city # 查询city字段。
where: state like '%山东%' # 条件是省份包含山东。
where: state like '%山东%' # 条件是省份包含山东。
postfix: "\t"
- field: field_with_children # 嵌套字段
......
......@@ -10,7 +10,7 @@ fields:
- field: field_use_excel
prefix: " ["
postfix: "]==== "
postfix: "]"
- field: field_with_children
prefix: " ["
......
此差异已折叠。
......@@ -8,7 +8,6 @@ import (
i118Utils "github.com/easysoft/zendata/src/utils/i118"
logUtils "github.com/easysoft/zendata/src/utils/log"
"github.com/easysoft/zendata/src/utils/vari"
"log"
"strings"
)
......@@ -85,7 +84,6 @@ func decodeOneLevel(line string, fields []model.DefField, rowMap *map[string]int
if index > -1 {
col = string(left[: index + len(field.Postfix)])
left = left[index + len(field.Postfix):]
log.Println(left)
}
} else if j == len(fields) - 1 {
col = string(left)
......
......@@ -22,7 +22,7 @@ func LoadConfigDef(defaultFile, configFile string, fieldsToExport *[]string) mod
if defaultFile != "" {
pathDefaultFile := defaultFile
if !fileUtils.IsAbosutePath(pathDefaultFile) {
pathDefaultFile = vari.ExeDir + pathDefaultFile
pathDefaultFile = vari.WorkDir + pathDefaultFile
}
defaultContent, err := ioutil.ReadFile(pathDefaultFile)
......@@ -41,7 +41,7 @@ func LoadConfigDef(defaultFile, configFile string, fieldsToExport *[]string) mod
// load configDef
pathConfigFile := configFile
if !fileUtils.IsAbosutePath(pathConfigFile) {
pathConfigFile = vari.ExeDir + pathConfigFile
pathConfigFile = vari.WorkDir + pathConfigFile
}
yamlContent, err := ioutil.ReadFile(pathConfigFile)
......
......@@ -63,7 +63,7 @@ func getResProp(from string) (string, string) { // from resource
}
if strings.Index(resFile, "system") > -1 { // system resource
resFile = vari.ExeDir + constant.ResDir + resFile
resFile = vari.WorkDir + constant.ResDir + resFile
} else {
resPath := resFile
if !filepath.IsAbs(resPath) {
......@@ -71,7 +71,7 @@ func getResProp(from string) (string, string) { // from resource
resPath = vari.ConfigDir + resFile
if !fileUtils.FileExist(resPath) { // in same folder with passed config file
resPath = vari.ExeDir + constant.ResDir + resFile
resPath = vari.WorkDir + constant.ResDir + resFile
if !fileUtils.FileExist(resPath) { // in res file
resPath = ""
}
......
......@@ -82,7 +82,7 @@ func findFilePath(file string) string {
resPath = vari.DefaultDir + file
if !fileUtils.FileExist(resPath) {
resPath = vari.ExeDir + constant.ResDir + file
resPath = vari.WorkDir + constant.ResDir + file
if !fileUtils.FileExist(resPath) {
resPath = ""
}
......
......@@ -22,7 +22,7 @@ const (
func ListRes() {
orderedKeys := [2]string{"yaml", "excel"}
res := map[string][][size]string{}
path := vari.ExeDir + "data"
path := vari.WorkDir + "data"
GetFilesAndDirs(path, &res)
names := make([]string, 0)
......
......@@ -34,11 +34,11 @@ func ParseRequestParams(req *http.Request) (defaultFile, configFile, fields stri
configDefContent := req.FormValue("config")
if defaultDefContent != "" {
defaultFile = vari.ExeDir + "._default.yaml"
defaultFile = vari.WorkDir + "._default.yaml"
fileUtils.WriteFile(defaultFile, defaultDefContent)
}
if configDefContent != "" {
configFile = vari.ExeDir + "._config.yaml"
configFile = vari.WorkDir + "._config.yaml"
fileUtils.WriteFile(configFile, configDefContent)
}
}
......
......@@ -19,6 +19,8 @@ import (
func InitConfig() {
vari.ExeDir = fileUtils.GetExeDir()
vari.WorkDir = fileUtils.GetWorkDir()
CheckConfigPermission()
constant.ConfigFile = vari.ExeDir + constant.ConfigFile
......
......@@ -132,10 +132,20 @@ func GetExeDir() string { // where zd.exe file in
return dir
}
func GetWorkDir() string { // where we run file in
dir, _ := os.Getwd()
dir, _ = filepath.Abs(dir)
dir = AddSepIfNeeded(dir)
//fmt.Printf("Debug: Launch %s in %s \n", arg1, dir)
return dir
}
func GetAbsDir(path string) string {
abs := ""
if !IsAbosutePath(path) {
path = vari.ExeDir + path
path = vari.WorkDir + path
}
abs, _ = filepath.Abs(filepath.Dir(path))
......@@ -169,7 +179,7 @@ func ConvertResPath(path string) (resType, resFile, sheet string) {
}
func AddRootPath(path string) string {
path = vari.ExeDir + "data" + constant.PthSep + path
path = vari.WorkDir + "data" + constant.PthSep + path
return path
}
......@@ -11,6 +11,7 @@ var (
RunMode constant.RunMode
ExeDir string
WorkDir string
LogDir string
ScreenWidth int
......
......@@ -168,13 +168,13 @@ func toGen() {
if vari.RunMode == constant.RunModeServer {
if root != "" {
if fileUtils.IsAbosutePath(root) {
vari.ExeDir = root
vari.WorkDir = root
} else {
vari.ExeDir = vari.ExeDir + root
vari.WorkDir = vari.WorkDir + root
}
vari.ExeDir = fileUtils.AddSepIfNeeded(vari.ExeDir)
vari.WorkDir = fileUtils.AddSepIfNeeded(vari.WorkDir)
}
constant.SqliteSource = strings.Replace(constant.SqliteSource, "file:", "file:" + vari.ExeDir, 1)
constant.SqliteSource = strings.Replace(constant.SqliteSource, "file:", "file:" + vari.WorkDir, 1)
StartServer()
} else if vari.RunMode == constant.RunModeServerRequest {
......
>> found part1_a
>> found part3_int_10
\ No newline at end of file
>> ('1|2|2')
\ No newline at end of file
>> <row><col>int_1&#x9;</col></row>
\ No newline at end of file
......@@ -16,7 +16,7 @@ pid=7
include_once __DIR__ . DIRECTORY_SEPARATOR . '../lib/zd.php';
$zd = new zendata();
$output = $zd->create("", "test.yaml", 10, "", array("fields"=>"field_nested_instant"));
$output = $zd->create("", "advanced.yaml", 10, "", array("fields"=>"field_nested_instant"));
$count = sprintf("%d", count($output));
print(">> $count\n");
......
......@@ -16,7 +16,7 @@ pid=7
include_once __DIR__ . DIRECTORY_SEPARATOR . '../lib/zd.php';
$zd = new zendata();
$output = $zd->create("", "test.yaml", 10, "", array("fields"=>"field_nested_range"));
$output = $zd->create("", "advanced.yaml", 10, "", array("fields"=>"field_nested_range"));
$count = sprintf("%d", count($output));
print(">> $count\n");
......
......@@ -7,8 +7,8 @@ cid=1374
pid=7
[group]
显示10行生成的数据 >>
验证第3行数据 >>
显示10行生成的数据 >>
验证第3行数据重复了4次 >>
[esac]
*/
......@@ -16,9 +16,11 @@ pid=7
include_once __DIR__ . DIRECTORY_SEPARATOR . '../lib/zd.php';
$zd = new zendata();
$output = $zd->create("", "test.yaml", 10, "", array("fields"=>"field_loop_range"));
$output = $zd->create("", "advanced.yaml", 10, "", array("fields"=>"field_loop_range"));
$count = sprintf("%d", count($output));
print(">> $count\n");
print(">> $output[2]\n");
\ No newline at end of file
$arr = explode("|", $output[2]);
$count = sprintf("%d", count($arr));
print(">> $count\n");
\ No newline at end of file
>> 10
>> [v]
\ No newline at end of file
#!/usr/bin/env php
<?php
/**
[case]
title=指定步长
cid=1340
pid=7
[group]
显示10行生成的数据 >>
验证第3行数据 >>
[esac]
*/
include_once __DIR__ . DIRECTORY_SEPARATOR . '../lib/zd.php';
$zd = new zendata();
$output = $zd->create("", "advanced.yaml", 10, "", array("fields"=>"field_step_negative"));
$count = sprintf("%d", count($output));
print(">> $count\n");
print(">> $output[2]\n");
\ No newline at end of file
>> found [1|1]
>> found [10.0.0.1/'8']
\ No newline at end of file
......@@ -16,15 +16,15 @@ pid=7
include_once __DIR__ . DIRECTORY_SEPARATOR . '../lib/zd.php';
$zd = new zendata();
$output = $zd->create("", "test2.yaml", 3, "output/test2.txt");
$output = $zd->create("", "advanced.yaml", 3, "output/advanced.txt");
$zd->decode("test2.yaml", "output/test2.txt", "output/test2.json");
$zd->decode("advanced.yaml", "output/advanced.txt", "output/advanced.json");
$arr = $zd->readOutput("output/test2.json");
$arr = $zd->readOutput("output/advanced.json");
$content = join($arr, "");
if (strpos($content, 'part1_a') > 0) {
print(">> found part1_a\n");
}
if (strpos($content, 'part3_int_10') > 0) {
print(">> found part3_int_10\n");
if (strpos($content, "[1|1]") > 0) {
print(">> found [1|1]\n");
}
if (strpos($content, "[10.0.0.1/'8']") > 0) {
print(">> found [10.0.0.1/'8']\n");
}
\ No newline at end of file
......@@ -174,7 +174,7 @@ class zendata
{
$filename = '';
$filename = sprintf("conf/zdata.conf");
$filename = sprintf("%s/conf/zdata.conf", dirname($this->cmdPath));
$content = file_get_contents($filename);
$fp = fopen($filename, "w");
......
>> ('2')
\ No newline at end of file
......@@ -15,9 +15,9 @@ pid=7
include_once __DIR__ . DIRECTORY_SEPARATOR . '../lib/zd.php';
$zd = new zendata();
$output = $zd->create("", "test2.yaml", 10, "output/test2.sql",
array("fields"=>"test0", "table"=>"tlb_table", "trim"=>"true"));
$output = $zd->create("", "default.yaml", 10, "output/default.sql",
array("fields"=>"field_common", "table"=>"tlb_table", "trim"=>"true"));
$lineArr = $zd->readOutput("output/test2.sql");
$lineArr = $zd->readOutput("output/field_common.sql");
print(">> $lineArr[2]\n");
\ No newline at end of file
>> <field_common>int_1 </field_common>
\ No newline at end of file
......@@ -19,4 +19,4 @@ $output = $zd->create("", "default.yaml", 10, "output/default.xml", array("field
$lineArr = $zd->readOutput("output/default.xml");
print(">> $lineArr[3]\n");
\ No newline at end of file
print(">> $lineArr[4]\n");
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册