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

create output dir if needed

上级 c716fe34
......@@ -19,6 +19,7 @@ import (
"os"
"os/signal"
"path"
"path/filepath"
"strconv"
"strings"
"syscall"
......@@ -187,6 +188,7 @@ func toGen() {
}
if output != "" {
fileUtils.MkDirIfNeeded(filepath.Dir(output))
fileUtils.RemoveExist(output)
action.FileWriter, _ = os.OpenFile(output, os.O_RDWR | os.O_CREATE, 0777)
defer action.FileWriter.Close()
......
......@@ -13,7 +13,7 @@ pid=0
[esac]
*/
include_once __DIR__ . DIRECTORY_SEPARATOR . '../common/zd.php';
include_once __DIR__ . DIRECTORY_SEPARATOR . '../lib/zd.php';
$zd = new zendata();
$output = $zd->create("", "default.yaml", 3, "", array("fields"=>"field_common"));
......
>> 3
>> int_1
\ 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", 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
......@@ -13,7 +13,7 @@ pid=0
[esac]
*/
include_once __DIR__ . DIRECTORY_SEPARATOR . '../common/zd.php';
include_once __DIR__ . DIRECTORY_SEPARATOR . '../lib/zd.php';
$zd = new zendata();
......
......@@ -15,7 +15,7 @@ pid=0
[esac]
*/
include_once __DIR__ . DIRECTORY_SEPARATOR . '../common/zd.php';
include_once __DIR__ . DIRECTORY_SEPARATOR . '../lib/zd.php';
$zd = new zendata();
......
......@@ -14,7 +14,7 @@ pid=0
[esac]
*/
include_once __DIR__ . DIRECTORY_SEPARATOR . '../common/zd.php';
include_once __DIR__ . DIRECTORY_SEPARATOR . '../lib/zd.php';
$zd = new zendata();
......
>> - field: id
\ 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->convertSql("zentao.sql", "output");
$lineArr = $zd->readOutput("output/zt_action.yaml", array(6));
$lines = join("\n", $lineArr);
print(">> $lines\n");
\ No newline at end of file
......@@ -14,7 +14,7 @@ pid=0
[esac]
*/
include_once __DIR__ . DIRECTORY_SEPARATOR . '../common/zd.php';
include_once __DIR__ . DIRECTORY_SEPARATOR . '../lib/zd.php';
$zd = new zendata();
......
......@@ -13,7 +13,7 @@ pid=0
[esac]
*/
include_once __DIR__ . DIRECTORY_SEPARATOR . '../common/zd.php';
include_once __DIR__ . DIRECTORY_SEPARATOR . '../lib/zd.php';
$zd = new zendata();
......
......@@ -17,8 +17,14 @@ class zendata
public function create($default, $conf, $lines, $output, $options = array())
{
$cmdStr = sprintf("%s -c %s/%s -n %d -F %s",
$this->cmdPath, $this->workDir, $conf, $lines, $options["fields"]);
$cmdStr = sprintf("%s -c %s/%s -n %d",
$this->cmdPath, $this->workDir, $conf, $lines);
if (count($options) > 0 && $options["fields"]) {
$cmdStr .= " -F " . $options["fields"];
}
if ($output) {
$cmdStr .= " -o " . $this->workDir . "/" . $output;
}
print("$cmdStr\n");
$output = [];
......@@ -26,8 +32,42 @@ class zendata
return $output;
}
public function parse($config, $input)
public function convertSql($file, $dir, $options = array())
{
$cmdStr = sprintf("%s -i %s/%s -o %s/%s", $this->cmdPath, $this->workDir, $file, $this->workDir, $dir);
print("$cmdStr\n");
$output = [];
exec($cmdStr, $output);
return $output;
}
public function readOutput($file, $lines=array())
{
$filePath = sprintf("%s/%s", $this->workDir, $file);
print("$filePath\n");
$content = file_get_contents($filePath);
if (count($lines) == 0) {
return $content;
}
$ret = array();
$arr = explode("\n", $content);
foreach ($lines as $num) {
array_push($ret, $arr[$num - 1]);
}
return $ret;
}
public function decode($config, $input, $out)
{
$cmdStr = sprintf("-D -c %s/%s -i %s/%s -o %s/%s",
$this->cmdPath, $this->workDir, $config, $this->workDir, $input, $this->workDir, $out);
print("$cmdStr\n");
exec($cmdStr, $output);
}
public function cmd($params)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册