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