[Swift-commit] r7754 - in trunk: libexec src/org/griphyn/vdl/engine src/org/griphyn/vdl/karajan/lib/swiftscript
yadunandb at ci.uchicago.edu
yadunandb at ci.uchicago.edu
Thu Apr 3 16:32:19 CDT 2014
Author: yadunandb
Date: 2014-04-03 16:32:18 -0500 (Thu, 03 Apr 2014)
New Revision: 7754
Modified:
trunk/libexec/swift-lib.k
trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java
trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java
Log:
Committing changes for system built-in command.
Allows for easy specification of files to mappers using common unix commands.
Tested with "ls" and "find <dir> -type f"
Tests in next commit
Modified: trunk/libexec/swift-lib.k
===================================================================
--- trunk/libexec/swift-lib.k 2014-04-02 22:04:22 UTC (rev 7753)
+++ trunk/libexec/swift-lib.k 2014-04-03 21:32:18 UTC (rev 7754)
@@ -9,6 +9,7 @@
export(strcut, def("org.griphyn.vdl.karajan.lib.swiftscript.Misc$StrCut"))
export(strstr, def("org.griphyn.vdl.karajan.lib.swiftscript.Misc$StrStr"))
export(strsplit, def("org.griphyn.vdl.karajan.lib.swiftscript.Misc$StrSplit"))
+ export(system, def("org.griphyn.vdl.karajan.lib.swiftscript.Misc$ExecSystem"))
export(strjoin, def("org.griphyn.vdl.karajan.lib.swiftscript.Misc$StrJoin"))
export(regexp, def("org.griphyn.vdl.karajan.lib.swiftscript.Misc$Regexp"))
export(toInt, def("org.griphyn.vdl.karajan.lib.swiftscript.Misc$ToInt"))
@@ -21,7 +22,7 @@
export(trace, def("org.griphyn.vdl.karajan.lib.swiftscript.Misc$Trace"))
export(tracef, def("org.griphyn.vdl.karajan.lib.swiftscript.Tracef"))
export(fprintf, def("org.griphyn.vdl.karajan.lib.swiftscript.Fprintf"))
-
+
/* included for backwards compatibility */
export(readdata, def("org.griphyn.vdl.karajan.lib.swiftscript.ReadData"))
export(readdata2, def("org.griphyn.vdl.karajan.lib.swiftscript.ReadStructured"))
Modified: trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java
===================================================================
--- trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java 2014-04-02 22:04:22 UTC (rev 7753)
+++ trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java 2014-04-03 21:32:18 UTC (rev 7754)
@@ -197,6 +197,7 @@
add(functionsMap, "strcut", returns(STRING), args(STRING, STRING));
add(functionsMap, "strstr", returns(INT), args(STRING, STRING));
add(functionsMap, "strsplit", returns(STRING_ARRAY), args(STRING, STRING));
+ add(functionsMap, "system", returns(STRING_ARRAY), args(STRING));
add(functionsMap, "strjoin", returns(STRING), args(ANY, STRING));
add(functionsMap, "toInt", returns(INT), args(ANY));
add(functionsMap, "toFloat", returns(FLOAT), args(ANY));
Modified: trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java 2014-04-02 22:04:22 UTC (rev 7753)
+++ trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java 2014-04-03 21:32:18 UTC (rev 7754)
@@ -18,6 +18,9 @@
package org.griphyn.vdl.karajan.lib.swiftscript;
import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.BufferedReader;
+
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -277,6 +280,51 @@
}
}
+ public static class ExecSystem extends AbstractSingleValuedFunction {
+ private ArgRef<AbstractDataNode> input;
+ //private ArgRef<AbstractDataNode> pattern;
+
+ @Override
+ protected Signature getSignature() {
+ return new Signature(params("input"));
+ }
+
+ @Override
+ public Object function(Stack stack) {
+ AbstractDataNode hinput = this.input.getValue(stack);
+ String input = SwiftFunction.unwrap(this, hinput);
+
+ DSHandle handle = new RootArrayDataNode(Types.STRING.arrayType());
+ StringBuffer out = new StringBuffer();
+ Process p;
+ int i = 0;
+
+ try {
+ p = Runtime.getRuntime().exec(input);
+ p.waitFor();
+ BufferedReader reader = new BufferedReader( new InputStreamReader(p.getInputStream()));
+ String line = "";
+ while ( (line = reader.readLine()) != null ) {
+ DSHandle el;
+ el = handle.getField(i++);
+ el.setValue(line);
+ //out.append(line + "\n");
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ handle.closeDeep();
+
+ if (PROVENANCE_ENABLED) {
+ int provid = SwiftFunction.nextProvenanceID();
+ SwiftFunction.logProvenanceResult(provid, handle, "system");
+ SwiftFunction.logProvenanceParameter(provid, hinput, "input");
+ }
+ return handle;
+ }
+ }
+
public static class StrSplit extends AbstractSingleValuedFunction {
private ArgRef<AbstractDataNode> input;
private ArgRef<AbstractDataNode> pattern;
@@ -601,7 +649,7 @@
return handle;
}
}
-
+
public static class Length extends AbstractSingleValuedFunction {
private ArgRef<AbstractDataNode> array;
More information about the Swift-commit
mailing list