Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
536 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# fbp 1.5.0 - released 02.07.2016 | ||
|
||
* Add JSON to FBP parser | ||
|
||
# fbp 1.4.0 - released 17.06.2016 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
module.exports = | ||
parse: (graph, options = {}) -> | ||
input = JSON.parse graph | ||
namedComponents = [] | ||
output = "" | ||
|
||
getName = (name) -> | ||
if input.processes[name].metadata? | ||
name = input.processes[name].metadata.label | ||
|
||
if name.indexOf('/') > -1 | ||
name = name.split('/').pop() | ||
#name = name.replace('/', '_') | ||
|
||
return name | ||
|
||
getInOutName = (name, data) -> | ||
if data.process? and input.processes[data.process].metadata? | ||
name = input.processes[data.process].metadata.label | ||
|
||
else if data.process? | ||
name = data.process | ||
|
||
if name.indexOf('/') > -1 | ||
name = name.split('/').pop() | ||
|
||
return name | ||
|
||
for name, inPort of input.inports | ||
process = getInOutName name, inPort | ||
name = name.toUpperCase() | ||
inPort.port = inPort.port.toUpperCase() | ||
output += "INPORT=#{process}.#{inPort.port}:#{name}\n" | ||
|
||
for name, outPort of input.outports | ||
process = getInOutName name, inPort | ||
name = name.toUpperCase() | ||
outPort.port = outPort.port.toUpperCase() | ||
output += "OUTPORT=#{process}.#{outPort.port}:#{name}\n" | ||
|
||
# add new lines after input and outports | ||
output += "\n" | ||
|
||
for conn in input.connections | ||
# it is data added in the noflo graph (IP) | ||
if conn.data? | ||
tgtPort = conn.tgt.port.toUpperCase() | ||
tgtName = conn.tgt.process | ||
tgtProcess = input.processes[tgtName].component | ||
tgt = getName tgtName | ||
unless tgtProcess in namedComponents | ||
tgt += "(#{tgtProcess})" | ||
namedComponents.push tgtProcess | ||
output += '"' + conn.data + '"' + " -> #{tgtPort} #{tgt}\n" | ||
# is not data, is a connection | ||
else | ||
srcPort = conn.src.port.toUpperCase() | ||
srcName = conn.src.process | ||
srcProcess = input.processes[srcName].component | ||
src = getName srcName | ||
unless srcProcess in namedComponents | ||
src += "(#{srcProcess})" | ||
namedComponents.push srcProcess | ||
|
||
tgtPort = conn.tgt.port.toUpperCase() | ||
tgtName = conn.tgt.process | ||
tgtProcess = input.processes[tgtName].component | ||
tgt = getName tgtName | ||
unless tgtProcess in namedComponents | ||
tgt += "(#{tgtProcess})" | ||
namedComponents.push tgtProcess | ||
output += "#{src} #{srcPort} -> #{tgtPort} #{tgt}\n" | ||
|
||
return output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
var indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; | ||
|
||
module.exports = { | ||
parse: function(graph, options) { | ||
var conn, getInOutName, getName, i, inPort, input, len, name, namedComponents, outPort, output, process, ref, ref1, ref2, src, srcName, srcPort, srcProcess, tgt, tgtName, tgtPort, tgtProcess; | ||
if (options == null) { | ||
options = {}; | ||
} | ||
input = JSON.parse(graph); | ||
namedComponents = []; | ||
output = ""; | ||
getName = function(name) { | ||
if (input.processes[name].metadata != null) { | ||
name = input.processes[name].metadata.label; | ||
} | ||
if (name.indexOf('/') > -1) { | ||
name = name.split('/').pop(); | ||
} | ||
return name; | ||
}; | ||
getInOutName = function(name, data) { | ||
if ((data.process != null) && (input.processes[data.process].metadata != null)) { | ||
name = input.processes[data.process].metadata.label; | ||
} else if (data.process != null) { | ||
name = data.process; | ||
} | ||
if (name.indexOf('/') > -1) { | ||
name = name.split('/').pop(); | ||
} | ||
return name; | ||
}; | ||
ref = input.inports; | ||
for (name in ref) { | ||
inPort = ref[name]; | ||
process = getInOutName(name, inPort); | ||
name = name.toUpperCase(); | ||
inPort.port = inPort.port.toUpperCase(); | ||
output += "INPORT=" + process + "." + inPort.port + ":" + name + "\n"; | ||
} | ||
ref1 = input.outports; | ||
for (name in ref1) { | ||
outPort = ref1[name]; | ||
process = getInOutName(name, inPort); | ||
name = name.toUpperCase(); | ||
outPort.port = outPort.port.toUpperCase(); | ||
output += "OUTPORT=" + process + "." + outPort.port + ":" + name + "\n"; | ||
} | ||
output += "\n"; | ||
ref2 = input.connections; | ||
for (i = 0, len = ref2.length; i < len; i++) { | ||
conn = ref2[i]; | ||
if (conn.data != null) { | ||
tgtPort = conn.tgt.port.toUpperCase(); | ||
tgtName = conn.tgt.process; | ||
tgtProcess = input.processes[tgtName].component; | ||
tgt = getName(tgtName); | ||
if (indexOf.call(namedComponents, tgtProcess) < 0) { | ||
tgt += "(" + tgtProcess + ")"; | ||
namedComponents.push(tgtProcess); | ||
} | ||
output += '"' + conn.data + '"' + (" -> " + tgtPort + " " + tgt + "\n"); | ||
} else { | ||
srcPort = conn.src.port.toUpperCase(); | ||
srcName = conn.src.process; | ||
srcProcess = input.processes[srcName].component; | ||
src = getName(srcName); | ||
if (indexOf.call(namedComponents, srcProcess) < 0) { | ||
src += "(" + srcProcess + ")"; | ||
namedComponents.push(srcProcess); | ||
} | ||
tgtPort = conn.tgt.port.toUpperCase(); | ||
tgtName = conn.tgt.process; | ||
tgtProcess = input.processes[tgtName].component; | ||
tgt = getName(tgtName); | ||
if (indexOf.call(namedComponents, tgtProcess) < 0) { | ||
tgt += "(" + tgtProcess + ")"; | ||
namedComponents.push(tgtProcess); | ||
} | ||
output += src + " " + srcPort + " -> " + tgtPort + " " + tgt + "\n"; | ||
} | ||
} | ||
return output; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.