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

create output dir if needed

上级 ab1051c3
......@@ -109,7 +109,7 @@ fields:
from: custom.ip.private.yaml # 引用data/custom/ip/private.yaml
use: all # 使用该文件中的所有实例。
prefix: "{"
postfix: "}"
postfix: "}\t"
- field: field_use_excel # 从excel数据源里面取数据。
from: system.address.v1.china # 从data/system/address/v1.xlsx文件中读取名为china的工作簿。
......
......@@ -20,12 +20,24 @@ fields:
prefix: "["
postfix: "]"
- field: field_loop_range
range: 1-3{3}
loop: 2-3
loopfix: "|"
prefix: "["
postfix: "]\t"
- field: field_nested_range
from: custom.test.number.v1.yaml
use: all
use: medium
prefix: "["
postfix: "]"
- field: field_nested_instant
from: custom.ip.private.yaml
use: all
prefix: "["
- field: field_nested_instant
from: custom.ip.private.yaml
use: all
......
>> 10
>> [10.2.2.3/'24'
\ No newline at end of file
#!/usr/bin/env php
<?php
/**
[case]
title=
cid=0
pid=0
[group]
>>
>>
[esac]
*/
include_once __DIR__ . DIRECTORY_SEPARATOR . '../lib/zd.php';
$zd = new zendata();
$output = $zd->create("", "test.yaml", 10, "", array("fields"=>"field_nested_instant"));
$count = sprintf("%d", count($output));
print(">> $count\n");
print(">> $output[2]\n");
\ No newline at end of file
>> 10
>> ['103']
\ No newline at end of file
#!/usr/bin/env php
<?php
/**
[case]
title=
cid=0
pid=0
[group]
>>
>>
[esac]
*/
include_once __DIR__ . DIRECTORY_SEPARATOR . '../lib/zd.php';
$zd = new zendata();
$output = $zd->create("", "test.yaml", 10, "", array("fields"=>"field_nested_range"));
$count = sprintf("%d", count($output));
print(">> $count\n");
print(">> $output[2]\n");
\ No newline at end of file
>> 10
>> part1_c|part2_C|part3_int_12
\ No newline at end of file
#!/usr/bin/env php
<?php
/**
[case]
title=
cid=0
pid=0
[group]
>>
>>
[esac]
*/
include_once __DIR__ . DIRECTORY_SEPARATOR . '../lib/zd.php';
$zd = new zendata();
$output = $zd->create("", "default.yaml", 10, "", array("fields"=>"field_with_children"));
$count = sprintf("%d", count($output));
print(">> $count\n");
print(">> $output[2]\n");
\ No newline at end of file
>> 3
>> int_1
\ No newline at end of file
>> 30
>> int_22
\ No newline at end of file
......@@ -16,8 +16,8 @@ pid=0
include_once __DIR__ . DIRECTORY_SEPARATOR . '../lib/zd.php';
$zd = new zendata();
$output = $zd->create("", "default.yaml", 3, "", array("fields"=>"field_common"));
$output = $zd->create("", "default.yaml", 30, "", array("fields"=>"field_common"));
$count = sprintf("%d", count($output));
print(">> $count\n");
print(">> $output[0]\n");
\ No newline at end of file
print(">> $output[12]\n");
\ No newline at end of file
>> 10
>> part1_c|part2_C|part3_int_12
\ No newline at end of file
#!/usr/bin/env php
<?php
/**
[case]
title=
cid=0
pid=0
[group]
>>
>>
[esac]
*/
include_once __DIR__ . DIRECTORY_SEPARATOR . '../lib/zd.php';
$zd = new zendata();
$output = $zd->create("default.yaml", "test.yaml", 10, "");
$count = sprintf("%d", count($output));
print(">> $count\n");
print(">> $output[2]\n");
\ No newline at end of file
>> 10
>> is in array
\ No newline at end of file
#!/usr/bin/env php
<?php
/**
[case]
title=
cid=0
pid=0
[group]
>>
>>
[esac]
*/
include_once __DIR__ . DIRECTORY_SEPARATOR . '../lib/zd.php';
$zd = new zendata();
$output = $zd->create("", "default.yaml", 10, "", array("fields"=>"field_file"));
$count = sprintf("%d", count($output));
print(">> $count\n");
$str = join($output, ",");
print("$str\n");
$array = array("aaron", "ben", "carl");
if (in_array($output[0], $array)) {
print(">> $output[0] is in array\n");
}
\ No newline at end of file
>> 10
>> passwd03
\ No newline at end of file
#!/usr/bin/env php
<?php
/**
[case]
title=
cid=0
pid=0
[group]
>>
>>
[esac]
*/
include_once __DIR__ . DIRECTORY_SEPARATOR . '../lib/zd.php';
$zd = new zendata();
$output = $zd->create("", "default.yaml", 10, "", array("fields"=>"field_format"));
$count = sprintf("%d", count($output));
print(">> $count\n");
print(">> $output[2]\n");
\ No newline at end of file
>> 10
>> g_h_i
\ No newline at end of file
#!/usr/bin/env php
<?php
/**
[case]
title=
cid=0
pid=0
[group]
>>
>>
[esac]
*/
include_once __DIR__ . DIRECTORY_SEPARATOR . '../lib/zd.php';
$zd = new zendata();
$output = $zd->create("", "default.yaml", 10, "", array("fields"=>"field_loop"));
$count = sprintf("%d", count($output));
print(">> $count\n");
print(">> $output[2]\n");
\ No newline at end of file
>> 10
>> [2|3]
\ No newline at end of file
#!/usr/bin/env php
<?php
/**
[case]
title=
cid=0
pid=0
[group]
>>
>>
[esac]
*/
include_once __DIR__ . DIRECTORY_SEPARATOR . '../lib/zd.php';
$zd = new zendata();
$output = $zd->create("", "test.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
>> 10
>> [10.2.2.3/'24'}
\ No newline at end of file
#!/usr/bin/env php
<?php
/**
[case]
title=
cid=0
pid=0
[group]
>>
>>
[esac]
*/
include_once __DIR__ . DIRECTORY_SEPARATOR . '../lib/zd.php';
$zd = new zendata();
$output = $zd->create("default.yaml", "test.yaml", 10, "", array("fields"=>"field_nested_instant"));
$count = sprintf("%d", count($output));
print(">> $count\n");
print(">> $output[2]\n");
\ No newline at end of file
>> 10
>> not 1,2,3
\ No newline at end of file
#!/usr/bin/env php
<?php
/**
[case]
title=
cid=0
pid=0
[group]
>>
>>
[esac]
*/
include_once __DIR__ . DIRECTORY_SEPARATOR . '../lib/zd.php';
$zd = new zendata();
$output = $zd->create("", "default.yaml", 10, "", array("fields"=>"field_random"));
$count = sprintf("%d", count($output));
print(">> $count\n");
$str = join($output, ",");
print("$str\n");
if ($output[0] != 1 || $output[1] != 2 || $output[2] != 3) {
print(">> not 1,2,3\n");
}
\ No newline at end of file
>> 10
>> user2
\ No newline at end of file
#!/usr/bin/env php
<?php
/**
[case]
title=
cid=0
pid=0
[group]
>>
>>
[esac]
*/
include_once __DIR__ . DIRECTORY_SEPARATOR . '../lib/zd.php';
$zd = new zendata();
$output = $zd->create("", "default.yaml", 10, "", array("fields"=>"field_repeat"));
$count = sprintf("%d", count($output));
print(">> $count\n");
print(">> $output[3]\n");
\ No newline at end of file
>> 10
>> 5
\ No newline at end of file
#!/usr/bin/env php
<?php
/**
[case]
title=
cid=0
pid=0
[group]
>>
>>
[esac]
*/
include_once __DIR__ . DIRECTORY_SEPARATOR . '../lib/zd.php';
$zd = new zendata();
$output = $zd->create("", "default.yaml", 10, "", array("fields"=>"field_step"));
$count = sprintf("%d", count($output));
print(">> $count\n");
print(">> $output[2]\n");
\ No newline at end of file
>> 10
>> '104,105'
\ No newline at end of file
#!/usr/bin/env php
<?php
/**
[case]
title=
cid=0
pid=0
[group]
>>
>>
[esac]
*/
include_once __DIR__ . DIRECTORY_SEPARATOR . '../lib/zd.php';
$zd = new zendata();
$output = $zd->create("", "default.yaml", 10, "", array("fields"=>"field_use_another_file"));
$count = sprintf("%d", count($output));
print(">> $count\n");
print(">> $output[2]\n");
\ No newline at end of file
>> 10
>> 淄博市
\ No newline at end of file
#!/usr/bin/env php
<?php
/**
[case]
title=
cid=0
pid=0
[group]
>>
>>
[esac]
*/
include_once __DIR__ . DIRECTORY_SEPARATOR . '../lib/zd.php';
$zd = new zendata();
$output = $zd->create("", "default.yaml", 10, "", array("fields"=>"field_use_excel"));
$count = sprintf("%d", count($output));
print(">> $count\n");
print(">> $output[2]\n");
\ No newline at end of file
>> 10
>> 192.168.2.3
\ No newline at end of file
#!/usr/bin/env php
<?php
/**
[case]
title=
cid=0
pid=0
[group]
>>
>>
[esac]
*/
include_once __DIR__ . DIRECTORY_SEPARATOR . '../lib/zd.php';
$zd = new zendata();
$output = $zd->create("", "default.yaml", 10, "", array("fields"=>"field_use_instance"));
$count = sprintf("%d", count($output));
print(">> $count\n");
print(">> $output[2]\n");
\ No newline at end of file
>> 10
>> '103'
\ No newline at end of file
#!/usr/bin/env php
<?php
/**
[case]
title=
cid=0
pid=0
[group]
>>
>>
[esac]
*/
include_once __DIR__ . DIRECTORY_SEPARATOR . '../lib/zd.php';
$zd = new zendata();
$output = $zd->create("", "default.yaml", 10, "", array("fields"=>"field_use_ranges"));
$count = sprintf("%d", count($output));
print(">> $count\n");
print(">> $output[2]\n");
\ No newline at end of file
>> 3
>> int_1
\ No newline at end of file
>> found part1_a
>> found part3_int_10
\ No newline at end of file
......@@ -20,6 +20,11 @@ $output = $zd->create("", "test2.yaml", 3, "output/test2.txt");
$zd->decode("test2.yaml", "output/test2.txt", "output/test2.json");
$lineArr = $zd->readOutput("output/zt_action.yaml", array(6));
$lines = join("\n", $lineArr);
print(">> $lines\n");
\ No newline at end of file
$arr = $zd->readOutput("output/test2.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");
}
......@@ -19,12 +19,25 @@ class zendata
{
$cmdStr = sprintf("%s -c %s/%s -n %d",
$this->cmdPath, $this->workDir, $conf, $lines);
if (count($options) > 0 && $options["fields"]) {
if ($default) {
$cmdStr = str_replace(" -c ", " -d " . $this->workDir . "/" . $default . " -c ", $cmdStr);
}
if (array_key_exists("fields", $options)) {
$cmdStr .= " -F " . $options["fields"];
}
if (array_key_exists("table", $options)) {
$cmdStr .= " -table " . $options["table"];
}
if (array_key_exists("trim", $options)) {
$cmdStr .= " -T ";
}
if ($output) {
$cmdStr .= " -o " . $this->workDir . "/" . $output;
}
print("$cmdStr\n");
$output = [];
......@@ -48,12 +61,19 @@ class zendata
print("$filePath\n");
$content = file_get_contents($filePath);
$arr = explode("\n", $content);
if (count($lines) == 0) {
return $content;
$ret = array();
foreach ($arr as $item) {
$item = trim($item);
if ($item) {
array_push($ret, $item);
}
}
return $ret;
}
$ret = array();
$arr = explode("\n", $content);
foreach ($lines as $num) {
array_push($ret, $arr[$num - 1]);
}
......@@ -63,7 +83,7 @@ class zendata
public function decode($config, $input, $out)
{
$cmdStr = sprintf("-D -c %s/%s -i %s/%s -o %s/%s",
$cmdStr = sprintf("%s -D -c %s/%s -i %s/%s -o %s/%s",
$this->cmdPath, $this->workDir, $config, $this->workDir, $input, $this->workDir, $out);
print("$cmdStr\n");
......
>> {"field_common":"int_2\t"},
\ No newline at end of file
#!/usr/bin/env php
<?php
/**
[case]
title=
cid=0
pid=0
[group]
>>
>>
[esac]
*/
include_once __DIR__ . DIRECTORY_SEPARATOR . '../lib/zd.php';
$zd = new zendata();
$output = $zd->create("", "default.yaml", 10, "output/default.json", array("fields"=>"field_common"));
$lineArr = $zd->readOutput("output/default.json");
print(">> $lineArr[2]\n");
\ No newline at end of file
>> ('1|2|2')
\ No newline at end of file
#!/usr/bin/env php
<?php
/**
[case]
title=
cid=0
pid=0
[group]
>>
>>
[esac]
*/
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"));
$lineArr = $zd->readOutput("output/test2.sql");
print(">> $lineArr[2]\n");
\ No newline at end of file
>> 10
>> int_3
\ No newline at end of file
#!/usr/bin/env php
<?php
/**
[case]
title=
cid=0
pid=0
[group]
>>
>>
[esac]
*/
include_once __DIR__ . DIRECTORY_SEPARATOR . '../lib/zd.php';
$zd = new zendata();
$output = $zd->create("", "default.yaml", 10, "output/default.txt", array("fields"=>"field_common"));
$lineArr = $zd->readOutput("output/default.txt");
$count = sprintf("%d", count($lineArr));
print(">> $count\n");
print(">> $lineArr[2]\n");
\ No newline at end of file
>> <row><col>int_1&#x9;</col></row>
\ No newline at end of file
#!/usr/bin/env php
<?php
/**
[case]
title=
cid=0
pid=0
[group]
>>
>>
[esac]
*/
include_once __DIR__ . DIRECTORY_SEPARATOR . '../lib/zd.php';
$zd = new zendata();
$output = $zd->create("", "default.yaml", 10, "output/default.xml", array("fields"=>"field_common"));
$lineArr = $zd->readOutput("output/default.xml");
print(">> $lineArr[3]\n");
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册