h1. Introduction
FIDO does not (yet) have an API which can be called for implementation in workflow systems. Although there is a FIDO class which could be called after import of fido.py, it is not recommended to use it. This has to do with the fact the class was not designed to be instantiated from outside scripts.
This does not mean you can not integrate FIDO into your workflows. FIDO has a main() function which accepts the same parameters as the command line interface which you have to pass as a list. You also need to catch the STDOUT and STDERR streams from FIDO in order to do usefull things with them, otherwise FIDO will just happily print to the STDOUT and STDERR streams of the calling script.
Below are simple examples for integration into Python worklow applications.
h2. Implementation when fido.py is on the same path as your worklow.py
{code}
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# example Python 2.7 workflow integration for FIDO
# Maurice de Rooij (NANETH), 2013
from cStringIO import StringIO
import sys
# set stdout to string to parse stdout of fido later
sys.stdout = mystdout = StringIO()
# set stderr to string to parse stderr of fido later
sys.stderr = mystderr = StringIO()
# import fido, assuming fido.py is in the same path as your workflow.py
import fido
# use the same parameters as commandline parameters by passing them as a list to fido.main()
fido.main(["-recurse","/path/to/analyse"])
# reset stdout so your script can output again
sys.stdout = sys.__stdout__
# reset stderr so your script can output again
sys.stderr = sys.__stderr__
# split result from stdout into list
fido_result = [x for x in mystdout.getvalue().split("\n") if x]
# print each stdout line from fido
for result in fido_result:
print "result: ", result
# split result from stderr into list
fido_errors = [x for x in mystderr.getvalue().split("\n") if x]
# print each stderr line from fido
for error in fido_errors:
print "error: ", error
{code}
h2. Implementation when fido.py is on a different path than your worklow.py
{code}
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# example Python 2.7 workflow integration for FIDO
# Maurice de Rooij (NANETH), 2013
from cStringIO import StringIO
import sys
# set stdout to string to parse stdout of fido later
sys.stdout = mystdout = StringIO()
# set stderr to string to parse stderr of fido later
sys.stderr = mystderr = StringIO()
# append the folder where fido.py is to sys.path
sys.path.append("/path/to/fido")
import fido
# use the same parameters as commandline parameters by passing them as a list to fido.main()
fido.main(["-recurse","/path/to/analyse"])
# reset stdout so your script can output again
sys.stdout = sys.__stdout__
# reset stderr so your script can output again
sys.stderr = sys.__stderr__
# split result from stdout into list
fido_result = [x for x in mystdout.getvalue().split("\n") if x]
# print each stdout line from fido
for result in fido_result:
print "result: ", result
# split result from stderr into list
fido_errors = [x for x in mystderr.getvalue().split("\n") if x]
# print each stderr line from fido
for error in fido_errors:
print "error: ", error
{code}
FIDO does not (yet) have an API which can be called for implementation in workflow systems. Although there is a FIDO class which could be called after import of fido.py, it is not recommended to use it. This has to do with the fact the class was not designed to be instantiated from outside scripts.
This does not mean you can not integrate FIDO into your workflows. FIDO has a main() function which accepts the same parameters as the command line interface which you have to pass as a list. You also need to catch the STDOUT and STDERR streams from FIDO in order to do usefull things with them, otherwise FIDO will just happily print to the STDOUT and STDERR streams of the calling script.
Below are simple examples for integration into Python worklow applications.
h2. Implementation when fido.py is on the same path as your worklow.py
{code}
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# example Python 2.7 workflow integration for FIDO
# Maurice de Rooij (NANETH), 2013
from cStringIO import StringIO
import sys
# set stdout to string to parse stdout of fido later
sys.stdout = mystdout = StringIO()
# set stderr to string to parse stderr of fido later
sys.stderr = mystderr = StringIO()
# import fido, assuming fido.py is in the same path as your workflow.py
import fido
# use the same parameters as commandline parameters by passing them as a list to fido.main()
fido.main(["-recurse","/path/to/analyse"])
# reset stdout so your script can output again
sys.stdout = sys.__stdout__
# reset stderr so your script can output again
sys.stderr = sys.__stderr__
# split result from stdout into list
fido_result = [x for x in mystdout.getvalue().split("\n") if x]
# print each stdout line from fido
for result in fido_result:
print "result: ", result
# split result from stderr into list
fido_errors = [x for x in mystderr.getvalue().split("\n") if x]
# print each stderr line from fido
for error in fido_errors:
print "error: ", error
{code}
h2. Implementation when fido.py is on a different path than your worklow.py
{code}
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# example Python 2.7 workflow integration for FIDO
# Maurice de Rooij (NANETH), 2013
from cStringIO import StringIO
import sys
# set stdout to string to parse stdout of fido later
sys.stdout = mystdout = StringIO()
# set stderr to string to parse stderr of fido later
sys.stderr = mystderr = StringIO()
# append the folder where fido.py is to sys.path
sys.path.append("/path/to/fido")
import fido
# use the same parameters as commandline parameters by passing them as a list to fido.main()
fido.main(["-recurse","/path/to/analyse"])
# reset stdout so your script can output again
sys.stdout = sys.__stdout__
# reset stderr so your script can output again
sys.stderr = sys.__stderr__
# split result from stdout into list
fido_result = [x for x in mystdout.getvalue().split("\n") if x]
# print each stdout line from fido
for result in fido_result:
print "result: ", result
# split result from stderr into list
fido_errors = [x for x in mystderr.getvalue().split("\n") if x]
# print each stderr line from fido
for error in fido_errors:
print "error: ", error
{code}