commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbe...@apache.org
Subject svn commit: r1032238 - /commons/sandbox/gsoc/2010/scxml-js/trunk/src/python/scxml/cgf/SCXMLCompiler.py
Date Sun, 07 Nov 2010 09:35:39 GMT
Author: jbeard
Date: Sun Nov  7 09:35:39 2010
New Revision: 1032238

URL: http://svn.apache.org/viewvc?rev=1032238&view=rev
Log:
Added command-line option parsing.

Modified:
    commons/sandbox/gsoc/2010/scxml-js/trunk/src/python/scxml/cgf/SCXMLCompiler.py

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/src/python/scxml/cgf/SCXMLCompiler.py
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/src/python/scxml/cgf/SCXMLCompiler.py?rev=1032238&r1=1032237&r2=1032238&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/src/python/scxml/cgf/SCXMLCompiler.py (original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/src/python/scxml/cgf/SCXMLCompiler.py Sun Nov
 7 09:35:39 2010
@@ -1,5 +1,6 @@
 import sys
 import pkg_resources
+import getopt
 from lxml import etree
 
 def compile(pathsToSCXML=[],backend="state",options={}):
@@ -20,17 +21,23 @@ def compile(pathsToSCXML=[],backend="sta
 	
 	for doc in sourceDocuments:
 		ir = transformDocument(doc,config["transformations"])
-		transformedJs = transformDocument(sourceDocument,[config["code"]],options,"text")
+		transformedJs = transformDocument(ir,[config["code"]],options,"text")
 		results.push(transformedJs) 
 
+		#TODO: optionally beautify result here
+
 	return results
 
 def transformDocument(sourceDocument=None,transformList=[],params={},output="xml"):
 
 	templateStreams = map(lambda t : pkg_resources.resource_stream(__name__,t), transformList)
+	print templateStreams 
 	templateDocs = map(lambda t : etree.parse(t), templateStreams)
-	compiledTemplates = map(lambda t : etree.XSLT(t), transformList)
+	print templateDocs 
+	compiledTemplates = map(lambda t : etree.XSLT(t), templateDocs)
+	print compiledTemplates 
 
+	#TODO: apply args to the transform
 	outputDocument = reduce(lambda docToTransform,transform: transform(docToTransform), compiledTemplates,
sourceDocument)
 
 	if output == "xml":
@@ -39,5 +46,29 @@ def transformDocument(sourceDocument=Non
 		#assume "text"
 		return outputDocument.root.getText() 
 
+def usage():
+	print "Couldn't parse command-line args. TODO: print helpful usage text."
+
+def optlistToDict(optlist):
+	toReturn = {}
+
+	for opt,arg in optlist:
+		toReturn[opt]=arg
+
+	return toReturn
+
+def main(argv):
+	#parse command-line args
+	optlist, args = getopt.getopt(argv, '', ["backend=", "ie","noIndexOf","beautify","log","verbose","genListenerHooks"])
+	print "opts: ", optlist
+	print "args: ", args
+	opts = optlistToDict(optlist)
+	results = compile(args,opts["--backend"],opts) 
+
+	for result in results:
+		print result
+
+
+
 if __name__ == "__main__":
-	pass #TODO: parse command-line args
+	main(sys.argv[1:])



Mime
View raw message