Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 import sys
00018 import types
00019 import string
00020 import os
00021
00022
00023 import pygraphviz as pgv
00024
00025 import rospy
00026 from simple_script_server import script
00027
00028
00029 if __name__ == "__main__":
00030 if (len(sys.argv) <= 1 ):
00031 print "Error: wrong number of input arguments"
00032 print "usage: rosrun cob_script_server script_to_graph.py <<SCRIPTFILE>> [level]"
00033
00034 sys.exit(1)
00035 elif (len(sys.argv) == 2):
00036 filename = sys.argv[1]
00037 level = 100
00038 elif (len(sys.argv) == 3):
00039 filename = sys.argv[1]
00040 level = int(sys.argv[2])
00041 else:
00042 print "Error: to many arguments"
00043 print "usage: rosrun cob_script_server script_to_graph.py <<SCRIPTFILE>> [level]"
00044 sys.exit(1)
00045
00046 print "Script file = ", filename
00047 print "Graph level = ", level
00048 rospy.set_param("/script_server/level",level)
00049
00050 filename_splitted = string.split(filename, "/")
00051
00052 scriptfile = filename_splitted[-1]
00053 if(len(filename_splitted) > 1):
00054 filename_splitted.pop(len(filename_splitted)-1)
00055 scriptdir = ""
00056 for name in filename_splitted:
00057 scriptdir += name + "/"
00058
00059 sys.path.insert(0,scriptdir)
00060 scriptfile_woext = string.split(scriptfile, ".")[0]
00061
00062
00063 try:
00064 __import__(scriptfile_woext, globals(), locals(), [], -1)
00065 scriptmodule = sys.modules[scriptfile_woext]
00066 for classname in dir(scriptmodule):
00067 subclass = scriptmodule.__getattribute__(classname)
00068 if(isinstance(subclass, types.ClassType)):
00069 if(issubclass(subclass, script)):
00070 if(classname != "script"):
00071 s = subclass()
00072 dotcode = s.Parse()
00073 print "dotcode = ",dotcode
00074 graph=pgv.AGraph(dotcode)
00075 graph.layout('dot')
00076 basename, extension = os.path.splitext(filename)
00077 if (level == 100):
00078 graph.draw(basename + ".png")
00079 else:
00080 graph.draw(basename + "_" + str(level) + ".png")
00081 except ImportError:
00082 print "Unable to import script file"
00083 print "usage: rosrun cob_script_server script_to_graph.py <<SCRIPTFILE>> [level]"
00084