more improvements.
[vutg.git] / src / vut_front_end.py
blob2e2db6b7aafac5b88f44ae9de539e78ac53c6f6f
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 """
4 =======================================
5 module_name: vut_front_end
6 ---------------------------------------
7 Author: Rodrigo Peixoto
8 Data: 10/02/2008
9 ---------------------------------------
10 Description:
11 - This module runs all the gerenation
12 process.
13 =======================================
14 License: GPL
15 ======================================================================
17 This program is free software: you can redistribute it and/or modify
18 it under the terms of the GNU General Public License as published by
19 the Free Software Foundation, either version 3 of the License, or
20 (at your option) any later version.
22 This program is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 GNU General Public License for more details.
27 You should have received a copy of the GNU General Public License
28 along with this program. If not, see <http://www.gnu.org/licenses/>.
30 =======================================================================
31 """
32 from vut_checker import *
33 from vut_generator import *
34 from vut_parser import *
35 import sys
37 ARGS_CAN_BE = ['skeleton','makefile']
39 def verify_parameters(params):
40 l = len(params)
41 executable_name = params[0]
42 params = params[1:]
43 ret = {}
44 aux = []
45 for param in params:
46 aux = param.split('=')
47 ret[aux[0]]= aux[1].split(',')
49 aux = None
50 return ret
52 class InvalidArgumentException(Exception):
53 pass
55 def run_vut_generator(args=[]):
56 #arg = "example5.vut"
57 #args = sys.argv
58 flags = verify_parameters(args)
59 print flags
60 lflags = len(flags)
61 gen_param = []
62 try:
63 try:
64 file_name = flags['vut_file'][0]
65 except KeyError:
66 raise InvalidArgumentException()
68 try:
69 gen_param = flags['gen']
70 assert set(gen_param).issubset(set(ARGS_CAN_BE)), "Error, the gen's values are wrong!"
71 except KeyError:
72 if lflags == 2: raise InvalidArgumentException()
74 # if len(args) == 3:
75 # if args[1] in ARGS_CAN_BE:
76 # gen_param = args[1]
77 # file_name = args[2]
78 # else:
79 # raise InvalidArgumentException()
81 # elif (len(args) == 2):
82 # file_name = args[1]
83 # else:
84 # raise InvalidArgumentException()
86 print "#################"
87 print "# @VUTGenerator #"
88 print "#################"
89 print "Phases: Check -> Parse -> Code Generation"
90 print "\nPHASE 1 [Check] --------------------------------------------\n"
91 VUTChercker(file_name).check_all()
92 print "\nPHASE 2 [Parse] --------------------------------------------\n"
93 vm = VUTParser(file_name).parse_all()
94 print "\nPHASE 3 [Code Generation] --------------------------------------------\n"
95 VUTGenerator(vm,gen_param).gen()
96 #VUTGenerator(vm).gen()
97 print u"\n\nGeneration complete @VUTGenerator."
99 except InvalidArgumentException:
100 print "The arguments are not valid. Please, check it out."
101 print "Usage: ./vutg gen=<item1>,<item2> vut_file=<file_name.vut>"
103 except KeyboardInterrupt:
104 print u"\n\nGeneration interrupted! @VUTGenerator."
106 if __name__=="__main__":
107 run_vut_generator("vutg gen=skeleton,makefile vu_file=example5.vut")