aboutsummaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorYakov Goldberg <yakov.goldberg@gmail.com>2012-11-08 22:51:55 +0200
committerYakov Goldberg <yakov.goldberg@gmail.com>2012-11-09 01:58:29 +0200
commit0ffbd6fed1e641c46a83581a278db7c8fbcf7a58 (patch)
tree2eb618399d0c95e5e0a84d068870534e95dd4c5f /bin
parenth_file_data_get() string.find() changed to regex (diff)
downloadeo_bindings-0ffbd6fed1e641c46a83581a278db7c8fbcf7a58.tar.gz
C: Project layout; setup added
package - eoparser modules - cparser, xmlparser bin - eo_xml_gen.py, eo_graph_gen.py data - types.xml tests - tests.py Adding setup.py. Usage: - python setup.py sdist - dist/*.tgz - extract - python setup.py install --prefix=<dist> Signed-off-by: Yakov Goldberg <yakov.goldberg@gmail.com>
Diffstat (limited to 'bin')
-rwxr-xr-xbin/eo_graph_gen.py192
-rwxr-xr-xbin/eo_xml_gen.py158
2 files changed, 350 insertions, 0 deletions
diff --git a/bin/eo_graph_gen.py b/bin/eo_graph_gen.py
new file mode 100755
index 0000000..ff8681c
--- /dev/null
+++ b/bin/eo_graph_gen.py
@@ -0,0 +1,192 @@
+#!/usr/bin/env python
+
+from eoparser.helper import isXML, dir_files_get, abs_path_get
+from eoparser.xmlparser import XMLparser
+from argparse import ArgumentParser
+import os
+
+def verbose_true(mes):
+ print mes
+
+def verbose_false(mes):
+ pass
+
+def main():
+ parser = ArgumentParser()
+ parser.add_argument("-d", "--dir", dest="directory",
+ action="append", help="Source files directory")
+
+ parser.add_argument("-o", "--outfile", dest="outfile",
+ action="store", help="Path for output files")
+
+ parser.add_argument("-v", "--verbose",
+ action="store_true", dest="verbose", default=False,
+ help="Print status messages to stdout")
+
+ parser.add_argument("--graphstyle", action="store", dest="graphstyle", default="digraph",
+ help="Set graph style. Default: \"digraph\"")
+
+ parser.add_argument("--edge", action="store", dest="edge", default="solid",
+ help="Set line style for parent edge. Default: \"solid\"")
+
+ parser.add_argument("--extedge", action="store", dest="extedge", default="dashed",
+ help="Set line style for extension edge. Default: \"dashed\"")
+
+ parser.add_argument("--rankdir", action="store", dest="rankdir", default="BT",
+ help="Direction of directed graph[BT, TB, LR, RL]. Default: \"BT\"")
+
+ parser.add_argument("--graphfontsize", action="store", dest="graphfontsize", default="15",
+ help="Graph font size. Default: \"15\"")
+
+ parser.add_argument("--graphlabel", action="store", dest="graphlabel", default="",
+ help="Graph label")
+
+ parser.add_argument("--nodefontsize", action="store", dest="nodefontsize", default="10",
+ help="Node font size. Default: \"10\"")
+
+ parser.add_argument("--nodeshape", action="store", dest="nodeshape", default="polygon",
+ help="Node shape.[\"polygon\", \"circle\", \"ellipse\"] Default: \"polygon\"")
+
+
+ styles = {}
+
+ args = parser.parse_args()
+ styles["edge"] = args.edge
+ styles["extedge"] = args.extedge
+ styles["graphstyle"] = args.graphstyle
+ styles["rankdir"] = args.rankdir
+ styles["graphfontsize"] = args.graphfontsize
+ styles["graphlabel"] = args.graphlabel
+ styles["nodefontsize"] = args.nodefontsize
+ styles["nodeshape"] = args.nodeshape
+
+
+ types = {
+ "REGULAR":"EO_CLASS_TYPE_REGULAR",
+ "MIXIN" : "EO_CLASS_TYPE_MIXIN",
+ "INTERFACE":"EO_CLASS_TYPE_INTERFACE",
+ "NO_INSTANT":"EO_CLASS_TYPE_REGULAR_NO_INSTANT"
+ }
+
+ n_color = {
+ types["REGULAR"]:"green",
+ types["MIXIN"] : "blue",
+ types["INTERFACE"]:"red",
+ types["NO_INSTANT"]:"darkviolet"
+ }
+
+ verbose_print = None
+ if args.verbose is True:
+ verbose_print = verbose_true
+ else:
+ verbose_print = verbose_false
+
+ verbose_print("Options: %s"%args)
+ verbose_print("Args: %s"%args)
+
+ directories = []
+ outfile = ""
+
+ if args.directory == None:
+ print "ERROR: no source directory was provided"
+ exit(1)
+ elif args.outfile == None:
+ print "ERROR: no output file was provided"
+ exit(1)
+
+ else:
+ directories = abs_path_get(args.directory)
+
+ outfile = args.outfile
+ outfile = os.path.expanduser(outfile)
+ outfile = os.path.abspath(outfile)
+
+ outdir = os.path.split(outfile)[0]
+ if not os.path.exists(outdir):
+ print "ERROR: output directory %s doesn't exists... Aborting..."%outdir
+ exit(1)
+
+ verbose_print("Dirs: %s"%directories)
+ verbose_print("Outfile: %s"%outfile)
+
+ xml_files = dir_files_get(directories)
+ xml_files = filter(isXML, xml_files)
+
+ graph = {}
+
+ if len(xml_files) == 0:
+ print "ERROR: no xml files were found"
+ exit(1)
+
+ xp = XMLparser()
+ for f in xml_files:
+ xp.parse(f)
+
+ graph = dict(xp.objects)
+
+ del xp
+
+ if len(graph) == 0:
+ print "ERROR: no data was found in source files"
+ exit(1)
+
+ lines = []
+
+ lines.append("%s G{"%(styles["graphstyle"]))
+ lines.append(" graph [rankdir = \"%s\", fontsize = %s, label = \"%s\"];"%(styles["rankdir"], styles["graphfontsize"], styles["graphlabel"]))
+ lines.append(" node [shape = \"%s\" fontsize = %s];"%(styles["nodeshape"], styles["nodefontsize"]))
+
+ #generating dot node description for node, for each class
+ for n, o in graph.items():
+ if o.eo_type == types["REGULAR"]:
+ line = " \"%s\" [label = \"%s \\n %s\", color = \"%s\"];"%(n, o.c_name, o.eo_type, n_color[types["REGULAR"]])
+ elif o.eo_type == types["MIXIN"]:
+ line = " \"%s\" [label = \"%s \\n %s\", color = \"%s\"];"%(n, o.c_name, o.eo_type, n_color[types["MIXIN"]])
+ elif o.eo_type == types["INTERFACE"]:
+ line = " \"%s\" [label = \"%s \\n %s\", color = \"%s\"];"%(n, o.c_name, o.eo_type, n_color[types["INTERFACE"]])
+ elif o.eo_type == types["NO_INSTANT"]:
+ line = " \"%s\" [label = \"%s \\n %s\", color = \"%s\"];"%(n, o.c_name, o.eo_type, n_color[types["NO_INSTANT"]])
+ else:
+ line = " \"%s\" [label = \"%s \\n %s\"];"%(n, o.c_name, o.eo_type)
+
+ lines.append(line)
+
+ #generating dot edge description for each parent of each class
+ for n, o in graph.items():
+ parent = o.parents[0]
+ ext = o.parents[1:]
+ ext = filter(len, ext)
+ if len(parent) != 0:
+ if parent in graph:
+ p_type = graph[parent].eo_type
+ else:
+ p_type = types["REGULAR"]
+ line = " \"%s\" -> \"%s\" [style = \"%s\", color=\"%s\"];"%(n, parent, styles["edge"], n_color[p_type])
+ lines.append(line)
+ for l in ext:
+ if graph[l].eo_type == types["REGULAR"]:
+ line = " \"%s\" -> \"%s\" [style=\"%s\", color=\"%s\"] ;"%(n, l, "dashed", n_color[types["REGULAR"]])
+ elif graph[l].eo_type == types["MIXIN"]:
+ line = " \"%s\" -> \"%s\" [style=\"%s\", color=\"%s\"] ;"%(n, l, "dashed", n_color[types["MIXIN"]])
+ elif graph[l].eo_type == types["INTERFACE"]:
+# line = " \"%s\" -> \"%s\" [style=\"%s\"] ;"%(k, l, styles["extedge"])
+ line = " \"%s\" -> \"%s\" [style=\"%s\", color = \"%s\"] ;"%(n, l, "dotted", n_color[types["INTERFACE"]])
+ elif graph[l].eo_type == types["NO_INSTANT"]:
+ line = " \"%s\" -> \"%s\" [style=\"%s\", color=\"%s\"] ;"%(n, l, "dashed", n_color[types["NO_INSTANT"]])
+ else:
+ line = " \"%s\" -> \"%s\" [style=\"%s\", color=\"%s\"] ;"%(k, l, "dashed", "black")
+
+ lines.append(line)
+ lines.append("}")
+
+ f = open(outfile, 'w')
+ for l in lines:
+ f.write(l+'\n')
+
+ f.close()
+
+ verbose_print("dot file: %s was generated"%(outfile))
+
+if __name__ == "__main__":
+ main()
+
diff --git a/bin/eo_xml_gen.py b/bin/eo_xml_gen.py
new file mode 100755
index 0000000..5d01b75
--- /dev/null
+++ b/bin/eo_xml_gen.py
@@ -0,0 +1,158 @@
+#!/usr/bin/env python
+
+from eoparser.helper import dir_files_get, abs_path_get, isC, isH, isXML
+from eoparser.helper import _const
+from eoparser.xmlparser import XMLparser
+from eoparser.cparser import Cparser
+from argparse import ArgumentParser
+import sys
+
+#creating instance to handle constants
+const = _const()
+
+def verbose_true(mes):
+ print mes
+def verbose_false(mes):
+ pass
+
+def main():
+
+ parser = ArgumentParser()
+ parser.add_argument("-d", "--dir", dest="directory",
+ action="append", help="source files")
+
+ parser.add_argument("-o", "--outdir", dest="outdir",
+ action="store", help="output directory")
+
+ parser.add_argument("-t", "--typedefs", dest="typedefs",
+ action="store", help="Additional typedefs for parser")
+
+ parser.add_argument("-i", "--include", dest="xmldir", default = sys.path,
+ action="append", help="Include xml directory")
+
+ parser.add_argument("-v", "--verbose",
+ action="store_true", dest="verbose", default=False,
+ help="print status messages to stdout")
+
+ args = parser.parse_args()
+ verbose_print = None
+
+ if args.verbose is True:
+ verbose_print = verbose_true
+ else:
+ verbose_print = verbose_false
+
+ directories = []
+ outdir = ""
+ typedefs = ""
+ xmldir = []
+
+ if args.directory == None:
+ print "No source directory was provided"
+ exit(1)
+ elif args.outdir == None:
+ print "No out directory was provided"
+ exit(1)
+ else:
+ directories = abs_path_get(args.directory)
+ if args.xmldir is not None:
+ xmldir = abs_path_get(args.xmldir, False)# not abort if dir doesn't exist
+
+ outdir = abs_path_get([args.outdir])[0]
+
+ if args.typedefs != None:
+ typedefs = abs_path_get([args.typedefs])[0]
+
+ verbose_print("dirs %s"%directories)
+ verbose_print("outdir %s"%outdir)
+
+ files = dir_files_get(directories)
+ c_files = filter(isC, files)
+ h_files = filter(isH, files)
+
+ cp = Cparser(args.verbose)
+ cp.outdir_set(outdir)
+
+ #adding typedefs from extern file
+ if typedefs:
+ cp.typedefs_add(typedefs)
+
+ #fetching data from c-file
+ for f in c_files:
+ # cp.c_file_data_get(f)
+ cp.c_file_data_get2(f)
+
+ #fetching data from h-file
+ for f in h_files:
+ cp.h_file_data_get(f)
+
+
+ #remove records, which are not class, t.e. they don't have GET_FUNCTION key
+ cl_data_tmp = dict(cp.cl_data) #deep copy of dictionary
+ for k in cl_data_tmp:
+ if const.GET_FUNCTION not in cp.cl_data[k]:
+ print "Warning: no define for class: %s. Record will be excluded from tree"%k
+ cp.cl_data.pop(k)
+ del cl_data_tmp
+
+ #mapping #defines, comments(@def) and op_ids together, to parse parameters
+ for k in cp.cl_data:
+ cp.parse_op_func_params(k)
+
+ #creating list of all parents for classes which are in tree
+ list_of_parents = []
+ for k in cp.cl_data:
+ list_of_parents += cp.cl_data[k][const.PARENTS]
+ list_of_parents = list(set(list_of_parents))
+
+ #checking, if we need to find any parent and filtering it's ids
+ cl_data_tmp2 = dict(cp.cl_data)
+ parents_to_find = filter(lambda ll: True if ll not in cl_data_tmp2 else False, list_of_parents)
+
+ verbose_print("parents_to_find: %s"%parents_to_find)
+
+ #if we have parents to find
+ if len(parents_to_find) != 0:
+ if len(xmldir) == 0:
+ print "No XML directory was provided"
+
+ verbose_print("xmldir: %s\n"%xmldir)
+ xml_files = dir_files_get(xmldir)
+ xml_files = filter(isXML, xml_files)
+
+ if len(xml_files) == 0:
+ print "ERROR: no include files found for %s classes... Aborting..."% ",".join(parents_to_find)
+ exit(1)
+ verbose_print("xml_files: %s\n"%xml_files)
+
+ #parsing include XMLs
+ xp = XMLparser()
+ for f in xml_files:
+ xp.parse(f)
+
+ #saving data about parents we were looking for
+ for n, o in xp.objects.items():
+ if o.macro in parents_to_find:
+ cp.cl_incl[o.macro] = {const.MODULE : o.mod_name,
+ const.C_NAME : o.c_name}
+ i = parents_to_find.index(o.macro)
+ parents_to_find.pop(i)
+ del xp
+
+
+ #if there are still parents, which we need to find - exit
+ if len(parents_to_find) != 0:
+ print "ERROR: XML files weren't found for %s classes... Aborting"%(",".join(parents_to_find))
+ exit(1)
+
+ #building XMLs
+ for k in cp.cl_data:
+ cp.build_xml(k)
+
+ #cp.print_data()
+ del cp
+
+if __name__ == "__main__":
+ main()
+
+